Skip to content

Commit 338a377

Browse files
committed
[LANG-1778] MethodUtils.getMatchingMethod() doesn't respect the
hierarchy of methods #1414 - Javadoc - Sort members - Simplify test
1 parent 1e45583 commit 338a377

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
4848
<!-- FIX -->
4949
<action type="fix" dev="ppkarwasz" due-to="Sebastian Steiner">[javadoc] Fix typo in Javadoc of Strings instances #1406.</action>
5050
<action type="fix" dev="ggregory" due-to="Hassan A Hashim">[javadoc] Fix Javadocs in ClassUtils #1410.</action>
51+
<action issue="LANG-1778" type="fix" dev="ggregory" due-to="wuwu2000">MethodUtils.getMatchingMethod() doesn't respect the hierarchy of methods #1414.</action>
5152
<!-- ADD -->
5253
<!-- UPDATE -->
5354
</release>

src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import org.junit.jupiter.api.Test;
5858

5959
/**
60-
* Tests MethodUtils
60+
* {@link Tests MethodUtils}.
6161
*/
6262
class MethodUtilsTest extends AbstractLangTest {
6363
protected abstract static class AbstractGetMatchingMethod implements InterfaceGetMatchingMethod {
@@ -74,6 +74,13 @@ interface ChildInterface {
7474
public static class ChildObject extends ParentObject implements ChildInterface {
7575
}
7676

77+
private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 { }
78+
79+
private static final class ConcreteGetMatchingMethod22 extends AbstractGetMatchingMethod2 {
80+
@Override
81+
public void testMethod6() { }
82+
}
83+
7784
private static final class GetMatchingMethodClass {
7885

7986
public void testMethod() {
@@ -109,19 +116,12 @@ public void testMethod4(final Color aColor1, final Color aColor2) {
109116
public void testMethod4(final Long aLong, final Long anotherLong) {
110117
}
111118
}
112-
113119
private static final class GetMatchingMethodImpl extends AbstractGetMatchingMethod {
114120
@Override
115121
public void testMethod5(final Exception exception) {
116122
}
117123
}
118124

119-
private static final class ConcreteGetMatchingMethod2 extends AbstractGetMatchingMethod2 { }
120-
private static final class ConcreteGetMatchingMethod22 extends AbstractGetMatchingMethod2 {
121-
@Override
122-
public void testMethod6() { }
123-
}
124-
125125
public static class GrandParentObject {
126126
}
127127
public static class InheritanceBean {
@@ -681,16 +681,13 @@ void testGetMatchingMethod() throws NoSuchMethodException {
681681
assertNullPointerException(
682682
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
683683

684-
{
685-
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
686-
assertNotNull(testMethod6);
687-
assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
688-
}
689-
{
690-
final Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod22.class, "testMethod6");
691-
assertNotNull(testMethod6);
692-
assertEquals(ConcreteGetMatchingMethod22.class, testMethod6.getDeclaringClass());
693-
}
684+
Method testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod2.class, "testMethod6");
685+
assertNotNull(testMethod6);
686+
assertEquals(AbstractGetMatchingMethod2.class, testMethod6.getDeclaringClass());
687+
688+
testMethod6 = MethodUtils.getMatchingMethod(ConcreteGetMatchingMethod22.class, "testMethod6");
689+
assertNotNull(testMethod6);
690+
assertEquals(ConcreteGetMatchingMethod22.class, testMethod6.getDeclaringClass());
694691
}
695692

696693
@Test

0 commit comments

Comments
 (0)