StartTimesMerger extends AbstractElementMerger { @Override public void mergeNodes(List<Node> fromParents, Element toParent, Document toDocument) throws PDUStitchingException { String earliestDateAsNodeValue = fromParents.get(0).getFirstChild().getNodeValue(); Date earliestDate = parseDate(earliestDateAsNodeValue); if (fromParents.size() > 1) { for (int i = 1; i < fromParents.size(); i++) { final String nodeValue = fromParents.get(i).getFirstChild().getNodeValue(); final Date date = parseDate(nodeValue); if (date.before(earliestDate)) { earliestDateAsNodeValue = nodeValue; earliestDate = date; } } } addTextToNode(toParent, earliestDateAsNodeValue, toDocument); }  @Override void mergeNodes(List<Node> fromParents, Element toParent, Document toDocument);  }
@Test public void testMergeNodes() throws Exception { List<Node> fromParents = new ArrayList<>(); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sentinel-safe:startTime>2013-07-07T15:32:52.300000Z</sentinel-safe:startTime>").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sentinel-safe:startTime>2013-07-07T15:37:52.300000Z</sentinel-safe:startTime>\n").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sentinel-safe:startTime>2013-07-07T15:42:52.300000Z</sentinel-safe:startTime>\n").getFirstChild()); final Document manifest = ManifestTestUtils.createDocument(); final Element manifestElement = manifest.createElement("sentinel-safe:startTime"); new StartTimesMerger().mergeNodes(fromParents, manifestElement, manifest); assertEquals(0, manifestElement.getAttributes().getLength()); assertEquals(1, manifestElement.getChildNodes().getLength()); assertEquals("2013-07-07T15:32:52.300000Z", manifestElement.getFirstChild().getNodeValue()); }