StopTimesMerger extends AbstractElementMerger { @Override public void mergeNodes(List<Node> fromParents, Element toParent, Document toDocument) throws PDUStitchingException { String latetDateAsNodeValue = fromParents.get(0).getFirstChild().getNodeValue(); Date latestDate = parseDate(latetDateAsNodeValue); 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.after(latestDate)) { latetDateAsNodeValue = nodeValue; latestDate = date; } } } addTextToNode(toParent, latetDateAsNodeValue, 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:stopTime>2013-07-07T15:37:52.000014Z</sentinel-safe:stopTime>").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sentinel-safe:stopTime>2013-07-07T15:42:52.000014Z</sentinel-safe:stopTime>").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sentinel-safe:stopTime>2013-07-07T15:47:52.000014Z</sentinel-safe:stopTime>").getFirstChild()); final Document manifest = ManifestTestUtils.createDocument(); final Element manifestElement = manifest.createElement("sentinel-safe:stopTime"); new StopTimesMerger().mergeNodes(fromParents, manifestElement, manifest); assertEquals(0, manifestElement.getAttributes().getLength()); assertEquals(1, manifestElement.getChildNodes().getLength()); assertEquals("2013-07-07T15:47:52.000014Z", manifestElement.getFirstChild().getNodeValue()); }