// can't remove when insertion is legal;
// succeeed or fail as unit
public void testReplaceChildAtomicity() {
Element parent = new Element("parent");
Text child = new Text("child");
parent.appendChild(child);
try {
parent.replaceChild(child, new DocType("root"));
fail("allowed doctype child of element");
}
catch (IllegalAddException success) {
assertEquals(parent, child.getParent());
assertEquals(1, parent.getChildCount());
}
Element e = new Element("e");
Text child2 = new Text("child2");
e.appendChild(child2);
try {
parent.replaceChild(child, child2);
fail("allowed replacement with existing parent");
}
catch (MultipleParentException success) {
assertEquals(e, child2.getParent());
assertEquals(parent, child.getParent());
assertEquals(1, parent.getChildCount());
assertEquals(1, e.getChildCount());
}