@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);
    assertEquals(1, retrieved.size());
    Node created = (Node) retrieved.values().toArray()[0];
    assertNotNull(created);
    assertEquals(newNodeName, created.getNodeName());
    assertEquals(newNodeValue, created.getTextContent());
    retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, TEST_NODE, newNodeName, null);
    assertEquals(1, retrieved.size());
    created = (Node) retrieved.values().toArray()[0];
    assertNotNull(created);
    assertEquals(newNodeName, created.getNodeName());
    assertTrue(created.getTextContent().isEmpty());
    retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, CHILD_NODE, newNodeName, newNodeValue);
    assertEquals(2, retrieved.size());
    retrieved.forEach((key, createdNode) -> {
        assertNotNull(createdNode);
        assertEquals(newNodeName, createdNode.getNodeName());
        assertEquals(newNodeValue, createdNode.getTextContent());
    });
    retrieved = DOMParserUtil.createNestedNodes(document, MAIN_NODE, CHILD_NODE, newNodeName, null);
    assertEquals(2, retrieved.size());
    retrieved.forEach((key, createdNode) -> {
        assertNotNull(createdNode);
        assertEquals(newNodeName, createdNode.getNodeName());
        assertTrue(createdNode.getTextContent().isEmpty());
    });
}