public static Map<Node, Node> createNestedNodes(Document document, String mainContainerNodeName, String containerNodeName, String childNodeName, String nodeContent) {
        Map<Node, Node> toReturn = new HashMap<>();
        asStream(document.getElementsByTagName(mainContainerNodeName))
                .map(Node::getChildNodes)
                .forEach(containerNodeList ->
                                 asStream(containerNodeList)
                                         .filter(containerNode -> Objects.equals(containerNodeName, containerNode.getNodeName()))
                                         .forEach(containerNode -> {
                                             Node childNode = document.createElement(childNodeName);
                                             containerNode.appendChild(childNode);
                                             if (nodeContent != null) {
                                                 childNode.setTextContent(nodeContent);
                                             }
                                             toReturn.put(containerNode, childNode);
                                         }));
        return toReturn;
    }
@Test
    public void createNestedNodes() throws Exception {
        final String newNodeName = "NEW_NODE_NAME";
        final String newNodeValue = "NEW_NODE_VALUE";
        Document document = DOMParserUtil.getDocument(XML);
        Map<Node, Node> retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, TEST_NODE, newNodeName, newNodeValue);
        assertThat(retrieved).hasSize(1);
        Node created = (Node) retrieved.values().toArray()[0];
        assertThat(created).isNotNull();
        assertThat(created.getNodeName()).isEqualTo(newNodeName);
        assertThat(created.getTextContent()).isEqualTo(newNodeValue);
        retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, TEST_NODE, newNodeName, null);
        assertThat(retrieved).hasSize(1);
        created = (Node) retrieved.values().toArray()[0];
        assertThat(created).isNotNull();
        assertThat(created.getNodeName()).isEqualTo(newNodeName);
        assertThat(created.getTextContent()).isEmpty();

        retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, CHILD_NODE, newNodeName, newNodeValue);
        assertThat(retrieved).hasSize(2);
        retrieved.forEach((key, createdNode) -> {
            assertThat(createdNode).isNotNull();
            assertThat(createdNode.getNodeName()).isEqualTo(newNodeName);
            assertThat(createdNode.getTextContent()).isEqualTo(newNodeValue);
        });
        retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, CHILD_NODE, newNodeName, null);
        assertThat(retrieved).hasSize(2);
        retrieved.forEach((key, createdNode) -> {
            assertThat(createdNode).isNotNull();
            assertThat(createdNode.getNodeName()).isEqualTo(newNodeName);
            assertThat(createdNode.getTextContent()).isEmpty();
        });
    }