|
|
|
|
@ -44,17 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat;
@@ -44,17 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
class BridgeMethodResolverTests { |
|
|
|
|
|
|
|
|
|
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) { |
|
|
|
|
Method[] methods = targetType.getMethods(); |
|
|
|
|
for (Method m : methods) { |
|
|
|
|
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) { |
|
|
|
|
return m; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void findBridgedMethod() throws Exception { |
|
|
|
|
Method unbridged = MyFoo.class.getDeclaredMethod("someMethod", String.class, Object.class); |
|
|
|
|
@ -106,6 +95,24 @@ class BridgeMethodResolverTests {
@@ -106,6 +95,24 @@ class BridgeMethodResolverTests {
|
|
|
|
|
assertThat(mostSpecificMethod).isSameAs(originalMethod); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void findBridgedMethodWithDefaultMethodInInterfaceHierarchy() throws Exception { |
|
|
|
|
Method getValueDefault = DefaultMethods.class.getMethod("getValue"); |
|
|
|
|
Method getValuesDefault = DefaultMethods.class.getMethod("getValues"); |
|
|
|
|
Method getValueArgDefault = DefaultMethods.class.getMethod("getValue", Integer.class); |
|
|
|
|
Method getValuesArgDefault = DefaultMethods.class.getMethod("getValues", Integer[].class); |
|
|
|
|
for (Method method : ConcreteMethods.class.getMethods()) { |
|
|
|
|
if (method.getName().equals("getValue")) { |
|
|
|
|
assertThat(BridgeMethodResolver.findBridgedMethod(method)).isEqualTo( |
|
|
|
|
method.getParameterCount() > 0 ? getValueArgDefault : getValueDefault); |
|
|
|
|
} |
|
|
|
|
else if (method.getName().equals("getValues")) { |
|
|
|
|
assertThat(BridgeMethodResolver.findBridgedMethod(method)).isEqualTo( |
|
|
|
|
method.getParameterCount() > 0 ? getValuesArgDefault : getValuesDefault); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void findBridgedMethodInHierarchyWithBoundedGenerics() throws Exception { |
|
|
|
|
Method originalMethod = Bar.class.getDeclaredMethod("someMethod", Object.class, Object.class); |
|
|
|
|
@ -161,6 +168,16 @@ class BridgeMethodResolverTests {
@@ -161,6 +168,16 @@ class BridgeMethodResolverTests {
|
|
|
|
|
assertThat(BridgeMethodResolver.findBridgedMethod(loadWithSettingsReturn)).isEqualTo(method); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<?> targetType) { |
|
|
|
|
Method[] methods = targetType.getMethods(); |
|
|
|
|
for (Method m : methods) { |
|
|
|
|
if (m.getName().equals(name) && m.getReturnType().equals(returnType)) { |
|
|
|
|
return m; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void findBridgedMethodFromParent() throws Exception { |
|
|
|
|
Method loadFromParentBridge = SettingsDaoImpl.class.getMethod("loadFromParent"); |
|
|
|
|
@ -451,6 +468,44 @@ class BridgeMethodResolverTests {
@@ -451,6 +468,44 @@ class BridgeMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface InterfaceMethods<T> { |
|
|
|
|
|
|
|
|
|
T getValue(); |
|
|
|
|
|
|
|
|
|
T[] getValues(); |
|
|
|
|
|
|
|
|
|
T getValue(T arg); |
|
|
|
|
|
|
|
|
|
T[] getValues(T[] args); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface DefaultMethods extends InterfaceMethods<Integer> { |
|
|
|
|
|
|
|
|
|
default Integer getValue() { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
default Integer[] getValues() { |
|
|
|
|
return new Integer[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
default Integer getValue(Integer arg) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
default Integer[] getValues(Integer[] args) { |
|
|
|
|
return new Integer[0]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class ConcreteMethods implements DefaultMethods { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class Enclosing<T> { |
|
|
|
|
|
|
|
|
|
public class Enclosed<S> { |
|
|
|
|
|