@Test public void shouldUseFactoryWithGivenConfigAndDeserializeAccordingly() throws Exception { Serializer mock = mock(Serializer.class); String str = "hello"; mockStatic(SimpleXmlFactory.class); when(SimpleXmlFactory.createSerializer(any(CRestConfig.class), any(Class.class))).thenReturn(mock); when(mock.read(any(Class.class),any(Reader.class),anyBoolean())).thenReturn(str); SimpleXmlDeserializer toTest = new SimpleXmlDeserializer(config); verify(config).get(SimpleXmlDeserializer.STRICT_PROP, true); verifyStatic(); SimpleXmlFactory.createSerializer(config, SimpleXmlDeserializer.class); assertEquals(str, toTest.deserialize(String.class, String.class, mock(InputStream.class), UTF8)); ArgumentCaptor<Reader> reader = ArgumentCaptor.forClass(Reader.class); verify(mock).read(eq(String.class), reader.capture(), eq(true)); assertEquals(InputStreamReader.class, reader.getValue().getClass()); assertEquals("UTF8", InputStreamReader.class.cast(reader.getValue()).getEncoding()); }
public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws Exception { try { return serializer.read(type, new InputStreamReader(stream, charset), strict); } finally { IOs.close(stream); } }
SimpleXmlDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws Exception { try { return serializer.read(type, new InputStreamReader(stream, charset), strict); } finally { IOs.close(stream); } } }
SimpleXmlDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws Exception { try { return serializer.read(type, new InputStreamReader(stream, charset), strict); } finally { IOs.close(stream); } } SimpleXmlDeserializer(CRestConfig crestConfig); }
SimpleXmlDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws Exception { try { return serializer.read(type, new InputStreamReader(stream, charset), strict); } finally { IOs.close(stream); } } SimpleXmlDeserializer(CRestConfig crestConfig); T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset); }
SimpleXmlDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws Exception { try { return serializer.read(type, new InputStreamReader(stream, charset), strict); } finally { IOs.close(stream); } } SimpleXmlDeserializer(CRestConfig crestConfig); T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset); static final String STRICT_PROP; static final String SERIALIZER_PROP; }