mdbuck77 commented on a change in pull request #680:
URL: https://github.com/apache/commons-lang/pull/680#discussion_r547396104
##########
File path: src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
##########
@@ -1018,4 +1019,83 @@ public void testDistance() throws Exception {
distanceMethod.setAccessible(false);
}
+
+ @Test
+ public void testGetMatchingMethod() throws NoSuchMethodException {
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod"),
+ GetMatchingMethodClass.class.getMethod("testMethod"));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod", Long.TYPE),
+ GetMatchingMethodClass.class.getMethod("testMethod",
Long.TYPE));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod", Long.class),
+ GetMatchingMethodClass.class.getMethod("testMethod",
Long.class));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod", (Class<?>) null),
+ GetMatchingMethodClass.class.getMethod("testMethod",
Long.class));
+
+ assertThrows(IllegalStateException.class,
+ () ->
MethodUtils.getMatchingMethod(GetMatchingMethodClass.class, "testMethod2",
(Class<?>) null));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod3", Long.TYPE, Long.class),
+ GetMatchingMethodClass.class.getMethod("testMethod3",
Long.TYPE, Long.class));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod3", Long.class, Long.TYPE),
+ GetMatchingMethodClass.class.getMethod("testMethod3",
Long.class, Long.TYPE));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod3", null, Long.TYPE),
+ GetMatchingMethodClass.class.getMethod("testMethod3",
Long.class, Long.TYPE));
+
+
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodClass.class,
"testMethod3", Long.TYPE, null),
+ GetMatchingMethodClass.class.getMethod("testMethod3",
Long.TYPE, Long.class));
+
+ assertThrows(IllegalStateException.class,
+ () ->
MethodUtils.getMatchingMethod(GetMatchingMethodClass.class, "testMethod4",
null, null));
+ }
+
+ private static final class GetMatchingMethodClass {
+ public String testMethod() {
+ return "testMethod";
+ }
+
+ public String testMethod(Long aLong) {
Review comment:
Done.
Michael
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]