This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch DOXIA-602 in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
commit 03a201f65f044123402b098fbbbb9e49a24a7203 Author: Sylwester Lachiewicz <slachiew...@apache.org> AuthorDate: Thu Feb 6 15:36:52 2020 +0100 [DOXIA-602] More improvements to tests --- .../maven/doxia/document/DocumentModelTest.java | 9 +--- .../maven/doxia/module/AbstractIdentityTest.java | 15 +++--- .../maven/doxia/sink/impl/AbstractSinkTest.java | 10 ++-- .../maven/doxia/module/apt/AptParserTest.java | 57 ++++----------------- .../module/confluence/ConfluenceParserTest.java | 27 ---------- .../doxia/module/docbook/DocBookParserTest.java | 1 - .../maven/doxia/module/fml/FmlParserTest.java | 20 ++------ .../maven/doxia/module/fo/FoAggregateSinkTest.java | 3 +- .../maven/doxia/module/xdoc/XdocParserTest.java | 58 +++------------------- 9 files changed, 34 insertions(+), 166 deletions(-) diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java index dd1f5cd..771ed5f 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java @@ -337,17 +337,10 @@ public class DocumentModelTest } File testFile = getTestFile( dir.getAbsolutePath(), "testModel.xml" ); - Writer w = null; - - try + try( Writer w = WriterFactory.newXmlWriter( testFile ) ) { - w = WriterFactory.newXmlWriter( testFile ); new DocumentXpp3Writer().write( w, model ); } - finally - { - IOUtil.close( w ); - } DocumentModel documentModel; diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java index e656eea..45292b5 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java @@ -94,10 +94,10 @@ public abstract class AbstractIdentityTest expected = writer.toString(); // write to file for comparison - Writer fileWriter = getTestWriter( "expected" ); - fileWriter.write( expected ); - IOUtil.close( fileWriter ); - + try ( Writer fileWriter = getTestWriter( "expected" ) ) + { + fileWriter.write( expected ); + } // generate the actual model writer = new StringWriter(); sink = createSink( writer ); @@ -113,9 +113,10 @@ public abstract class AbstractIdentityTest String actual = writer.toString(); // write to file for comparison - fileWriter = getTestWriter( "actual" ); - fileWriter.write( actual ); - IOUtil.close( fileWriter ); + try( Writer fileWriter = getTestWriter( "actual" ) ) + { + fileWriter.write( actual ); + } // Disabled by default, it's unlikely that all our modules // will pass this test any time soon, but the generated diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java index 208785a..0191895 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java @@ -29,9 +29,9 @@ import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventAttributes; import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.util.IOUtil; -import org.xmlunit.matchers.CompareMatcher; import static org.hamcrest.MatcherAssert.assertThat; +import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo; /** * Abstract base class to test sinks. @@ -588,7 +588,7 @@ public abstract class AbstractSinkTest if ( isXmlSink() ) { - assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) )); + assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) )); } else { @@ -611,7 +611,7 @@ public abstract class AbstractSinkTest if ( isXmlSink() ) { - assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) )); + assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) )); } else { @@ -632,7 +632,7 @@ public abstract class AbstractSinkTest if ( isXmlSink() ) { - assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) )); + assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) )); } else { @@ -673,7 +673,7 @@ public abstract class AbstractSinkTest if ( isXmlSink() ) { - assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) )); + assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) )); } else { diff --git a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java index e9018d7..163d28d 100644 --- a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java +++ b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java @@ -54,35 +54,23 @@ public class AptParserTest parser = lookup( Parser.ROLE, "apt" ); } - /** {@inheritDoc} */ protected Parser createParser() { return parser; } - protected String parseFileToAptSink( String file ) - throws ParseException + protected String parseFileToAptSink( String file ) throws ParseException, IOException { - StringWriter output = null; - Reader reader = null; - try + try( StringWriter output = new StringWriter(); + Reader reader = getTestReader( file ) ) { - output = new StringWriter(); - reader = getTestReader( file ); - Sink sink = new AptSink( output ); createParser().parse( reader, sink ); - } - finally - { - IOUtil.close( output ); - IOUtil.close( reader ); - } - return output.toString(); + return output.toString(); + } } - /** @throws Exception */ public void testLineBreak() throws Exception { @@ -91,7 +79,6 @@ public class AptParserTest assertTrue( linebreak.contains( "Line\\" + EOL + "break." ) ); } - /** @throws Exception */ public void testSnippetMacro() throws Exception { @@ -100,7 +87,6 @@ public class AptParserTest assertTrue( macro.contains( "<modelVersion\\>4.0.0\\</modelVersion\\>" ) ); } - /** @throws Exception */ public void testCommentsBeforeTitle() throws Exception { @@ -110,7 +96,6 @@ public class AptParserTest + EOL + " -----" + EOL + " Test DOXIA-379" ) ); } - /** @throws Exception */ public void testSnippet() throws Exception { @@ -129,8 +114,6 @@ public class AptParserTest "verbatim_", "paragraph", "text", "paragraph_", "listItem_", "list_", "body_" ); } - - /** @throws Exception */ public void testSnippetTrailingSpace() throws Exception { @@ -146,7 +129,6 @@ public class AptParserTest assertEquals( it, "head", "head_", "body", "verbatim", "text", "verbatim_", "body_" ); } - /** @throws Exception */ public void testTocMacro() throws Exception { @@ -161,31 +143,20 @@ public class AptParserTest * Parses the test document test.apt and re-emits * it into parser/test.apt. * - * @throws java.io.IOException if the test file cannot be read. - * @throws org.apache.maven.doxia.parser.ParseException if the test file cannot be parsed. + * @throws IOException if the test file cannot be read. + * @throws ParseException if the test file cannot be parsed. */ public void testTestDocument() throws IOException, ParseException { - Writer writer = null; - Reader reader = null; - try + try( Writer writer = getTestWriter( "test" ); + Reader reader = getTestReader( "test" ) ) { - writer = getTestWriter( "test" ); - reader = getTestReader( "test" ); - Sink sink = new AptSink( writer ); - createParser().parse( reader, sink ); } - finally - { - IOUtil.close( writer ); - IOUtil.close( reader ); - } } - /** @throws Exception */ public void testBoxedVerbatim() throws Exception { @@ -206,7 +177,6 @@ public class AptParserTest assertEquals( it, "text", "verbatim_", "body_" ); } - /** @throws Exception */ public void testMultiLinesInTableCells() throws Exception { @@ -257,7 +227,6 @@ public class AptParserTest assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" ); } - /** @throws Exception */ public void testLineBreakInTableCells() throws Exception { @@ -317,7 +286,6 @@ public class AptParserTest assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" ); } - /** @throws Exception */ public void testDOXIA38() throws Exception { @@ -360,7 +328,6 @@ public class AptParserTest assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" ); } - /** @throws Exception */ public void testSpecialCharactersInTables() throws Exception { @@ -386,7 +353,6 @@ public class AptParserTest assertEquals( it, "tableCell_", "tableCell", "text", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" ); } - /** @throws Exception */ public void testSpacesAndBracketsInAnchors() throws Exception { @@ -418,7 +384,6 @@ public class AptParserTest assertEquals( it, "link_", "paragraph_", "body_" ); } - /** @throws Exception */ public void testSectionTitleAnchors() throws Exception { @@ -436,9 +401,6 @@ public class AptParserTest "section1", "sectionTitle1", "anchor", "text", "anchor_", "sectionTitle1_", "section1_", "body_" ); } - /** - * @throws Exception - */ public void testTableHeaders() throws Exception { // DOXIA-404 @@ -504,7 +466,6 @@ public class AptParserTest assertEquals( it, "link_", "sectionTitle1_", "section1_", "body_" ); } - /** {@inheritDoc} */ protected String outputExtension() { return "apt"; diff --git a/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java b/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java index 5028dd4..a8f5805 100644 --- a/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java +++ b/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java @@ -76,19 +76,16 @@ public class ConfluenceParserTest super.tearDown(); } - /** {@inheritDoc} */ protected Parser createParser() { return parser; } - /** {@inheritDoc} */ protected String outputExtension() { return "confluence"; } - /** @throws Exception */ public void testMarkupTestPage() throws Exception { @@ -96,7 +93,6 @@ public class ConfluenceParserTest assertContainsLines( result, "end:body" ); } - /** @throws Exception */ public void testParagraphWithSimpleFormatting() throws Exception { @@ -111,7 +107,6 @@ public class ConfluenceParserTest assertEquals( 5, result.split( "end:paragraph" ).length ); } - /** @throws Exception */ public void testLineBreak() throws Exception { @@ -124,7 +119,6 @@ public class ConfluenceParserTest assertContainsLines( result, "inline\n" + lineBreak ); } - /** @throws Exception */ public void testEscapes() throws Exception { @@ -138,7 +132,6 @@ public class ConfluenceParserTest assertContainsLines( result, "trailing slash\\\n" ); } - /** @throws Exception */ public void testSectionTitles() throws Exception { @@ -153,7 +146,6 @@ public class ConfluenceParserTest assertContainsLines( "Section title has leading space", result, "sectionTitle1\ntext: TitleWithLeadingSpace" ); } - /** @throws Exception */ public void testNestedBulletList() throws Exception { @@ -167,7 +159,6 @@ public class ConfluenceParserTest assertEquals( 5, result.split( "end:listItem\n" ).length ); } - /** @throws Exception */ public void testNestedHeterogenousList() throws Exception { @@ -184,7 +175,6 @@ public class ConfluenceParserTest assertEquals( 5, result.split( "end:listItem\n" ).length ); } - /** @throws Exception */ public void testListWithSimpleFormatting() throws Exception { @@ -205,7 +195,6 @@ public class ConfluenceParserTest assertEquals( 9, result.split( "end:listItem\n" ).length ); } - /** @throws Exception */ public void testAnchor() throws Exception { @@ -218,7 +207,6 @@ public class ConfluenceParserTest assertEquals( 4, result.split( "end:anchor\n" ).length ); } - /** @throws Exception */ public void testUnknownMacro() throws Exception { @@ -227,7 +215,6 @@ public class ConfluenceParserTest assertContainsLines( result, "begin:paragraph\ntext: {unknown:start}" ); } - /** @throws Exception */ public void testCodeMacro() throws Exception { @@ -240,7 +227,6 @@ public class ConfluenceParserTest assertEquals( 3, result.split( "end:verbatim\n" ).length ); } - /** @throws Exception */ public void testFigure() throws Exception { @@ -279,7 +265,6 @@ public class ConfluenceParserTest assertEquals( it, "figure_", "body_" ); } - /** @throws Exception */ public void testLink() throws Exception { @@ -314,7 +299,6 @@ public class ConfluenceParserTest } - /** @throws Exception */ public void testTableWithLinks() throws Exception { @@ -327,7 +311,6 @@ public class ConfluenceParserTest assertEquals( 4, result.split( "end:link\n" ).length ); } - /** @throws Exception */ public void testTableWithImages() throws Exception { @@ -351,7 +334,6 @@ public class ConfluenceParserTest assertEquals( it, "figure_", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" ); } - /** @throws Exception */ public void testParagraphWithList() throws Exception { @@ -366,7 +348,6 @@ public class ConfluenceParserTest assertEquals( 2, result.split( "end:list\n" ).length ); } - /** @throws Exception */ public void testParagraphWithFigure() throws Exception { @@ -380,7 +361,6 @@ public class ConfluenceParserTest assertEquals( 2, result.split( "end:figure\n" ).length ); } - /** @throws Exception */ public void testParagraphWithHeader() throws Exception { @@ -394,7 +374,6 @@ public class ConfluenceParserTest assertEquals( 2, result.split( "end:sectionTitle2\n" ).length ); } - /** @throws Exception */ public void testNestedFormats() throws Exception { @@ -426,7 +405,6 @@ public class ConfluenceParserTest assertEquals( 12, result.split( "end:monospaced\n" ).length ); } - /** @throws Exception */ public void testNoteInfoTipQuote() throws Exception { @@ -484,8 +462,6 @@ public class ConfluenceParserTest /** * DOXIA-247 - * - * @throws ParseException */ public void testEndBracketInList() throws ParseException @@ -564,8 +540,6 @@ public class ConfluenceParserTest /** * DOXIA-370 - * - * @throws ParseException */ public void testSeparatorInParagraph() throws ParseException @@ -578,7 +552,6 @@ public class ConfluenceParserTest /* parsing with separator in middle of paragraph */ createParser().parse( new StringReader( document ), sink ); assertTrue( "generated document should have a size > 0", output.toString().length() > 0 ); - } public void testListFollowedByMacro() throws Exception diff --git a/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookParserTest.java b/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookParserTest.java index 06dd69a..8aaff87 100644 --- a/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookParserTest.java +++ b/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookParserTest.java @@ -98,7 +98,6 @@ public class DocBookParserTest extends AbstractParserTest } } - /** @throws Exception */ public void testSignificantWhiteSpace() throws Exception { diff --git a/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java b/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java index e22af15..1eeb164 100644 --- a/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java +++ b/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java @@ -259,36 +259,22 @@ public class FmlParserTest public void testFaqMacro() throws Exception { - Writer output = null; - Reader reader = null; - try + try ( Writer output = getTestWriter( "macro" ); + Reader reader = getTestReader( "macro" ) ) { - output = getTestWriter( "macro" ); - reader = getTestReader( "macro" ); - Sink sink = new XhtmlBaseSink( output ); createParser().parse( reader, sink ); sink.close(); } - finally - { - IOUtil.close( output ); - IOUtil.close( reader ); - } File f = getTestFile( getBasedir(), outputBaseDir() + getOutputDir() + "macro.fml" ); assertTrue( "The file " + f.getAbsolutePath() + " was not created", f.exists() ); String content; - try + try ( Reader reader = new FileReader( f ) ) { - reader = new FileReader( f ); content = IOUtil.toString( reader ); } - finally - { - IOUtil.close( reader ); - } assertTrue( content.contains( "<a name=\"macro-definition\">Macro Question</a>" ) ); } diff --git a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java index e309a70..d87e0fc 100644 --- a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java +++ b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java @@ -36,6 +36,7 @@ import java.io.Writer; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; +import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo; /** * Test FoAggregateSink. @@ -183,7 +184,7 @@ public class FoAggregateSinkTest + "width=\"100%\"/>" + Markup.EOL; String actual = writer.toString(); - assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) )); + assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) )); } /** diff --git a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java index c24ad4d..80196ee 100644 --- a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java +++ b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java @@ -101,76 +101,45 @@ public class XdocParserTest public void testSnippetMacro() throws Exception { - Writer output = null; - Reader reader = null; - - try + try( Writer output = getTestWriter( "macro" ); + Reader reader = getTestReader( "macro" ) ) { - output = getTestWriter( "macro" ); - reader = getTestReader( "macro" ); - Sink sink = new XdocSink( output ); createParser().parse( reader, sink ); sink.close(); } - finally - { - IOUtil.close( output ); - IOUtil.close( reader ); - } File f = getTestFile( getBasedir(), outputBaseDir() + getOutputDir() + "macro.xml" ); assertTrue( "The file " + f.getAbsolutePath() + " was not created", f.exists() ); String content; - try + try( Reader reader = new FileReader( f ) ) { - reader = new FileReader( f ); content = IOUtil.toString( reader ); } - finally - { - IOUtil.close( reader ); - } assertTrue( content.contains( "<modelVersion>4.0.0</modelVersion>" ) ); } - /** @throws Exception */ public void testTocMacro() throws Exception { - Writer output = null; - Reader reader = null; - - try + try( Writer output = getTestWriter( "toc" ); + Reader reader = getTestReader( "toc" ) ) { - output = getTestWriter( "toc" ); - reader = getTestReader( "toc" ); - Sink sink = new XdocSink( output ); createParser().parse( reader, sink ); sink.close(); } - finally - { - IOUtil.close( output ); - IOUtil.close( reader ); - } File f = getTestFile( getBasedir(), outputBaseDir() + getOutputDir() + "toc.xml" ); assertTrue( "The file " + f.getAbsolutePath() + " was not created", f.exists() ); String content; - try + try ( Reader reader = new FileReader( f ) ) { - reader = new FileReader( f ); content = IOUtil.toString( reader ); } - finally - { - IOUtil.close( reader ); - } // No section, only subsection 1 and 2 assertTrue( content.contains( "<a href=\"#Section_11\">Section 11</a>" ) ); @@ -187,7 +156,6 @@ public class XdocParserTest return sink.getEventList().iterator(); } - /** @throws Exception */ public void testHeadEventsList() throws Exception { @@ -232,7 +200,6 @@ public class XdocParserTest assertEquals( it, "title_", "head_", "body", "body_" ); } - /** @throws Exception */ public void testDocumentBodyEventsList() throws Exception { @@ -243,7 +210,6 @@ public class XdocParserTest assertEquals( it, "body", "body_" ); } - /** @throws Exception */ public void testSectionEventsList() throws Exception { @@ -255,7 +221,6 @@ public class XdocParserTest "sectionTitle2_", "section2_", "section1_" ); } - /** @throws Exception */ public void testSectionAttributes() throws Exception { @@ -281,7 +246,6 @@ public class XdocParserTest assertEquals( it, "text", "sectionTitle1_", "section1_" ); } - /** @throws Exception */ public void testNestedSectionsEventsList() throws Exception { @@ -295,7 +259,6 @@ public class XdocParserTest "section2_", "section2", "sectionTitle2", "text", "sectionTitle2_", "section2_", "section1_" ); } - /** @throws Exception */ public void testSourceEventsList() throws Exception { @@ -316,7 +279,6 @@ public class XdocParserTest assertEquals( it, "verbatim", "text", "verbatim_" ); } - /** @throws Exception */ public void testSourceContainingDTD() throws Exception { @@ -331,7 +293,6 @@ public class XdocParserTest assertEquals( it, "verbatim", "text", "verbatim_" ); } - /** @throws Exception */ public void testPreEOL() throws Exception { @@ -346,8 +307,6 @@ public class XdocParserTest /** * Test section with ids. - * - * @throws java.lang.Exception if any. */ public void testSectionIdAnchor() throws Exception @@ -369,8 +328,6 @@ public class XdocParserTest /** * Test script block. - * - * @throws java.lang.Exception if any. */ public void testJavaScript() throws Exception @@ -383,8 +340,6 @@ public class XdocParserTest /** * Test unknown tags. - * - * @throws java.lang.Exception if any. */ public void testUnknown() throws Exception @@ -424,7 +379,6 @@ public class XdocParserTest } } - /** @throws Exception */ public void testEntities() throws Exception {