@Test public void shouldProcessParamEncodingThem() throws Exception { Serializer serializer = new ToStringSerializer(); ParamConfig paramConfig = mock(ParamConfig.class); when(paramConfig.getSerializer()).thenReturn(serializer); when(paramConfig.isEncoded()).thenReturn(false); when(paramConfig.getName()).thenReturn("p1"); Param param = mock(Param.class); when(param.getParamConfig()).thenReturn(paramConfig); when(param.getValue()).thenReturn((Collection) asList("v 11", "v 12")); List<EncodedPair> actual = toTest.process(param, UTF8, true); assertEquals(1, actual.size()); assertEquals("p1", actual.get(0).getName()); assertEquals("v%2011--v%2012", actual.get(0).getValue()); }
public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { StringBuilder sb = new StringBuilder(); Serializer serializer = param.getParamConfig().getSerializer(); boolean isEncoded = !encodeIfNeeded || param.getParamConfig().isEncoded(); boolean first = true; for(Object value : param.getValue()){ String serializedValue = serialize(serializer, value, charset); if(!first) { sb.append(listSeparator); } sb.append(serializedValue); first = false; } if(sb.length() == 0) { return emptyList(); }else{ return singletonList(toPair(param.getParamConfig().getName(), sb.toString(), charset, isEncoded)); } }
CollectionMergingParamProcessor implements ParamProcessor { public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { StringBuilder sb = new StringBuilder(); Serializer serializer = param.getParamConfig().getSerializer(); boolean isEncoded = !encodeIfNeeded || param.getParamConfig().isEncoded(); boolean first = true; for(Object value : param.getValue()){ String serializedValue = serialize(serializer, value, charset); if(!first) { sb.append(listSeparator); } sb.append(serializedValue); first = false; } if(sb.length() == 0) { return emptyList(); }else{ return singletonList(toPair(param.getParamConfig().getName(), sb.toString(), charset, isEncoded)); } } }
CollectionMergingParamProcessor implements ParamProcessor { public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { StringBuilder sb = new StringBuilder(); Serializer serializer = param.getParamConfig().getSerializer(); boolean isEncoded = !encodeIfNeeded || param.getParamConfig().isEncoded(); boolean first = true; for(Object value : param.getValue()){ String serializedValue = serialize(serializer, value, charset); if(!first) { sb.append(listSeparator); } sb.append(serializedValue); first = false; } if(sb.length() == 0) { return emptyList(); }else{ return singletonList(toPair(param.getParamConfig().getName(), sb.toString(), charset, isEncoded)); } } CollectionMergingParamProcessor(String listSeparator); }
CollectionMergingParamProcessor implements ParamProcessor { public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { StringBuilder sb = new StringBuilder(); Serializer serializer = param.getParamConfig().getSerializer(); boolean isEncoded = !encodeIfNeeded || param.getParamConfig().isEncoded(); boolean first = true; for(Object value : param.getValue()){ String serializedValue = serialize(serializer, value, charset); if(!first) { sb.append(listSeparator); } sb.append(serializedValue); first = false; } if(sb.length() == 0) { return emptyList(); }else{ return singletonList(toPair(param.getParamConfig().getName(), sb.toString(), charset, isEncoded)); } } CollectionMergingParamProcessor(String listSeparator); List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded); }
CollectionMergingParamProcessor implements ParamProcessor { public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { StringBuilder sb = new StringBuilder(); Serializer serializer = param.getParamConfig().getSerializer(); boolean isEncoded = !encodeIfNeeded || param.getParamConfig().isEncoded(); boolean first = true; for(Object value : param.getValue()){ String serializedValue = serialize(serializer, value, charset); if(!first) { sb.append(listSeparator); } sb.append(serializedValue); first = false; } if(sb.length() == 0) { return emptyList(); }else{ return singletonList(toPair(param.getParamConfig().getName(), sb.toString(), charset, isEncoded)); } } CollectionMergingParamProcessor(String listSeparator); List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded);  }