@Test public void removeChild() { // Arrange BaseElement c0 = Document.get().createBaseElement(); ButtonElement c1 = Document.get().createPushButtonElement(); n.appendChild(c0); n.appendChild(c1); // Act n.removeChild(c1); // Assert assertEquals(1, n.getChildNodes().getLength()); assertEquals(c0, n.getChildNodes().getItem(0)); }
static Node insertAtIndex(Node parent, Node newChild, int index) { List<Node> list = getChildNodeList(parent); // First, remove from old parent Node oldParent = newChild.getParentNode(); if (oldParent != null) { oldParent.removeChild(newChild); } // Then, check parent doesn't contain newChild and remove it if necessary list.remove(newChild); // Finally, add if (index == -1 || index >= list.size()) { list.add(newChild); } else { list.add(index, newChild); } // Manage getParentNode() JavaScriptObjects.setProperty(newChild, JsoProperties.PARENT_NODE_FIELD, parent); return newChild; }