ArgumentConvertor implements IArgumentConvertor { Object getResult(String jsonArg, IJsonMarshaller ijm, JsonMarshallerType type) throws JsonUnmarshallingException { Object result; switch (type) { case LIST: result = argumentServices.getJavaResultFromSpecificUnmarshallerIterable(jsonArg, ijm); break; case MAP: result = argumentServices.getJavaResultFromSpecificUnmarshallerMap(jsonArg, ijm); break; default: result = ijm.toJava(jsonArg); } return result; }  @Override Object convertJsonToJava(String jsonArg, Type paramType, Annotation[] parameterAnnotations);  }
@Test public void testGetResultSingle() throws JsonUnmarshallingException { System.out.println("getResult"); String jsonArg = "{\"language\":\"fr\",\"country\":\"FR\"}"; LocaleMarshaller lm = new LocaleMarshaller(); Object result = instance.getResult(jsonArg, lm, JsonMarshallerType.SINGLE); assertThat(result).isInstanceOf(Locale.class); }
@Test public void testGetResultIterable() throws JsonUnmarshallingException { System.out.println("getResult"); String jsonArg = "[{\"language\":\"fr\",\"country\":\"FR\"}, {\"language\":\"fr\",\"country\":\"FR\"}]"; LocaleMarshaller lm = new LocaleMarshaller(); when(argumentServices.getJavaResultFromSpecificUnmarshallerIterable(anyString(), any(IJsonMarshaller.class))).thenReturn(Arrays.asList(Locale.FRANCE, Locale.US)); Object result = instance.getResult(jsonArg, lm, JsonMarshallerType.LIST); assertThat(result).isInstanceOf(List.class); }
@Test public void testGetResultMap() throws JsonUnmarshallingException { System.out.println("getResult"); String jsonArg = "{\"KEY1\":{\"language\":\"fr\",\"country\":\"FR\"},\"KEY2\":{\"language\":\"fr\",\"country\":\"FR\"}}"; LocaleMarshaller lm = new LocaleMarshaller(); when(argumentServices.getJavaResultFromSpecificUnmarshallerMap(anyString(), any(IJsonMarshaller.class))).thenReturn(getMapOfLocale()); Object result = instance.getResult(jsonArg, lm, JsonMarshallerType.MAP); assertThat(result).isInstanceOf(Map.class); }