DefaultCookieParamProcessor extends DefaultParamProcessor { @Override public List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded) throws Exception { List<EncodedPair> pairs = super.process(param, charset, encodeIfNeeded); String cookie = join(pairs, ','); if(isBlank(cookie)) { return Collections.emptyList(); } return singletonList(toPreEncodedPair("Cookie", cookie)); }  @Override List<EncodedPair> process(Param param, Charset charset, boolean encodeIfNeeded);  }
@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("Cookie", actual.get(0).getName()); assertEquals("p1=v%2011,p1=v%2012", actual.get(0).getValue()); }
@Test public void shouldProcessPreEncodedParams() throws Exception { Serializer serializer = new ToStringSerializer(); ParamConfig paramConfig = mock(ParamConfig.class); when(paramConfig.getSerializer()).thenReturn(serializer); when(paramConfig.isEncoded()).thenReturn(true); when(paramConfig.getName()).thenReturn("p1"); Param param = mock(Param.class); when(param.getParamConfig()).thenReturn(paramConfig); when(param.getValue()).thenReturn((Collection) asList("v%2011", "v%2012")); List<EncodedPair> actual = toTest.process(param, UTF8, true); assertEquals(1, actual.size()); assertEquals("Cookie", actual.get(0).getName()); assertEquals("p1=v%2011,p1=v%2012", actual.get(0).getValue()); }
@Test public void shouldProcessParamIgnoringEncodingFlag() 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, false); assertEquals(1, actual.size()); assertEquals("Cookie", actual.get(0).getName()); assertEquals("p1=v 11,p1=v 12", actual.get(0).getValue()); }
@Test public void shouldProcessPreEncodedParamsIgnoringEncodingFlag() throws Exception { Serializer serializer = new ToStringSerializer(); ParamConfig paramConfig = mock(ParamConfig.class); when(paramConfig.getSerializer()).thenReturn(serializer); when(paramConfig.isEncoded()).thenReturn(true); when(paramConfig.getName()).thenReturn("p1"); Param param = mock(Param.class); when(param.getParamConfig()).thenReturn(paramConfig); when(param.getValue()).thenReturn((Collection) asList("v%2011", "v%2012")); List<EncodedPair> actual = toTest.process(param, UTF8, false); assertEquals(1, actual.size()); assertEquals("Cookie", actual.get(0).getName()); assertEquals("p1=v%2011,p1=v%2012", actual.get(0).getValue()); }
@Test public void shouldProcessEmptyParams() throws Exception { Serializer serializer = new ToStringSerializer(); ParamConfig paramConfig = mock(ParamConfig.class); when(paramConfig.getSerializer()).thenReturn(serializer); when(paramConfig.isEncoded()).thenReturn(true); when(paramConfig.getName()).thenReturn("p1"); Param param = mock(Param.class); when(param.getParamConfig()).thenReturn(paramConfig); when(param.getValue()).thenReturn(Collections.<Object>emptyList()); List<EncodedPair> actual = toTest.process(param, UTF8, true); assertEquals(0, actual.size()); }