ServiceServices { OcelotMethod getOcelotMethod(Method method) { OcelotMethod ocelotMethod = new OcelotMethod(method.getName(), serviceTools.getShortName(serviceTools.getLiteralType(method.getGenericReturnType()))); Annotation[][] annotations = method.getParameterAnnotations(); Type[] types = method.getGenericParameterTypes(); int index = 0; for (Type type : types) { ocelotMethod.getArgtypes().add(serviceTools.getShortName(serviceTools.getLiteralType(type))); try { ocelotMethod.getArgtemplates().add(serviceTools.getTemplateOfType(type, serviceTools.getJsonMarshaller(annotations[index]))); } catch (JsonMarshallerException ex) { ocelotMethod.getArgtemplates().add(type.getTypeName()); } index++; } return ocelotMethod; }  List<OcelotService> getServices(HttpSession httpSession);  }
@Test public void testGetOcelotMethod0Arg() throws NoSuchMethodException { System.out.println("getOcelotMethod"); Method method = this.getClass().getDeclaredMethod("methodWith0Arg"); when(serviceTools.getShortName(anyString())).thenReturn("returntype"); OcelotMethod result = instance.getOcelotMethod(method); assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo("methodWith0Arg"); assertThat(result.getReturntype()).isEqualTo("returntype"); assertThat(result.getArgtypes()).isEmpty(); assertThat(result.getArgtemplates()).isEmpty(); }
@Test public void testGetOcelotMethod2Args() throws NoSuchMethodException, JsonMarshallerException { System.out.println("getOcelotMethod"); Method method = this.getClass().getDeclaredMethod("methodWith2Args", String.class, String.class); when(serviceTools.getShortName(anyString())).thenReturn("returntype").thenReturn("argtype"); when(serviceTools.getTemplateOfType(any(Type.class), any(IJsonMarshaller.class))).thenReturn("template"); OcelotMethod result = instance.getOcelotMethod(method); assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo("methodWith2Args"); assertThat(result.getReturntype()).isEqualTo("returntype"); assertThat(result.getArgtypes()).hasSize(2); assertThat(result.getArgtemplates()).hasSize(2); }
@Test public void testGetOcelotMethod2ArgsWithOneUnmarshalled() throws NoSuchMethodException, JsonMarshallerException { System.out.println("getOcelotMethod"); Method method = this.getClass().getDeclaredMethod("methodWith2Args", String.class, String.class); when(serviceTools.getShortName(anyString())).thenReturn("returntype").thenReturn("argtype"); when(serviceTools.getTemplateOfType(any(Type.class), any(IJsonMarshaller.class))).thenReturn("template").thenThrow(JsonMarshallerException.class); OcelotMethod result = instance.getOcelotMethod(method); assertThat(result).isNotNull(); assertThat(result.getName()).isEqualTo("methodWith2Args"); assertThat(result.getReturntype()).isEqualTo("returntype"); assertThat(result.getArgtypes()).hasSize(2); assertThat(result.getArgtemplates()).hasSize(2); assertThat(result.getArgtemplates().get(1)).isEqualTo("java.lang.String"); }