@Test
  public void testArchiveSerializeApplicationVersion() throws Exception {
    underTest.setArchive(true);
    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);
  }
  @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);
  }