This commit is contained in:
Stephane Nicoll 2023-08-24 09:04:14 +02:00
parent c809fda4ed
commit 86e02a47fb
1 changed files with 17 additions and 13 deletions

View File

@ -394,22 +394,25 @@ class ClassUtilsTests {
@Test
void getMostSpecificMethod() throws NoSuchMethodException {
Method defaultPrintMethod = ClassUtils.getMethod(MethodsInterface.class, "defaultPrint");
assertThat(ClassUtils.getMostSpecificMethod(defaultPrintMethod, MethodsInterfaceImplementation.class)).isEqualTo(defaultPrintMethod);
assertThat(ClassUtils.getMostSpecificMethod(defaultPrintMethod, SubMethodsInterfaceImplementation.class)).isEqualTo(defaultPrintMethod);
assertThat(ClassUtils.getMostSpecificMethod(defaultPrintMethod, MethodsInterfaceImplementation.class))
.isEqualTo(defaultPrintMethod);
assertThat(ClassUtils.getMostSpecificMethod(defaultPrintMethod, SubMethodsInterfaceImplementation.class))
.isEqualTo(defaultPrintMethod);
Method printMethod = ClassUtils.getMethod(MethodsInterface.class, "print", String.class);
assertThat(ClassUtils.getMostSpecificMethod(printMethod, MethodsInterfaceImplementation.class)).isNotEqualTo(printMethod);
assertThat(ClassUtils.getMostSpecificMethod(printMethod, MethodsInterfaceImplementation.class))
.isNotEqualTo(printMethod);
assertThat(ClassUtils.getMostSpecificMethod(printMethod, MethodsInterfaceImplementation.class))
.isEqualTo(ClassUtils.getMethod(MethodsInterfaceImplementation.class, "print", String.class));
assertThat(ClassUtils.getMostSpecificMethod(printMethod, SubMethodsInterfaceImplementation.class))
.isEqualTo(ClassUtils.getMethod(MethodsInterfaceImplementation.class, "print", String.class));
Method protectedPrintMethod = MethodsInterfaceImplementation.class.getDeclaredMethod("protectedPrint");
assertThat(ClassUtils.getMostSpecificMethod(protectedPrintMethod, MethodsInterfaceImplementation.class)).isEqualTo(protectedPrintMethod);
assertThat(ClassUtils.getMostSpecificMethod(protectedPrintMethod, MethodsInterfaceImplementation.class))
.isEqualTo(protectedPrintMethod);
assertThat(ClassUtils.getMostSpecificMethod(protectedPrintMethod, SubMethodsInterfaceImplementation.class))
.isEqualTo(SubMethodsInterfaceImplementation.class.getDeclaredMethod("protectedPrint"));
Method packageAccessiblePrintMethod = MethodsInterfaceImplementation.class.getDeclaredMethod("packageAccessiblePrint");
assertThat(ClassUtils.getMostSpecificMethod(packageAccessiblePrintMethod, MethodsInterfaceImplementation.class))
.isEqualTo(packageAccessiblePrintMethod);
@ -590,6 +593,7 @@ class ClassUtilsTests {
default void defaultPrint() {
}
void print(String messages);
}