Skip to content

Commit

Permalink
Merge branch 'pbielicki-bug#128'
Browse files Browse the repository at this point in the history
  • Loading branch information
mockitoguy committed Dec 31, 2014
2 parents 3c8892b + 3ca1ba3 commit 0aaa36c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ protected void registerTypeVariablesOn(Type classType) {
}

protected void registerTypeParametersOn(TypeVariable[] typeParameters) {
for (TypeVariable typeVariable : typeParameters) {
registerTypeVariableIfNotPresent(typeVariable);
for (TypeVariable type : typeParameters) {
registerTypeVariableIfNotPresent(type);
}
}

Expand Down Expand Up @@ -376,6 +376,7 @@ private void readTypeVariables() {
for (Type type : typeVariable.getBounds()) {
registerTypeVariablesOn(type);
}
registerTypeParametersOn(new TypeVariable[] { typeVariable });
registerTypeVariablesOn(getActualTypeArgumentFor(typeVariable));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.internal.util.reflection.GenericMetadataSupport.inferFrom;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
Expand All @@ -17,9 +18,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

@SuppressWarnings("unused")
public class GenericMetadataSupportTest {

interface GenericsSelfReference<T extends GenericsSelfReference<T>> {
Expand Down Expand Up @@ -62,7 +63,6 @@ public void can_get_raw_type_from_Class() throws Exception {
assertThat(inferFrom(StringList.class).rawType()).isEqualTo(StringList.class);
}


@Test
public void can_get_raw_type_from_ParameterizedType() throws Exception {
assertThat(inferFrom(ListOfAnyNumbers.class.getGenericInterfaces()[0]).rawType()).isEqualTo(List.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.mockitousage.bugs.deepstubs;

import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;

public class DeepStubFailingWhenGenricNestedAsRawTypeTest {

interface MyClass1<MC2 extends MyClass2> {
MC2 getNested();
}

interface MyClass2<MC3 extends MyClass3> {
MC3 getNested();
}

interface MyClass3 {
String returnSomething();
}

@Test
public void discoverDeepMockingOfGenerics() {
MyClass1 myMock1 = mock(MyClass1.class, RETURNS_DEEP_STUBS);
when(myMock1.getNested().getNested().returnSomething()).thenReturn("Hello World.");
}
}

0 comments on commit 0aaa36c

Please sign in to comment.