diff --git a/src/org/mockito/internal/util/reflection/GenericMetadataSupport.java b/src/org/mockito/internal/util/reflection/GenericMetadataSupport.java index 8046052fd1..80bd908b5e 100644 --- a/src/org/mockito/internal/util/reflection/GenericMetadataSupport.java +++ b/src/org/mockito/internal/util/reflection/GenericMetadataSupport.java @@ -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); } } @@ -376,6 +376,7 @@ private void readTypeVariables() { for (Type type : typeVariable.getBounds()) { registerTypeVariablesOn(type); } + registerTypeParametersOn(new TypeVariable[] { typeVariable }); registerTypeVariablesOn(getActualTypeArgumentFor(typeVariable)); } diff --git a/test/org/mockito/internal/util/reflection/GenericMetadataSupportTest.java b/test/org/mockito/internal/util/reflection/GenericMetadataSupportTest.java index f15833ccbf..a45d549ce3 100644 --- a/test/org/mockito/internal/util/reflection/GenericMetadataSupportTest.java +++ b/test/org/mockito/internal/util/reflection/GenericMetadataSupportTest.java @@ -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; @@ -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> { @@ -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); diff --git a/test/org/mockitousage/bugs/deepstubs/DeepStubFailingWhenGenricNestedAsRawTypeTest.java b/test/org/mockitousage/bugs/deepstubs/DeepStubFailingWhenGenricNestedAsRawTypeTest.java new file mode 100644 index 0000000000..d7f28f9054 --- /dev/null +++ b/test/org/mockitousage/bugs/deepstubs/DeepStubFailingWhenGenricNestedAsRawTypeTest.java @@ -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 getNested(); + } + + interface MyClass2 { + 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."); + } +}