### Question:
BooleanOptimizationRebuildingVisitor extends RebuildingVisitor { public static ASTJexlScript optimize(JexlNode node) { if (node == null) { return null; } BooleanOptimizationRebuildingVisitor visitor = new BooleanOptimizationRebuildingVisitor(); return (ASTJexlScript) node.jjtAccept(visitor, null); }  static ASTJexlScript optimize(JexlNode node); @Override Object visit(ASTAndNode node, Object data);  }### Answer:
@Test public void testConjunction() throws ParseException { String original = "a && b && c"; optimize(original, original, false, false); }
@Test public void testConjunctionWithFlatten() throws ParseException { String original = "a && b && c"; optimize(original, original, false, true); }
@Test public void testDisjunction() throws ParseException { String original = "a || b || c"; optimize(original, original, true, false); }
@Test public void testDisjunctionWithFlatten() throws ParseException { String original = "a || b || c"; optimize(original, original, true, true); }
@Test public void testChildDisjunction() throws ParseException { String original = "a && b || c"; String expected = "(a && b) || c"; optimize(original, expected, true, false); }
@Test public void testDistributeOrTerms() throws ParseException { String original = "a && b && c && d && (e || f)"; String expected = "(a && b && c && d && e) || (a && b && c && d && f)"; optimize(original, expected, true, false); }
@Test public void testDistributeOrTermsWithFlatten() throws ParseException { String original = "(a || b) && (c || d) && (e || f)"; String expected = "((c || d) && (e || f) && a) || ((c || d) && (e || f) && b)"; optimize(original, expected, true, true); }
@Test public void testDistributeLargestOrTerms() throws ParseException { String original = "(a || b) && (c || d) && (e || f || g)"; String expected = "((c || d) && (e || f || g) && a) || ((c || d) && (e || f || g) && b)"; optimize(original, expected, true, false); }
@Test public void testDistributeLargestOrTermsWithFlatten() throws ParseException { String original = "(a || b) && (c || d) && (e || f || g)"; String expected = "((c || d) && (a || b) && e) || ((c || d) && (a || b) && f) || ((c || d) && (a || b) && g)"; optimize(original, expected, true, true); }