### Question:
VariableMetadata implements Serializable { public void setParent(VariableMetadata parent, String relationshipToParent) { if (relationshipToParent != null && parent != null) { if (parent.childrenWithRoles.containsKey(relationshipToParent)) { throw new IllegalArgumentException( "The parent already has a child with the relationship: " + relationshipToParent); } } VariableMetadata currentMetadata = parent; while (currentMetadata != null) { if (currentMetadata.equals(this)) { throw new IllegalArgumentException( "Setting this as a parent metadata creates a circular tree"); } currentMetadata = currentMetadata.getParent(); } if (this.parent != null && !this.parent.equals(parent)) { this.parent.children.remove(this); Iterator<Entry<String, VariableMetadata>> iterator = this.parent.childrenWithRoles .entrySet().iterator(); while (iterator.hasNext()) { Entry<String, VariableMetadata> children = iterator.next(); if (children.getValue().equals(this)) { iterator.remove(); } } } this.parent = parent; if (this.parent != null) { this.parent.children.add(this); if (relationshipToParent != null) { this.parent.childrenWithRoles.put(relationshipToParent.trim(), this); } dataset = parent.getDataset(); } } VariableMetadata(Parameter parameter, HorizontalDomain hDomain, VerticalDomain zDomain,
            TemporalDomain tDomain);  VariableMetadata(Parameter parameter, HorizontalDomain hDomain, VerticalDomain zDomain,
            TemporalDomain tDomain, boolean scalar); void setDataset(Dataset dataset); String getId(); Dataset getDataset(); Parameter getParameter(); HorizontalDomain getHorizontalDomain(); VerticalDomain getVerticalDomain(); TemporalDomain getTemporalDomain(); VariableMetadata getParent(); Set<VariableMetadata> getChildren(); void setParent(VariableMetadata parent, String relationshipToParent); VariableMetadata getChildWithRole(String role); boolean isScalar(); Map<String, Object> getVariableProperties();  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testNonCircularTrees() { setUp(); metadata4.setParent(metadata3, null); metadata3.setParent(metadata2, null); metadata2.setParent(metadata1, null); metadata1.setParent(metadata4, null); }