UiFrameworkUtil { public static Object invokeMethodWithArguments(Object target, Method method, Map<Class<?>, Object> possibleArguments, ConversionService conversionService, ApplicationContext applicationContext) throws PageAction { try { Class<?>[] types = method.getParameterTypes(); Object[] params = new Object[types.length]; for (int i = 0; i < types.length; ++i) { Object result = determineArgumentValue(target, possibleArguments, new MethodParameter(method, i), conversionService, applicationContext); if (result instanceof BindingResult) { params[i] = ((BindingResult) result).getTarget(); if ((i + 1 < types.length) && Errors.class.isAssignableFrom(types[i + 1])) { params[i + 1] = result; i += 1; } } else { params[i] = result; } } return method.invoke(target, params); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ((InvocationTargetException) ex).getTargetException() instanceof Exception) { ex = (Exception) ((InvocationTargetException) ex).getTargetException(); } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } if (ex.getCause() != null && ex.getCause() instanceof RuntimeException) throw (RuntimeException) ex.getCause(); if (ex instanceof PageAction) throw (PageAction) ex; throw new UiFrameworkException("Exception in controller method", ex); } }  static Object executeControllerMethod(Object controller, String httpRequestMethod, Map<Class<?>, Object> possibleArguments,
                                                 ConversionService conversionService, ApplicationContext applicationContext); static Object invokeMethodWithArguments(Object target, Method method, Map<Class<?>, Object> possibleArguments,
                                                   ConversionService conversionService, ApplicationContext applicationContext); static Object[] determineControllerMethodParameters(Object controller, Method method, Map<Class<?>, Object> argumentsByType,
                                                               ConversionService conversionService, ApplicationContext applicationContext); static Object determineArgumentValue(Object controller, Map<Class<?>, Object> valuesByType, MethodParameter methodParam,
                                                ConversionService conversionService, ApplicationContext applicationContext); @SuppressWarnings("unchecked") static T findCause(Throwable t, Class<T> lookFor); static String getMessage(MessageSourceResolvable msg); static boolean checkAndSetDevelopmentModeForProvider(String key, Object provider); static DateFormat getDateFormat(AdministrationService administrationService, Locale locale); static DateFormat getDateTimeFormat(AdministrationService administrationService, Locale locale); static DateFormat getTimeFormat(AdministrationService administrationService, Locale locale);  }
@Test public void test_invokeMethodWithArgumentsShouldHandleBindParamsAnnotation() throws Exception { final String expectedName = "expectedName"; final Integer one = new Integer(1); Object controller = new Object() { public void post(@BindParams MockDomainObject command, Integer nextArg) { assertThat(command.getName(), is(expectedName)); assertThat(nextArg, is(one)); } public void postAndValidate(@BindParams MockDomainObject command, Errors errors, Integer nextArg) { assertThat(command.getName(), is(expectedName)); assertThat(errors, is(notNullValue())); assertThat(errors.hasErrors(), is(false)); assertThat(nextArg, is(one)); } }; Method postMethod1 = controller.getClass().getMethod("post", MockDomainObject.class, Integer.class); Method postMethod2 = controller.getClass().getMethod("postAndValidate", MockDomainObject.class, Errors.class, Integer.class); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("name", expectedName); HashMap<Class<?>, Object> possibleArguments = new HashMap<Class<?>, Object>(); possibleArguments.put(HttpServletRequest.class, request); possibleArguments.put(Integer.class, one); UiFrameworkUtil.invokeMethodWithArguments(controller, postMethod1, possibleArguments, conversionService, applicationContext); UiFrameworkUtil.invokeMethodWithArguments(controller, postMethod2, possibleArguments, conversionService, applicationContext); }