MethodServices { void checkMethod(Method method, List<Object> arguments, List<String> parameters, int nbparam) throws IllegalArgumentException, JsonUnmarshallingException, JsonMarshallerException { Type[] paramTypes = method.getGenericParameterTypes(); Annotation[][] parametersAnnotations = method.getParameterAnnotations(); int idx = 0; for (Type paramType : paramTypes) { logger.debug("Try to convert argument ({}) {} : {}.", new Object[]{idx, paramType, parameters.get(idx)}); arguments.add(argumentConvertor.convertJsonToJava(parameters.get(idx), paramType, parametersAnnotations[idx])); idx++; if (idx > nbparam) { throw new IllegalArgumentException(); } } }  Method getMethodFromDataService(final Class dsClass, final MessageFromClient message, List<Object> arguments); Method getNonProxiedMethod(Class cls, String methodName, Class<?>... parameterTypes);  }
@Test public void testCheckMethod() throws NoSuchMethodException, JsonUnmarshallingException, JsonMarshallerException { String methodname = "methodWith2Arguments"; Class dsClass = ClassAsDataService.class; Method method = dsClass.getMethod(methodname, Integer.class, String.class); List<Object> arguments = new ArrayList<>(); List<String> parameters = Arrays.asList("5", "\"foo\""); int nbparam = 2; when(argumentsServices.convertJsonToJava(anyString(), any(Class.class), any(Annotation[].class))).thenReturn("ok"); instance.checkMethod(method, arguments, parameters, nbparam); assertThat(arguments).hasSize(2); }
@Test(expected = IllegalArgumentException.class) public void testCheckMethodFail() throws NoSuchMethodException, JsonUnmarshallingException, JsonMarshallerException { String methodname = "methodWith2Arguments"; Class dsClass = ClassAsDataService.class; Method method = dsClass.getMethod(methodname, Integer.class, String.class); List<Object> arguments = new ArrayList<>(); List<String> parameters = Arrays.asList("5", "\"foo\""); int nbparam = 1; when(argumentsServices.convertJsonToJava(anyString(), any(Class.class), any(Annotation[].class))).thenReturn("ok"); instance.checkMethod(method, arguments, parameters, nbparam); }