MultiPartBinarySerializer implements Serializer<MultiPart<Param>> { public void serialize(MultiPart<Param> multipart, Charset charset, OutputStream out) throws Exception { Serializer<MultiPart<?>> serializer = getSerializer(multipart.getParamConfig().getValueClass()); serialize(multipart, charset, out, serializer); }  void serialize(MultiPart<Param> multipart, Charset charset, OutputStream out);  }
@Test public void serializeShouldInterateOverAllParamValuesAndSerializeThem() throws Exception { Serializer serializer = mock(Serializer.class); OutputStream out = mock(OutputStream.class); Param param = mock(Param.class); ParamConfig paramConfig = mock(ParamConfig.class); when(param.getValue()).thenReturn(Arrays.<Object>asList("a", "b")); MultiPart<Param> multiPart = new MultiPart<Param>(paramConfig,param, "boundary"); MultiPartBinarySerializer.serialize(multiPart, UTF8, out, serializer); ArgumentCaptor<MultiPart> mp = ArgumentCaptor.forClass((Class)MultiPart.class); verify(serializer, times(2)).serialize(mp.capture(), eq(UTF8), eq(out)); assertEquals("boundary", mp.getAllValues().get(0).getBoundary()); assertSame(paramConfig, mp.getAllValues().get(0).getParamConfig()); assertSame("a", mp.getAllValues().get(0).getValue()); assertEquals("boundary", mp.getAllValues().get(1).getBoundary()); assertSame(paramConfig, mp.getAllValues().get(1).getParamConfig()); assertSame("b", mp.getAllValues().get(1).getValue()); }