@Test public void shouldBuildARequestFromGivenParams() throws Exception { Object[] args = new Object[]{"1",new Object[]{"a","b"}, new Object[]{null}, asList("a","b", "c"), null}; ParamConfig[] extraparams = {}; ParamConfig pc1 = mock(ParamConfig.class); ParamConfig pc2 = mock(ParamConfig.class); ParamConfig pc3 = mock(ParamConfig.class); ParamConfig pc4 = mock(ParamConfig.class); ParamConfig pc5 = mock(ParamConfig.class); RequestInterceptor requestInterceptor = mock(RequestInterceptor.class); Request expected = mock(Request.class); when(mockRequestBuilderFactory.create()).thenReturn(mockRequestBuilder); when(mockMethodConfig.getExtraParams()).thenReturn(extraparams); when(mockRequestBuilder.addParams(extraparams)).thenReturn(mockRequestBuilder); when(mockMethodConfig.getParamCount()).thenReturn(args.length); when(mockMethodConfig.getParamConfig(0)).thenReturn(pc1); when(mockMethodConfig.getParamConfig(1)).thenReturn(pc2); when(mockMethodConfig.getParamConfig(2)).thenReturn(pc3); when(mockMethodConfig.getParamConfig(3)).thenReturn(pc4); when(mockMethodConfig.getParamConfig(4)).thenReturn(pc5); when(mockMethodConfig.getRequestInterceptor()).thenReturn(requestInterceptor); when(pc5.getDefaultValue()).thenReturn("default"); when(mockRequestBuilder.build(mockMethodConfig)).thenReturn(expected); Request actual = Requests.from(mockRequestBuilderFactory, mockMethodConfig, args); assertSame(expected, actual); verify(mockRequestBuilder).addParams(extraparams); verify(mockRequestBuilder).addParam(pc1, Collections.<Object>singleton("1")); verify(mockRequestBuilder).addParam(pc2, Arrays.<Object>asList("a","b")); verify(mockRequestBuilder).addParam(pc4, Arrays.<Object>asList("a","b","c")); verify(mockRequestBuilder).addParam(pc5); verify(requestInterceptor).beforeFire(mockRequestBuilder, mockMethodConfig, args); verify(mockRequestBuilder).build(mockMethodConfig); verifyNoMoreInteractions(mockRequestBuilder); }
public static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args) throws Exception { RequestBuilder builder = factory.create().addParams(mc.getExtraParams()); for (int i = 0; i < mc.getParamCount(); i++) { Collection<Object> values = Objects.asCollection(args[i]); ParamConfig pc = mc.getParamConfig(i); if(containsOnlyNulls(values)) { if(pc.getDefaultValue() != null) { builder.addParam(pc); } }else{ builder.addParam(pc, values); } } mc.getRequestInterceptor().beforeFire(builder, mc, args); return builder.build(mc); }
Requests { public static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args) throws Exception { RequestBuilder builder = factory.create().addParams(mc.getExtraParams()); for (int i = 0; i < mc.getParamCount(); i++) { Collection<Object> values = Objects.asCollection(args[i]); ParamConfig pc = mc.getParamConfig(i); if(containsOnlyNulls(values)) { if(pc.getDefaultValue() != null) { builder.addParam(pc); } }else{ builder.addParam(pc, values); } } mc.getRequestInterceptor().beforeFire(builder, mc, args); return builder.build(mc); } }
Requests { public static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args) throws Exception { RequestBuilder builder = factory.create().addParams(mc.getExtraParams()); for (int i = 0; i < mc.getParamCount(); i++) { Collection<Object> values = Objects.asCollection(args[i]); ParamConfig pc = mc.getParamConfig(i); if(containsOnlyNulls(values)) { if(pc.getDefaultValue() != null) { builder.addParam(pc); } }else{ builder.addParam(pc, values); } } mc.getRequestInterceptor().beforeFire(builder, mc, args); return builder.build(mc); } private  Requests(); }
Requests { public static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args) throws Exception { RequestBuilder builder = factory.create().addParams(mc.getExtraParams()); for (int i = 0; i < mc.getParamCount(); i++) { Collection<Object> values = Objects.asCollection(args[i]); ParamConfig pc = mc.getParamConfig(i); if(containsOnlyNulls(values)) { if(pc.getDefaultValue() != null) { builder.addParam(pc); } }else{ builder.addParam(pc, values); } } mc.getRequestInterceptor().beforeFire(builder, mc, args); return builder.build(mc); } private  Requests(); static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args); }
Requests { public static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args) throws Exception { RequestBuilder builder = factory.create().addParams(mc.getExtraParams()); for (int i = 0; i < mc.getParamCount(); i++) { Collection<Object> values = Objects.asCollection(args[i]); ParamConfig pc = mc.getParamConfig(i); if(containsOnlyNulls(values)) { if(pc.getDefaultValue() != null) { builder.addParam(pc); } }else{ builder.addParam(pc, values); } } mc.getRequestInterceptor().beforeFire(builder, mc, args); return builder.build(mc); } private  Requests(); static Request from(RequestBuilderFactory factory, MethodConfig mc, Object[] args);  }