Element implements IAttributes { public void setParent(Element element) { if (parent != null) { throw new IllegalStateException("Parent element has already been defined."); } this.parent = element; } Element(String id);  Element(Element parent); String getId(); Element getParent(); void setParent(Element element); @SuppressWarnings("unchecked") @Override O getAttribute(String identifier); @Override boolean isDefined(String identifier); @Override Attributes getAttributes(); Attributes getLocalAttributes(); Set<String> getLocalAttributeNames(); @Override void setAttribute(String identifier, Object object); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override Parameter getAttributeParameter(String identifier); @Override Set<String> getAttributeNames(); String getType(); void setType(String type); static String TYPE; }
@Test public void testSetParent() { Element parent = new Element("id"); Element element = new Element("other id"); element.setParent(parent); Assert.assertTrue(parent == element.getParent()); Assert.assertFalse(element == element.getParent()); }
@Test(expected = IllegalStateException.class) public void testSetParentIfNotExisting() { Element parent = new Element("id"); Element element = new Element(parent); element.setParent(parent); }