DurationMerger extends AbstractElementMerger { @Override public void mergeNodes(List<Node> fromParents, Element toParent, Document toDocument) throws PDUStitchingException { int duration = 0; for (Node node : fromParents) { try { duration += Integer.parseInt(node.getTextContent()); } catch (NumberFormatException nfe) { throw new PDUStitchingException("Could not parse duration: " + nfe.getMessage()); } } addTextToNode(toParent, String.valueOf(duration), 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" + " <sentinel3:duration>179</sentinel3:duration>").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <sentinel3:duration>179</sentinel3:duration>").getFirstChild()); fromParents.add(ManifestTestUtils.createNode( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <sentinel3:duration>179</sentinel3:duration>").getFirstChild()); Document manifest = ManifestTestUtils.createDocument(); final Element manifestElement = manifest.createElement("sentinel3:duration"); manifest.appendChild(manifestElement); new DurationMerger().mergeNodes(fromParents, manifestElement, manifest); assertEquals(0, manifestElement.getAttributes().getLength()); assertEquals(1, manifestElement.getChildNodes().getLength()); assertEquals("537", manifestElement.getFirstChild().getNodeValue()); assertEquals("537", manifestElement.getTextContent()); }