TransformingVisitor extends AstVisitor { @Override public String toString() { return getResult().toString(); }  T applyTo(AstNode node); abstract T getResult(); @Override String toString();  }
@Test public void testToString() { TransformingVisitor<String> subject = new TransformingVisitor<String>() { @Override public String getResult() { return "expected"; } }; assertEquals("expected", subject.toString()); }