Consistent support for Java 8 default methods (in interfaces implemented by user classes)
Covers ReflectionUtils.doWithMethods as well as affected annotation post-processors. Includes an extension of MethodMetadata for the detection of @Bean default methods. Issue: SPR-12822 Issue: SPR-10919
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,8 +66,8 @@ public class ReflectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void setField() {
|
||||
final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
|
||||
final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
|
||||
TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
|
||||
Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
@@ -79,13 +79,6 @@ public class ReflectionUtilsTests {
|
||||
assertNull(testBean.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void setFieldIllegal() {
|
||||
final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
|
||||
final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
|
||||
ReflectionUtils.setField(field, testBean, "FooBar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeMethod() throws Exception {
|
||||
String rob = "Rob Harrop";
|
||||
@@ -94,65 +87,50 @@ public class ReflectionUtilsTests {
|
||||
bean.setName(rob);
|
||||
|
||||
Method getName = TestObject.class.getMethod("getName", (Class[]) null);
|
||||
Method setName = TestObject.class.getMethod("setName", new Class[] { String.class });
|
||||
Method setName = TestObject.class.getMethod("setName", String.class);
|
||||
|
||||
Object name = ReflectionUtils.invokeMethod(getName, bean);
|
||||
assertEquals("Incorrect name returned", rob, name);
|
||||
|
||||
String juergen = "Juergen Hoeller";
|
||||
ReflectionUtils.invokeMethod(setName, bean, new Object[] { juergen });
|
||||
ReflectionUtils.invokeMethod(setName, bean, juergen);
|
||||
assertEquals("Incorrect name set", juergen, bean.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void declaresException() throws Exception {
|
||||
Method remoteExMethod = A.class.getDeclaredMethod("foo", new Class[] { Integer.class });
|
||||
Method remoteExMethod = A.class.getDeclaredMethod("foo", Integer.class);
|
||||
assertTrue(ReflectionUtils.declaresException(remoteExMethod, RemoteException.class));
|
||||
assertTrue(ReflectionUtils.declaresException(remoteExMethod, ConnectException.class));
|
||||
assertFalse(ReflectionUtils.declaresException(remoteExMethod, NoSuchMethodException.class));
|
||||
assertFalse(ReflectionUtils.declaresException(remoteExMethod, Exception.class));
|
||||
|
||||
Method illegalExMethod = B.class.getDeclaredMethod("bar", new Class[] { String.class });
|
||||
Method illegalExMethod = B.class.getDeclaredMethod("bar", String.class);
|
||||
assertTrue(ReflectionUtils.declaresException(illegalExMethod, IllegalArgumentException.class));
|
||||
assertTrue(ReflectionUtils.declaresException(illegalExMethod, NumberFormatException.class));
|
||||
assertFalse(ReflectionUtils.declaresException(illegalExMethod, IllegalStateException.class));
|
||||
assertFalse(ReflectionUtils.declaresException(illegalExMethod, Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void copySrcToDestinationOfIncorrectClass() {
|
||||
TestObject src = new TestObject();
|
||||
String dest = new String();
|
||||
try {
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// Ok
|
||||
}
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullSrc() {
|
||||
TestObject src = null;
|
||||
String dest = new String();
|
||||
try {
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// Ok
|
||||
}
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullDest() {
|
||||
TestObject src = new TestObject();
|
||||
String dest = null;
|
||||
try {
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// Ok
|
||||
}
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user