ArgumentConvertor implements IArgumentConvertor { @Override public Object convertJsonToJava(String jsonArg, Type paramType, Annotation[] parameterAnnotations) throws JsonUnmarshallingException, JsonMarshallerException { if ("null".equals(jsonArg)) { return null; } JsonUnmarshaller juma = getJsonUnmarshallerAnnotation(parameterAnnotations); if (null != juma) { Object result = getResult(jsonArg, argumentServices.getIJsonMarshallerInstance(juma.value()), juma.type()); argumentServices.checkType(result, paramType); return result; } else { return convertArgument(jsonArg, paramType); } }  @Override Object convertJsonToJava(String jsonArg, Type paramType, Annotation[] parameterAnnotations);  }
@Test public void testConvertJsonToJava() throws JsonUnmarshallingException, JsonMarshallerException { System.out.println("convertJsonToJava"); doReturn(null).when(instance).getMarshallerAnnotation(any(Annotation[].class)); doReturn("result").when(instance).convertArgument(anyString(), any(Type.class)); Object result = instance.convertJsonToJava("\"result\"", String.class, new Annotation[]{}); assertThat(result).isEqualTo("result"); }
@Test(expected = JsonUnmarshallingException.class) public void testConvertJsonToJavaBadUnmarshaller() throws DataServiceException, JsonUnmarshallingException, JsonMarshallerException, NoSuchMethodException { System.out.println("convertJsonToJavaBadUnmarshaller"); Method method = ClassAsDataService.class.getMethod("methodWithBadUnmarshaller", String.class); when(argumentServices.getIJsonMarshallerInstance(any(Class.class))).thenThrow(JsonUnmarshallingException.class); Annotation[] annotations = method.getParameterAnnotations()[0]; instance.convertJsonToJava("", null, annotations); }