Add missing precondition check to AutowireUtils.resolveDependency

See gh-2060
This commit is contained in:
Sam Brannen
2019-03-02 14:39:43 +01:00
parent 02be21d0dc
commit d4f544d42f
2 changed files with 17 additions and 7 deletions

View File

@@ -159,15 +159,24 @@ public class AutowireUtilsTests {
}
@Test
public void resolveDependencyPreconditionsForBeanFactory() throws Exception {
Method method = getClass().getDeclaredMethod("autowirableMethod", String.class, String.class, String.class, String.class);
Parameter parameter = method.getParameters()[0];
public void resolveDependencyPreconditionsForContainingClass() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("AutowireCapableBeanFactory must not be null");
AutowireUtils.resolveDependency(parameter, 0, null, null);
exception.expectMessage("Containing class must not be null");
AutowireUtils.resolveDependency(getParameter(), 0, null, null);
}
@Test
public void resolveDependencyPreconditionsForBeanFactory() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("AutowireCapableBeanFactory must not be null");
AutowireUtils.resolveDependency(getParameter(), 0, getClass(), null);
}
private Parameter getParameter() throws NoSuchMethodException {
Method method = getClass().getDeclaredMethod("autowirableMethod", String.class, String.class, String.class, String.class);
return method.getParameters()[0];
}
@Test
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
Constructor<?> constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class);