@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);
  }
  @Before
  public void setUp() throws Exception {

    /*
     A mock ArchiveOutputStream
    */
    ArchiveOutputStream arxOs = mock(ArchiveOutputStream.class);

    /*
     * Mock the classes related to archiving support
     */
    arxFactory = mock(ArchiveStreamFactory.class);
    when(arxFactory.newArchiveOutputStream(any(OutputStream.class))).thenReturn(arxOs);

    /*
     * Populate the live package state object with test objects
     */
    state.setCreationToolVersion(applicationVersion);
    state.setPackageName(packageName);
    state.setPackageMetadataList(packageMetadata);
    state.setDomainProfileIdList(domainProfileUris);
    state.setDomainObjectRDF(domainObjectsRDF);
    state.setUserSpecifiedProperties(userProperties);
    state.setPackageTree(packageTreeRDF);

    /*
     * Configure the live stream marshalling map with XStream converters.  Not all streams are marshalled by
     * XStream.  The PACKAGE_TREE and DOMAIN_OBJECTS streams are RDF, and marshalled by Jena.
     */

    /* Marshallers */
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.APPLICATION_VERSION).getMarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.PACKAGE_NAME).getMarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.PACKAGE_METADATA).getMarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller)
                liveMarshallerMap.get(StreamId.USER_SPECIFIED_PROPERTIES).getMarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.DOMAIN_PROFILE_LIST).getMarshaller())
            .getXStream());

    /* Unmarshallers */
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.APPLICATION_VERSION).getUnmarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.PACKAGE_NAME).getUnmarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.PACKAGE_METADATA).getUnmarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller)
                liveMarshallerMap.get(StreamId.USER_SPECIFIED_PROPERTIES).getUnmarshaller())
            .getXStream());
    configure(
        ((XStreamMarshaller) liveMarshallerMap.get(StreamId.DOMAIN_PROFILE_LIST).getUnmarshaller())
            .getXStream());

    /*
     * Configure the class under test with the mocked marshaller map, and the mock archive
     * stream factory.  Individual tests can set their marshallers, like using a live marshaller map.
     */
    underTest.setMarshallerMap(mockedMarshallerMap);
    underTest.setArxStreamFactory(arxFactory);
  }