@Test public void testDeserializeZipArchiveSimple() throws Exception { // produce a zip archive containing a single serialized stream for this test. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(baos); ZipArchiveEntry zipEntry = new ZipArchiveEntry(StreamId.APPLICATION_VERSION.name()); zipOut.putArchiveEntry(zipEntry); IOUtils.copy(APPLICATION_VERSION_1.getInputStream(), zipOut); zipOut.closeArchiveEntry(); zipOut.close(); state = new PackageState(); when(mockedMarshallerMap .get(StreamId.APPLICATION_VERSION) .getUnmarshaller() .unmarshal(any(Source.class))) .thenReturn(applicationVersion); ByteArrayInputStream zipIn = new ByteArrayInputStream(baos.toByteArray()); underTest.deserialize(state, StreamId.APPLICATION_VERSION, zipIn); assertNotNull(state.getCreationToolVersion()); assertEquals(applicationVersion, state.getCreationToolVersion()); verify(mockedMarshallerMap.get(StreamId.APPLICATION_VERSION).getUnmarshaller()) .unmarshal(any(Source.class)); }
@Test public void testDeserializeSimple() throws Exception { state = new PackageState(); when(mockedMarshallerMap .get(StreamId.APPLICATION_VERSION) .getUnmarshaller() .unmarshal(any(Source.class))) .thenReturn(applicationVersion); underTest.deserialize( state, StreamId.APPLICATION_VERSION, new BufferedInputStream(APPLICATION_VERSION_1.getInputStream())); assertNotNull(state.getCreationToolVersion()); assertEquals(applicationVersion, state.getCreationToolVersion()); verify(mockedMarshallerMap.get(StreamId.APPLICATION_VERSION).getUnmarshaller()) .unmarshal(any(Source.class)); }
@Test public void testSerializeStreamWithNullFieldInPackageState() throws Exception { state = new PackageState(); StreamResult result = new StreamResult(new NullOutputStream()); // we're using mocks, so nothing will be // written to the output stream assertNull(state.getCreationToolVersion()); underTest.serializeToResult(state, StreamId.APPLICATION_VERSION, result); // Nothing was serialized, the application version field for the state was null. verifyZeroInteractions(mockedMarshallerMap.get(StreamId.APPLICATION_VERSION).getMarshaller()); // Set a non-null value, and try again state.setCreationToolVersion(applicationVersion); underTest.serializeToResult(state, StreamId.APPLICATION_VERSION, result); verify(mockedMarshallerMap.get(StreamId.APPLICATION_VERSION).getMarshaller()) .marshal(applicationVersion, result); }