### Question:
DecisionTreeOptimiser { public DecisionTree optimiseTree(DecisionTree tree){ ConstraintNode newRootNode = optimiseLevelOfTree(tree.getRootNode()); return new DecisionTree(newRootNode, tree.getFields()); }  DecisionTree optimiseTree(DecisionTree tree);  }### Answer:
@Test public void optimise_circularDependency() { ConstraintNode original = constraintNode() .withDecision( constraintNode() .where(A).isNull() .where(B).isNull(), constraintNode() .where(A).isNotNull()) .withDecision( constraintNode() .where(B).isNull() .where(A).isNull(), constraintNode() .where(B).isNotNull()) .build(); ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new ProfileFields(Collections.EMPTY_LIST))) .getRootNode(); assertThat(actual, sameBeanAs(original)); }
@Test public void optimise_oneCommonIf(){ ConstraintNode original = constraintNode() .where(A).isInSet("a1", "a2") .where(B).isInSet("b1", "b2") .where(C).isInSet("c1", "c2") .where(D).isInSet("d1", "d2") .where(E).isInSet("e1", "e2") .withDecision( constraintNode() .where(A).isInSet("a1") .withDecision( constraintNode() .where(B).isInSet("b1") .where(D).isInSet("d1"), constraintNode() .where(B).isNotInSet("b1")) .withDecision( constraintNode() .where(C).isInSet("c1") .where(E).isInSet("e1"), constraintNode() .where(C).isNotInSet("c1")), constraintNode() .where(A).isNotInSet("a1")) .build(); ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new ProfileFields(Collections.EMPTY_LIST))) .getRootNode(); assertThat(actual, sameBeanAs(original)); }