Autowiring of generic types
Includes revisions of MethodParameter and DependencyDescriptor (in particular towards a reference to the containing class). Also refines several ResolvableType method signatures. Issue: SPR-9965
This commit is contained in:
@@ -44,13 +44,12 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResolvableType}.
|
||||
@@ -196,7 +195,7 @@ public class ResolvableTypeTests {
|
||||
@Test
|
||||
public void forMethodReturn() throws Exception {
|
||||
Method method = Methods.class.getMethod("charSequenceReturn");
|
||||
ResolvableType type = ResolvableType.forMethodReturn(method);
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(method);
|
||||
assertThat(type.getType(), equalTo(method.getGenericReturnType()));
|
||||
}
|
||||
|
||||
@@ -204,7 +203,7 @@ public class ResolvableTypeTests {
|
||||
public void forMethodReturnMustNotBeNull() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Method must not be null");
|
||||
ResolvableType.forMethodReturn(null);
|
||||
ResolvableType.forMethodReturnType(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -557,25 +556,25 @@ public class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
public void resolveBoundedTypeVariableResult() throws Exception {
|
||||
ResolvableType type = ResolvableType.forMethodReturn(Methods.class.getMethod("boundedTypeVaraibleResult"));
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("boundedTypeVaraibleResult"));
|
||||
assertThat(type.resolve(), equalTo((Class) CharSequence.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveVariableNotFound() throws Exception {
|
||||
ResolvableType type = ResolvableType.forMethodReturn(Methods.class.getMethod("typedReturn"));
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("typedReturn"));
|
||||
assertThat(type.resolve(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTypeVaraibleFromMethodReturn() throws Exception {
|
||||
ResolvableType type = ResolvableType.forMethodReturn(Methods.class.getMethod("typedReturn"));
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("typedReturn"));
|
||||
assertThat(type.resolve(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTypeVaraibleFromMethodReturnWithInstanceClass() throws Exception {
|
||||
ResolvableType type = ResolvableType.forMethodReturn(
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(
|
||||
Methods.class.getMethod("typedReturn"), TypedMethods.class);
|
||||
assertThat(type.resolve(), equalTo((Class) String.class));
|
||||
}
|
||||
@@ -685,11 +684,11 @@ public class ResolvableTypeTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTypeVariableFromMethodParameterTypeWithImplementsClass()
|
||||
throws Exception {
|
||||
public void resolveTypeVariableFromMethodParameterTypeWithImplementsClass() throws Exception {
|
||||
Method method = Methods.class.getMethod("typedParameter", Object.class);
|
||||
MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(method, 0);
|
||||
ResolvableType type = ResolvableType.forMethodParameter(methodParameter, TypedMethods.class);
|
||||
methodParameter.setContainingClass(TypedMethods.class);
|
||||
ResolvableType type = ResolvableType.forMethodParameter(methodParameter);
|
||||
assertThat(type.resolve(), equalTo((Class) String.class));
|
||||
assertThat(type.getType().toString(), equalTo("T"));
|
||||
}
|
||||
@@ -697,7 +696,7 @@ public class ResolvableTypeTests {
|
||||
@Test
|
||||
public void resolveTypeVariableFromMethodReturn() throws Exception {
|
||||
Method method = Methods.class.getMethod("typedReturn");
|
||||
ResolvableType type = ResolvableType.forMethodReturn(method);
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(method);
|
||||
assertThat(type.resolve(), nullValue());
|
||||
assertThat(type.getType().toString(), equalTo("T"));
|
||||
}
|
||||
@@ -705,7 +704,7 @@ public class ResolvableTypeTests {
|
||||
@Test
|
||||
public void resolveTypeVariableFromMethodReturnWithImplementsClass() throws Exception {
|
||||
Method method = Methods.class.getMethod("typedReturn");
|
||||
ResolvableType type = ResolvableType.forMethodReturn(method, TypedMethods.class);
|
||||
ResolvableType type = ResolvableType.forMethodReturnType(method, TypedMethods.class);
|
||||
assertThat(type.resolve(), equalTo((Class) String.class));
|
||||
assertThat(type.getType().toString(), equalTo("T"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user