MethodResolver { public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; }  static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes);  }
@Test public void testResolveMethod1() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "abs"; Class< ? >[] paramTypes = new Class< ? >[] {int.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, int.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod2() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "abs"; Class< ? >[] paramTypes = new Class< ? >[] {Integer.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, int.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod3() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "abd"; Class< ? >[] paramTypes = new Class< ? >[] {Integer.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = null; Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod4() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "abs"; Class< ? >[] paramTypes = new Class< ? >[] {byte.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, int.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod5() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "abs"; Class< ? >[] paramTypes = new Class< ? >[] {char.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, int.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod6() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "round"; Class< ? >[] paramTypes = new Class< ? >[] {int.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, float.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod7() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "round"; Class< ? >[] paramTypes = new Class< ? >[] {long.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, float.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod8() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "log"; Class< ? >[] paramTypes = new Class< ? >[] {int.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, double.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod9() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.Math"); String methodName = "log"; Class< ? >[] paramTypes = new Class< ? >[] {float.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, double.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod10() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.String"); String methodName = "valueOf"; Class< ? >[] paramTypes = new Class< ? >[] {String.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, Object.class); Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod11() throws ClassNotFoundException, NoSuchMethodException{ Class< ? > declareClass = Class.forName("com.huawei.streaming.expression.MethodTest"); String methodName = "f"; Class< ? >[] paramTypes = new Class< ? >[] {int.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = null; Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod12() throws ClassNotFoundException, NoSuchMethodException{ Class< ? > declareClass = Class.forName("com.huawei.streaming.expression.MethodTest"); String methodName = "f"; Class< ? >[] paramTypes = new Class< ? >[] {Integer.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = null; Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod13() throws ClassNotFoundException, NoSuchMethodException{ Class< ? > declareClass = Class.forName("com.huawei.streaming.expression.MethodTest"); String methodName = "f2"; Class< ? >[] paramTypes = new Class< ? >[] {int.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, Integer.class);; Assert.assertEquals(expectedMethod, actualMethod); }
@Test public void testResolveMethod14() throws ClassNotFoundException, NoSuchMethodException{ Class< ? > declareClass = Class.forName("com.huawei.streaming.expression.MethodTest"); String methodName = "f3"; Class< ? >[] paramTypes = new Class< ? >[] {Integer.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, int.class);; Assert.assertEquals(expectedMethod, actualMethod); }