final String stringAst = DetailNodeTreeStringPrinter.printFileAst(file); System.out.print(stringAst);
/** * Verifies the javadoc tree generated for the supplied javadoc file against the expected tree * in the supplied text file. * @param expectedTextPrintFilename name of the text file having the expected tree. * @param actualJavadocFilename name of the file containing the javadoc. * @throws Exception if exception occurs during verification. */ protected static void verifyJavadocTree(String expectedTextPrintFilename, String actualJavadocFilename) throws Exception { final String expectedContents = readFile(expectedTextPrintFilename); final String actualContents = DetailNodeTreeStringPrinter.printFileAst( new File(actualJavadocFilename)).replaceAll(CRLF_REGEX, LF_REGEX); assertEquals("Generated tree from the javadoc file should match the pre-defined tree", expectedContents, actualContents); }
@Test public void testParseFileWithError() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst( new File(getPath("InputDetailNodeTreeStringPrinterJavadocWithError.javadoc"))); Assert.fail("Javadoc parser didn't fail on missing end tag"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(0, MSG_JAVADOC_MISSED_HTML_CLOSE, 1, "qwe")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
@Test public void testUnescapedJavaCodeWithGenericsInJavadoc() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst(new File( getPath("InputDetailNodeTreeStringPrinter" + "UnescapedJavaCodeWithGenericsInJavadoc.javadoc"))); Assert.fail("Exception is expected"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(35, MSG_JAVADOC_MISSED_HTML_CLOSE, 7, "parsing")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
@Test public void testNoViableAltException() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst(new File(getPath( "InputDetailNodeTreeStringPrinterNoViableAltException.javadoc"))); Assert.fail("Exception is expected"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(0, MSG_JAVADOC_PARSE_RULE_ERROR, 9, "no viable alternative at input '<<'", "HTML_ELEMENT")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
@Test public void testWrongHtmlTagOrder() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst(new File(getPath( "InputDetailNodeTreeStringPrinterWrongHtmlTagOrder.javadoc" ))); Assert.fail("Exception is expected"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(0, MSG_JAVADOC_MISSED_HTML_CLOSE, 10, "tag2")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
@Test public void testOmittedStartTagForHtmlElement() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst(new File(getPath( "InputDetailNodeTreeStringPrinterOmittedStartTagForHtmlElement.javadoc" ))); Assert.fail("Exception is expected"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(0, MSG_JAVADOC_MISSED_HTML_CLOSE, 3, "a")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
@Test public void testHtmlTagCloseBeforeTagOpen() throws Exception { try { DetailNodeTreeStringPrinter.printFileAst(new File(getPath( "InputDetailNodeTreeStringPrinterHtmlTagCloseBeforeTagOpen.javadoc" ))); Assert.fail("Exception is expected"); } catch (IllegalArgumentException ex) { final String expected = (String) GET_PARSE_ERROR_MESSAGE.invoke(null, new ParseErrorMessage(0, MSG_JAVADOC_PARSE_RULE_ERROR, 4, "no viable alternative at input '</tag'", "HTML_ELEMENT")); assertEquals("Generated and expected parse error messages don't match", expected, ex.getMessage()); } }
final String stringAst = DetailNodeTreeStringPrinter.printFileAst(file); System.out.print(stringAst);