package com.fenixinfotech.jaxb.playpen;

import com.fenixinfotech.jaxb.playpen.SampleRoot;
import com.fenixinfotech.jaxb.playpen.Samples;
import org.junit.Before;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.*;

public class JAXBUtilTest {
    private File testInputFile = null;
    private File testOutputFile = null;
    private JAXBUtil jaxbUtil = null;

    @Before
    public void init() {
        // Input file
        String testFileLocation = "src" + File.separator + "test" + File.separator + "data" + File.separator + "test-data.xml";
        testInputFile = new File(testFileLocation);
        assertNotNull(testInputFile);
        assertTrue(testInputFile.exists());

        // Output file
        String testOutputDirectoryLocation = "target" + File.separator + "test" + File.separator + "data";
        File testOutputDirectory = new File(testOutputDirectoryLocation);
        if (!testOutputDirectory.exists()) {
            testOutputDirectory.mkdirs();
        }
        assertTrue(testOutputDirectory.exists());
        testOutputFile = new File(testOutputDirectory, "test-data" + Math.random() + ".xml");
        assertNotNull(testOutputFile);

        // Util instance
        jaxbUtil = new JAXBUtil();
    }

    @Test
    public void unmarshall() throws Exception {
        Object object = jaxbUtil.unmarshall(testInputFile);
        assertNotNull(object);
        assertTrue(object instanceof SampleRoot);
        SampleRoot sampleRoot = (SampleRoot) object;
        assertEquals(2, sampleRoot.getSamples().getSample().size());
    }

    @Test
    public void marshall() throws Exception {
        SampleRoot sampleRoot = SampleRoot.builder().withId("id0").withSamples(Samples.builder().addSample("Sample0", "Sample1").build()).build();
        jaxbUtil.marshall(sampleRoot, testOutputFile);
    }

}
@@ -1527,60 +1527,306 @@
 sert
-Equals(2, sampleRoot.getSamples().getSample().size()
+NotNull(sampleRoot);%0A%0A        SampleRoot expectedSampleRoot = SampleRoot%0A                .builder()%0A                .withId(%22id0%22)%0A                .withSamples(Samples.builder().withSample(%22Sample0%22, %22Sample1%22).build())%0A                .build();%0A%0A        assertEquals(expectedSampleRoot, sampleRoot
 );%0A 

Build an expected object for the unmarshall and check for equality