void () { final Integer[] visits = new Integer[]{0, 0, 0}; DomElementVisitor visitor = new MyVisitor() { @Override public void visit(InheritedElement element) { visits[0]++; } @Override public void visitDomElement(DomElement element) { visits[1]++; } @Override public void visitMyElement(MyElement element) { visits[2]++; } }; createElement("", MyElement.class).accept(visitor); final List<Integer> visitsList = Arrays.asList(visits); assertEquals(Arrays.asList(0, 0, 1), visitsList); createElement("", InheritedElement.class).accept(visitor); assertEquals(Arrays.asList(1, 0, 1), visitsList); createElement("", AnotherElement.class).accept(visitor); assertEquals(Arrays.asList(1, 1, 1), visitsList); createElement("", DomElement.class).accept(visitor); assertEquals(Arrays.asList(1, 2, 1), visitsList); createElement("", InheritedElement.class).accept(new DomElementVisitor() { @Override public void visitDomElement(DomElement element) { visits[1]++; } }); assertEquals(Arrays.asList(1, 3, 1), visitsList); }