@Test
	public void testShouldNotVisitTerminal() {
		String input = "A";
		VisitorBasicLexer lexer = new VisitorBasicLexer(new ANTLRInputStream(input));
		VisitorBasicParser parser = new VisitorBasicParser(new CommonTokenStream(lexer));

		VisitorBasicParser.SContext context = parser.s();
		assertEquals("(s A <EOF>)", context.toStringTree(parser));

		VisitorBasicVisitor<String> listener = new VisitorBasicBaseVisitor<String>() {
			@Override
			public String visitTerminal(TerminalNode node) {
				throw new RuntimeException("Should not be reachable");
			}

			@Override
			protected String defaultResult() {
				return "default result";
			}

			@Override
			protected boolean shouldVisitNextChild(RuleNode node, String currentResult) {
				return false;
			}
		};

		String result = listener.visit(context);
		String expected = "default result";
		assertEquals(expected, result);
	}
This test verifies that {@link AbstractParseTreeVisitor#shouldVisitNextChild} is called before visiting the first
child. It also verifies that {@link AbstractParseTreeVisitor#defaultResult} provides the default return value for
visiting a tree.
runtime-testsuite/test/org/antlr/v4/test/runtime/java/api/TestVisitors.java