protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
/** * Create a {@link MethodInvoker} using the provided interface, and method * name from that interface. * * @param cls the interface to search for the method named * @param methodName of the method to be invoked * @param object to be invoked * @param paramTypes - parameter types of the method to search for. * @return MethodInvoker if the method is found, null if it is not. */ public static MethodInvoker getMethodInvokerForInterface(Class<?> cls, String methodName, Object object, Class<?>... paramTypes) { if (cls.isAssignableFrom(object.getClass())) { return MethodInvokerUtils.getMethodInvokerByName(object, methodName, true, paramTypes); } else { return null; } }
@Test public void testExitStatusReturn() throws Throwable{ Map<String, Set<MethodInvoker>> invokerMap = new HashMap<>(); Set<MethodInvoker> invokers = asSet(MethodInvokerUtils.getMethodInvokerByName(testClass, "method3", false)); invokers.add(MethodInvokerUtils.getMethodInvokerByName(testClass, "method3", false)); invokerMap.put("method3", invokers); interceptor = new MethodInvokerMethodInterceptor(invokerMap); assertEquals(ExitStatus.COMPLETED, interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method3")))); }
@Test public void testMultipleInvokersPerName() throws Throwable{ Map<String, Set<MethodInvoker>> invokerMap = new HashMap<>(); Set<MethodInvoker> invokers = asSet(MethodInvokerUtils.getMethodInvokerByName(testClass, "method1", false)); invokers.add(MethodInvokerUtils.getMethodInvokerByName(testClass, "method2", false)); invokerMap.put("method1", invokers); interceptor = new MethodInvokerMethodInterceptor(invokerMap); interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method1"))); assertEquals(1, testClass.method1Count); interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method2"))); assertEquals(1, testClass.method2Count); }
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
/** * Create a {@link MethodInvoker} using the provided interface, and method * name from that interface. * * @param cls the interface to search for the method named * @param methodName of the method to be invoked * @param object to be invoked * @param paramTypes - parameter types of the method to search for. * @return MethodInvoker if the method is found, null if it is not. */ public static MethodInvoker getMethodInvokerForInterface(Class<?> cls, String methodName, Object object, Class<?>... paramTypes) { if (cls.isAssignableFrom(object.getClass())) { return MethodInvokerUtils.getMethodInvokerByName(object, methodName, true, paramTypes); } else { return null; } }