List of usage examples for org.apache.commons.compress.archivers ArchiveOutputStream ArchiveOutputStream
ArchiveOutputStream
From source file:org.dataconservancy.packaging.tool.impl.AnnotationDrivenPackageStateSerializerTest.java
@Test public void testArchiveSerializeApplicationVersion() throws Exception { underTest.setArchive(true);//from w ww . j a va 2 s .c o m underTest.setMarshallerMap(liveMarshallerMap); // Set a spy on the ApplicationVersionConverter ApplicationVersionConverter applicationVersionConverter = spy(new ApplicationVersionConverter()); XStreamMarshaller xsm = (XStreamMarshaller) underTest.getMarshallerMap().get(StreamId.APPLICATION_VERSION) .getMarshaller(); XStream x = xsm.getXStream(); x.registerConverter(applicationVersionConverter, XStream.PRIORITY_VERY_HIGH); // because there is a non-spy // version of this already // registered in the configure // method ByteArrayOutputStream result = new ByteArrayOutputStream(); when(arxFactory.newArchiveOutputStream(result)).thenAnswer(invocationOnMock -> new ArchiveOutputStream() { @Override public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException { } @Override public void closeArchiveEntry() throws IOException { } @Override public void finish() throws IOException { } @Override public ArchiveEntry createArchiveEntry(File file, String s) throws IOException { return mock(ArchiveEntry.class); } @Override public void write(byte[] b, int off, int len) throws IOException { result.write(b, off, len); } }); underTest.serialize(state, StreamId.APPLICATION_VERSION, result); verify(applicationVersionConverter, atLeastOnce()).canConvert(ApplicationVersion.class); // cant verify the marshal(...) method b/c it's final verify(applicationVersionConverter).marshalInternal(eq(applicationVersion), any(HierarchicalStreamWriter.class), any(MarshallingContext.class)); assertTrue(result.size() > 1); }