@Test public void testByArgumentTypes() throws ScriptException { MethodExecutionStrategy methodExecutionStrategy = MethodExecutionStrategy.byArgumentTypes( TestMethod.class, "doSomething", new Class<?>[] { String.class, int.class }, "Hello", 42); TestMethod instance = new TestMethod(); Object result = methodExecutionStrategy.execute(instance); assertThat(result).isEqualTo("doSomething(Hello,42)"); }
public static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments) throws ScriptException { try { Method method = clazz.getMethod(methodName, argumentTypes); return byMethod(method, arguments); } catch (NoSuchMethodException e) { throw new ScriptException(e); } }
MethodExecutionStrategy implements ExecutionStrategy { public static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments) throws ScriptException { try { Method method = clazz.getMethod(methodName, argumentTypes); return byMethod(method, arguments); } catch (NoSuchMethodException e) { throw new ScriptException(e); } } }
MethodExecutionStrategy implements ExecutionStrategy { public static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments) throws ScriptException { try { Method method = clazz.getMethod(methodName, argumentTypes); return byMethod(method, arguments); } catch (NoSuchMethodException e) { throw new ScriptException(e); } } private  MethodExecutionStrategy(Method method, Object... arguments); }
MethodExecutionStrategy implements ExecutionStrategy { public static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments) throws ScriptException { try { Method method = clazz.getMethod(methodName, argumentTypes); return byMethod(method, arguments); } catch (NoSuchMethodException e) { throw new ScriptException(e); } } private  MethodExecutionStrategy(Method method, Object... arguments); @Override Object execute(Object instance); static MethodExecutionStrategy byMethod(Method method, Object... arguments); static MethodExecutionStrategy byMainMethod(Class<?> clazz, String... arguments); static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments); static MethodExecutionStrategy byMatchingArguments(Class<?> clazz, String methodName, Object... arguments); }
MethodExecutionStrategy implements ExecutionStrategy { public static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments) throws ScriptException { try { Method method = clazz.getMethod(methodName, argumentTypes); return byMethod(method, arguments); } catch (NoSuchMethodException e) { throw new ScriptException(e); } } private  MethodExecutionStrategy(Method method, Object... arguments); @Override Object execute(Object instance); static MethodExecutionStrategy byMethod(Method method, Object... arguments); static MethodExecutionStrategy byMainMethod(Class<?> clazz, String... arguments); static MethodExecutionStrategy byArgumentTypes(Class<?> clazz, String methodName, Class<?>[] argumentTypes, Object... arguments); static MethodExecutionStrategy byMatchingArguments(Class<?> clazz, String methodName, Object... arguments);  }