### Question:
BranchNormalizedVisitor implements FilterVisitor { @Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; }  @Override Object visit( ExprNode node ); @Override boolean canVisit( ExprNode node ); @Override boolean isPrefix(); @Override List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); static String getNormalizedFilter( SchemaManager schemaManager, String filter ); static String getNormalizedFilter( ExprNode filter );  }### Answer:
@Test public void testBranchNormalizedVisitor0() throws Exception { String filter = "(ou=Human Resources)"; ExprNode ori = FilterParser.parse( filter ); ExprNode altered = FilterParser.parse( filter ); BranchNormalizedVisitor visitor = new BranchNormalizedVisitor(); visitor.visit( altered ); assertEquals( ori.toString(), altered.toString() ); }
@Test public void testBranchNormalizedVisitor1() throws Exception { String filter = "(&(ou=Human Resources)(uid=akarasulu))"; ExprNode ori = FilterParser.parse( filter ); ExprNode altered = FilterParser.parse( filter ); BranchNormalizedVisitor visitor = new BranchNormalizedVisitor(); visitor.visit( altered ); assertEquals( ori.toString(), altered.toString() ); }
@Test public void testBranchNormalizedVisitor2() throws Exception { String filter = "(&(uid=akarasulu)(ou=Human Resources)"; filter += "(|(uid=akarasulu)(ou=Human Resources))) "; ExprNode ori = FilterParser.parse( filter ); ExprNode altered = FilterParser.parse( filter ); BranchNormalizedVisitor visitor = new BranchNormalizedVisitor(); visitor.visit( altered ); assertFalse( ori.toString().equals( altered.toString() ) ); }
@Test public void testBranchNormalizedVisitor3() throws Exception { String filter = "(&(ou=Human Resources)(uid=akarasulu)"; filter += "(|(ou=Human Resources)(uid=akarasulu)))"; ExprNode ori = FilterParser.parse( filter ); ExprNode altered = FilterParser.parse( filter ); BranchNormalizedVisitor visitor = new BranchNormalizedVisitor(); visitor.visit( altered ); assertTrue( ori.toString().equals( altered.toString() ) ); }