Skip to content

Commit

Permalink
[LANG-1754] Use getAllSuperclassesAndInterfaces() in getMatchingMetho…
Browse files Browse the repository at this point in the history
…d(). (#1289)

Co-authored-by: Vaclav Haisman <[email protected]>
  • Loading branch information
vhbcm and wilx authored Oct 10, 2024
1 parent 37cb5a4 commit 6597040
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static Method getMatchingMethod(final Class<?> cls, final String methodNa
.filter(method -> method.getName().equals(methodName))
.collect(Collectors.toList());

ClassUtils.getAllSuperclasses(cls).stream()
getAllSuperclassesAndInterfaces(cls).stream()
.map(Class::getDeclaredMethods)
.flatMap(Stream::of)
.filter(method -> method.getName().equals(methodName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@
* Unit tests MethodUtils
*/
public class MethodUtilsTest extends AbstractLangTest {
interface InterfaceGetMatchingMethod {
default void testMethod6() {
}
}

protected abstract static class AbstractGetMatchingMethod {
protected abstract static class AbstractGetMatchingMethod implements InterfaceGetMatchingMethod {
public abstract void testMethod5(Exception exception);
}

Expand Down Expand Up @@ -682,6 +686,9 @@ public void testGetMatchingMethod() throws NoSuchMethodException {
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodImpl.class, "testMethod5", RuntimeException.class),
GetMatchingMethodImpl.class.getMethod("testMethod5", Exception.class));

assertEquals(GetMatchingMethodImpl.class.getMethod("testMethod6"),
MethodUtils.getMatchingMethod(GetMatchingMethodImpl.class, "testMethod6"));

assertThrows(NullPointerException.class,
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
}
Expand Down

0 comments on commit 6597040

Please sign in to comment.