private static void test( final XmlContentModel XmlContentModel, final String initialContent, final String elementNameToInsert, final String expectedContent) throws Exception { Element root = parse(initialContent); NodeList nodeList = root.getChildNodes(); final int position = XmlContentModel.findInsertionPosition(nodeList, new QName(elementNameToInsert)); final Element elementToInsert = root.getOwnerDocument().createElementNS(null, elementNameToInsert); if (position == -1) { root.appendChild(elementToInsert); } else { final Node nodeAtPosition = nodeList.item(position); root.insertBefore(elementToInsert, nodeAtPosition); } final Element expectedContentRoot = parse(expectedContent); if (!equal(nodeList, expectedContentRoot.getChildNodes())) { final StringBuilder buf = new StringBuilder(); buf.append("=== actual ===\n"); buf.append(toString(root.getOwnerDocument())); buf.append("\n=== expected ===\n"); buf.append(expectedContent); assertTrue(buf.toString(), false); } }