[DOXIA-602] More improvements to tests
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..fd44f87 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
@@ -19,6 +19,13 @@
* under the License.
*/
+import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Reader;
+import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Writer;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
import java.io.File;
import java.io.IOException;
import java.io.Reader;
@@ -26,15 +33,6 @@
import java.util.Date;
import java.util.List;
-import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Reader;
-import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Writer;
-
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.WriterFactory;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
/**
* Test DocumentModel.
*
@@ -337,17 +335,10 @@
}
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 @@
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 @@
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.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 @@
if ( isXmlSink() )
{
- assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
+ assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) ));
}
else
{
@@ -611,7 +611,7 @@
if ( isXmlSink() )
{
- assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
+ assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) ));
}
else
{
@@ -632,7 +632,7 @@
if ( isXmlSink() )
{
- assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
+ assertThat ( wrapXml( actual ), isIdenticalTo( wrapXml( expected ) ));
}
else
{
@@ -673,7 +673,7 @@
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 @@
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 @@
assertTrue( linebreak.contains( "Line\\" + EOL + "break." ) );
}
- /** @throws Exception */
public void testSnippetMacro()
throws Exception
{
@@ -100,7 +87,6 @@
assertTrue( macro.contains( "<modelVersion\\>4.0.0\\</modelVersion\\>" ) );
}
- /** @throws Exception */
public void testCommentsBeforeTitle()
throws Exception
{
@@ -110,7 +96,6 @@
+ EOL + " -----" + EOL + " Test DOXIA-379" ) );
}
- /** @throws Exception */
public void testSnippet()
throws Exception
{
@@ -129,8 +114,6 @@
"verbatim_", "paragraph", "text", "paragraph_", "listItem_", "list_", "body_" );
}
-
- /** @throws Exception */
public void testSnippetTrailingSpace()
throws Exception
{
@@ -146,7 +129,6 @@
assertEquals( it, "head", "head_", "body", "verbatim", "text", "verbatim_", "body_" );
}
- /** @throws Exception */
public void testTocMacro()
throws Exception
{
@@ -161,31 +143,20 @@
* 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 @@
assertEquals( it, "text", "verbatim_", "body_" );
}
- /** @throws Exception */
public void testMultiLinesInTableCells()
throws Exception
{
@@ -257,7 +227,6 @@
assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
}
- /** @throws Exception */
public void testLineBreakInTableCells()
throws Exception
{
@@ -317,7 +286,6 @@
assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
}
- /** @throws Exception */
public void testDOXIA38()
throws Exception
{
@@ -360,7 +328,6 @@
assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
}
- /** @throws Exception */
public void testSpecialCharactersInTables()
throws Exception
{
@@ -386,7 +353,6 @@
assertEquals( it, "tableCell_", "tableCell", "text", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
}
- /** @throws Exception */
public void testSpacesAndBracketsInAnchors()
throws Exception
{
@@ -418,7 +384,6 @@
assertEquals( it, "link_", "paragraph_", "body_" );
}
- /** @throws Exception */
public void testSectionTitleAnchors()
throws Exception
{
@@ -436,9 +401,6 @@
"section1", "sectionTitle1", "anchor", "text", "anchor_", "sectionTitle1_", "section1_", "body_" );
}
- /**
- * @throws Exception
- */
public void testTableHeaders() throws Exception
{
// DOXIA-404
@@ -504,7 +466,6 @@
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 @@
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 @@
assertContainsLines( result, "end:body" );
}
- /** @throws Exception */
public void testParagraphWithSimpleFormatting()
throws Exception
{
@@ -111,7 +107,6 @@
assertEquals( 5, result.split( "end:paragraph" ).length );
}
- /** @throws Exception */
public void testLineBreak()
throws Exception
{
@@ -124,7 +119,6 @@
assertContainsLines( result, "inline\n" + lineBreak );
}
- /** @throws Exception */
public void testEscapes()
throws Exception
{
@@ -138,7 +132,6 @@
assertContainsLines( result, "trailing slash\\\n" );
}
- /** @throws Exception */
public void testSectionTitles()
throws Exception
{
@@ -153,7 +146,6 @@
assertContainsLines( "Section title has leading space", result, "sectionTitle1\ntext: TitleWithLeadingSpace" );
}
- /** @throws Exception */
public void testNestedBulletList()
throws Exception
{
@@ -167,7 +159,6 @@
assertEquals( 5, result.split( "end:listItem\n" ).length );
}
- /** @throws Exception */
public void testNestedHeterogenousList()
throws Exception
{
@@ -184,7 +175,6 @@
assertEquals( 5, result.split( "end:listItem\n" ).length );
}
- /** @throws Exception */
public void testListWithSimpleFormatting()
throws Exception
{
@@ -205,7 +195,6 @@
assertEquals( 9, result.split( "end:listItem\n" ).length );
}
- /** @throws Exception */
public void testAnchor()
throws Exception
{
@@ -218,7 +207,6 @@
assertEquals( 4, result.split( "end:anchor\n" ).length );
}
- /** @throws Exception */
public void testUnknownMacro()
throws Exception
{
@@ -227,7 +215,6 @@
assertContainsLines( result, "begin:paragraph\ntext: {unknown:start}" );
}
- /** @throws Exception */
public void testCodeMacro()
throws Exception
{
@@ -240,7 +227,6 @@
assertEquals( 3, result.split( "end:verbatim\n" ).length );
}
- /** @throws Exception */
public void testFigure()
throws Exception
{
@@ -279,7 +265,6 @@
assertEquals( it, "figure_", "body_" );
}
- /** @throws Exception */
public void testLink()
throws Exception
{
@@ -314,7 +299,6 @@
}
- /** @throws Exception */
public void testTableWithLinks()
throws Exception
{
@@ -327,7 +311,6 @@
assertEquals( 4, result.split( "end:link\n" ).length );
}
- /** @throws Exception */
public void testTableWithImages()
throws Exception
{
@@ -351,7 +334,6 @@
assertEquals( it, "figure_", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
}
- /** @throws Exception */
public void testParagraphWithList()
throws Exception
{
@@ -366,7 +348,6 @@
assertEquals( 2, result.split( "end:list\n" ).length );
}
- /** @throws Exception */
public void testParagraphWithFigure()
throws Exception
{
@@ -380,7 +361,6 @@
assertEquals( 2, result.split( "end:figure\n" ).length );
}
- /** @throws Exception */
public void testParagraphWithHeader()
throws Exception
{
@@ -394,7 +374,6 @@
assertEquals( 2, result.split( "end:sectionTitle2\n" ).length );
}
- /** @throws Exception */
public void testNestedFormats()
throws Exception
{
@@ -426,7 +405,6 @@
assertEquals( 12, result.split( "end:monospaced\n" ).length );
}
- /** @throws Exception */
public void testNoteInfoTipQuote()
throws Exception
{
@@ -484,8 +462,6 @@
/**
* DOXIA-247
- *
- * @throws ParseException
*/
public void testEndBracketInList()
throws ParseException
@@ -564,8 +540,6 @@
/**
* DOXIA-370
- *
- * @throws ParseException
*/
public void testSeparatorInParagraph()
throws ParseException
@@ -578,7 +552,6 @@
/* 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 @@
}
}
- /** @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 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 static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo;
/**
* Test FoAggregateSink.
@@ -183,7 +184,7 @@
+ "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-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/ParagraphTest.java b/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/ParagraphTest.java
index 0281865..05c5402 100644
--- a/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/ParagraphTest.java
+++ b/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/ParagraphTest.java
@@ -94,6 +94,7 @@
*
* @throws ParseException on error
*/
+ @Test
public final void testParagraphWithStartingList()
throws ParseException
{
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 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 @@
return sink.getEventList().iterator();
}
- /** @throws Exception */
public void testHeadEventsList()
throws Exception
{
@@ -232,7 +200,6 @@
assertEquals( it, "title_", "head_", "body", "body_" );
}
- /** @throws Exception */
public void testDocumentBodyEventsList()
throws Exception
{
@@ -243,7 +210,6 @@
assertEquals( it, "body", "body_" );
}
- /** @throws Exception */
public void testSectionEventsList()
throws Exception
{
@@ -255,7 +221,6 @@
"sectionTitle2_", "section2_", "section1_" );
}
- /** @throws Exception */
public void testSectionAttributes()
throws Exception
{
@@ -281,7 +246,6 @@
assertEquals( it, "text", "sectionTitle1_", "section1_" );
}
- /** @throws Exception */
public void testNestedSectionsEventsList()
throws Exception
{
@@ -295,7 +259,6 @@
"section2_", "section2", "sectionTitle2", "text", "sectionTitle2_", "section2_", "section1_" );
}
- /** @throws Exception */
public void testSourceEventsList()
throws Exception
{
@@ -316,7 +279,6 @@
assertEquals( it, "verbatim", "text", "verbatim_" );
}
- /** @throws Exception */
public void testSourceContainingDTD()
throws Exception
{
@@ -331,7 +293,6 @@
assertEquals( it, "verbatim", "text", "verbatim_" );
}
- /** @throws Exception */
public void testPreEOL()
throws Exception
{
@@ -346,8 +307,6 @@
/**
* Test section with ids.
- *
- * @throws java.lang.Exception if any.
*/
public void testSectionIdAnchor()
throws Exception
@@ -369,8 +328,6 @@
/**
* Test script block.
- *
- * @throws java.lang.Exception if any.
*/
public void testJavaScript()
throws Exception
@@ -383,8 +340,6 @@
/**
* Test unknown tags.
- *
- * @throws java.lang.Exception if any.
*/
public void testUnknown()
throws Exception
@@ -424,7 +379,6 @@
}
}
- /** @throws Exception */
public void testEntities()
throws Exception
{