From 946f1b158ceca2077da0d7a6153c1a97281d7b10 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 1 Feb 2021 02:26:43 +0100 Subject: [PATCH] Tests improvements / AssertJ / Java 16+ --- pom.xml | 11 + .../javadoc/AbstractFixJavadocMojoTest.java | 48 +- .../javadoc/AbstractJavadocMojoTest.java | 36 +- .../maven/plugins/javadoc/JavadocJarTest.java | 35 +- .../plugins/javadoc/JavadocReportTest.java | 572 +++++++++--------- .../plugins/javadoc/JavadocUtilTest.java | 102 +--- .../plugins/javadoc/JavadocVersionTest.java | 41 +- .../javadoc/TestJavadocReportTest.java | 6 +- .../io/xpp3/JavadocOptionsXpp3ReaderTest.java | 16 +- .../def/configuration/App.java | 3 + .../def/configuration/AppSample.java | 2 +- 11 files changed, 427 insertions(+), 445 deletions(-) diff --git a/pom.xml b/pom.xml index 5cb55f9a..2d7edee6 100644 --- a/pom.xml +++ b/pom.xml @@ -293,6 +293,11 @@ under the License. plexus-utils 3.3.0 + + commons-io + commons-io + 2.6 + org.codehaus.plexus plexus-interactivity-api @@ -352,6 +357,12 @@ under the License. shaded test + + org.assertj + assertj-core + 2.9.1 + test + diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojoTest.java index 049d57a0..54c5dc6e 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojoTest.java @@ -25,18 +25,19 @@ import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; public class AbstractFixJavadocMojoTest - extends TestCase { private JavaSource getJavaSource( String source ) { return new JavaProjectBuilder().addSource( new StringReader( source ) ); } + @Test public void testReplaceLinkTags_noLinkTag() - throws Throwable { String comment = "/** @see ConnectException */"; String source = "import java.net.ConnectException;\n" @@ -46,12 +47,12 @@ public void testReplaceLinkTags_noLinkTag() JavaClass clazz = getJavaSource( source ).getClassByName( "NoLinkTag" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - - assertEquals( "/** @see ConnectException */", newComment ); + + assertThat( newComment ).isEqualTo( "/** @see ConnectException */" ); } + @Test public void testReplaceLinkTags_oneLinkTag() - throws Throwable { String comment = "/** {@link ConnectException} */"; String source = "import java.net.ConnectException;\n" @@ -61,11 +62,11 @@ public void testReplaceLinkTags_oneLinkTag() JavaClass clazz = getJavaSource( source ).getClassByName( "OneLinkTag" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException} */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException} */" ); } + @Test public void testReplaceLinkTags_missingEndBrace() - throws Throwable { String comment = "/** {@link ConnectException */"; String source = "import java.net.ConnectException;\n" @@ -75,11 +76,11 @@ public void testReplaceLinkTags_missingEndBrace() JavaClass clazz = getJavaSource( source ).getClassByName( "MissingEndBrace" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link ConnectException */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link ConnectException */" ); } + @Test public void testReplaceLinkTags_spacesAfterLinkTag() - throws Throwable { String comment = "/** {@link ConnectException} */"; String source = "import java.net.ConnectException;\n" @@ -89,11 +90,11 @@ public void testReplaceLinkTags_spacesAfterLinkTag() JavaClass clazz = getJavaSource( source ).getClassByName( "SpacesAfterLinkTag" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException} */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException} */" ); } + @Test public void testReplaceLinkTags_spacesAfterClassName() - throws Throwable { String comment = "/** {@link ConnectException } */"; String source = "import java.net.ConnectException;\n" @@ -103,11 +104,11 @@ public void testReplaceLinkTags_spacesAfterClassName() JavaClass clazz = getJavaSource( source ).getClassByName( "SpacesAfterClassName" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException} */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException} */" ); } + @Test public void testReplaceLinkTags_spacesAfterMethod() - throws Throwable { String comment = "/** {@link ConnectException#getMessage() } */"; String source = "import java.net.ConnectException;\n" @@ -117,11 +118,11 @@ public void testReplaceLinkTags_spacesAfterMethod() JavaClass clazz = getJavaSource( source ).getClassByName( "SpacesAfterMethod" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException#getMessage()} */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException#getMessage()} */" ); } + @Test public void testReplaceLinkTags_containingHash() - throws Throwable { String comment = "/** {@link ConnectException#getMessage()} */"; String source = "import java.net.ConnectException;\n" @@ -131,11 +132,11 @@ public void testReplaceLinkTags_containingHash() JavaClass clazz = getJavaSource( source ).getClassByName( "ContainingHashes" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException#getMessage()} */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException#getMessage()} */" ); } + @Test public void testReplaceLinkTags_followedByHash() - throws Throwable { String comment = "/** {@link ConnectException} ##important## */"; String source = "import java.net.ConnectException;\n" @@ -145,11 +146,11 @@ public void testReplaceLinkTags_followedByHash() JavaClass clazz = getJavaSource( source ).getClassByName( "FollowedByHash" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** {@link java.net.ConnectException} ##important## */", newComment ); + assertThat( newComment ).isEqualTo( "/** {@link java.net.ConnectException} ##important## */" ); } + @Test public void testReplaceLinkTags_twoLinks() - throws Throwable { String comment = "/** Use {@link ConnectException} instead of {@link Exception} */"; String source = "import java.net.ConnectException;\n" @@ -159,11 +160,12 @@ public void testReplaceLinkTags_twoLinks() JavaClass clazz = getJavaSource( source ).getClassByName( "TwoLinks" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** Use {@link java.net.ConnectException} instead of {@link java.lang.Exception} */", newComment ); + assertThat( newComment ).isEqualTo( + "/** Use {@link java.net.ConnectException} instead of {@link java.lang.Exception} */" ); } + @Test public void testReplaceLinkTags_OnlyAnchor() - throws Throwable { String comment = "/** There's a {@link #getClass()} but no setClass() */"; String source = "import java.net.ConnectException;\n" @@ -173,6 +175,6 @@ public void testReplaceLinkTags_OnlyAnchor() JavaClass clazz = getJavaSource( source ).getClassByName( "OnlyAnchor" ); String newComment = AbstractFixJavadocMojo.replaceLinkTags( comment, clazz ); - assertEquals( "/** There's a {@link #getClass()} but no setClass() */", newComment ); + assertThat( newComment ).isEqualTo( "/** There's a {@link #getClass()} but no setClass() */" ); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java index 14324927..78046118 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java @@ -19,7 +19,8 @@ * under the License. */ -import static org.mockito.Matchers.anyString; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -28,33 +29,28 @@ import java.io.File; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; -import org.apache.maven.plugins.javadoc.AbstractJavadocMojo; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; public class AbstractJavadocMojoTest - extends TestCase { AbstractJavadocMojo mojo; - @Override - protected void setUp() - throws Exception + @Before + public void setUp() { - super.setUp(); mojo = new AbstractJavadocMojo() { @Override public void doExecute() - throws MojoExecutionException, MojoFailureException { } }; } + @Test public void testMJAVADOC432_DetectLinksMessages() { Log log = mock( Log.class ); @@ -63,20 +59,21 @@ public void testMJAVADOC432_DetectLinksMessages() mojo.outputDirectory = new File( "target/test-classes" ); // first continues after warning, next exits with warning - assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), true ) ); - assertFalse( mojo.isValidJavadocLink( "file://%%", true ) ); - assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), true ) ); + assertThat( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), true ) ).isFalse(); + assertThat( mojo.isValidJavadocLink( "file://%%", true ) ).isFalse(); + assertThat( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), true ) ).isFalse(); verify( log, times( 4 ) ).warn( anyString() ); verify( log, never() ).error( anyString() ); // first continues after error, next exits with error - assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), false ) ); - assertFalse( mojo.isValidJavadocLink( "file://%%", false ) ); - assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), false ) ); + assertThat( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), false ) ).isFalse(); + assertThat( mojo.isValidJavadocLink( "file://%%", false ) ).isFalse(); + assertThat( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), false ) ).isFalse(); verify( log, times( 4 ) ).error( anyString() ); verify( log, times( 4 ) ).warn( anyString() ); // no extra warnings } + @Test public void testMJAVADOC527_DetectLinksRecursion() { Log log = mock( Log.class ); @@ -84,7 +81,8 @@ public void testMJAVADOC527_DetectLinksRecursion() mojo.setLog( log ); mojo.outputDirectory = new File( "target/test-classes" ); - assertFalse( mojo.isValidJavadocLink( "http://javamail.java.net/mailapi/apidocs", false ) ); - assertTrue( mojo.isValidJavadocLink( "http://commons.apache.org/proper/commons-lang/apidocs", false ) ); + assertThat( mojo.isValidJavadocLink( "http://javamail.java.net/mailapi/apidocs", false ) ).isFalse(); + assertThat( + mojo.isValidJavadocLink( "http://commons.apache.org/proper/commons-lang/apidocs", false ) ).isTrue(); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java index 900851cb..eb46b6c2 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java @@ -21,10 +21,8 @@ import java.io.File; -import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -35,7 +33,8 @@ import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.codehaus.plexus.util.FileUtils; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Maria Odea Ching @@ -79,7 +78,7 @@ public void testDefaultConfig() //check if the javadoc jar file was generated File generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-default/target/javadocjar-default-javadoc.jar" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).exists(); Set set = new HashSet<>(); @@ -131,11 +130,11 @@ else if ( javadocVersion.isBefore( "1.8" ) ) //check if the javadoc files were created generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-default/target/site/apidocs/javadocjar/def/App.html" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat(generatedFile).exists(); generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-default/target/site/apidocs/javadocjar/def/AppSample.html" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).exists(); } /** @@ -154,7 +153,7 @@ public void testInvalidDestdir() //check if the javadoc jar file was generated File generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-invalid-destdir/target/javadocjar-invalid-destdir-javadoc.jar" ); - assertFalse( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).doesNotExist(); } public void testContinueIfFailOnErrorIsFalse() throws Exception @@ -167,7 +166,7 @@ public void testContinueIfFailOnErrorIsFalse() throws Exception //check if the javadoc jar file was generated File generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-failonerror/target/javadocjar-failonerror-javadoc.jar" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).exists(); } public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exception @@ -180,7 +179,7 @@ public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exceptio //check if the javadoc jar file was generated File generatedFile = new File( getBasedir(), "target/test/unit/javadocjar-archive-config/target/javadocjar-archive-config-javadoc.jar" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).exists(); //validate contents of jar file ZipFile jar = new ZipFile( generatedFile ); @@ -192,16 +191,12 @@ public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exceptio } jar.close(); - List expected = new ArrayList<>(); - expected.add( "META-INF/" ); - expected.add( "META-INF/maven/" ); - expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/" ); - expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/" ); - expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml" ); - expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties" ); - - for (String entry : expected) { - assertTrue("Expected jar to contain " + entry, set.contains(entry)); - } + assertThat( set ).contains( + "META-INF/", + "META-INF/maven/", + "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/", + "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/", + "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml", + "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties" ); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java index 393e66e5..a7f00eb6 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -19,7 +19,9 @@ * under the License. */ -import static org.junit.Assert.assertThat; +import static org.apache.commons.io.FileUtils.copyDirectory; +import static org.apache.commons.io.FileUtils.deleteDirectory; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeThat; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.containsString; @@ -36,9 +38,11 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; @@ -53,9 +57,10 @@ import org.apache.maven.repository.internal.MavenRepositorySystemSession; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; +import org.apache.maven.shared.utils.StringUtils; +import org.apache.maven.shared.utils.io.FileUtils; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.StringUtils; +import org.hamcrest.MatcherAssert; import org.junit.AssumptionViolatedException; import org.junit.Ignore; import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager; @@ -77,7 +82,7 @@ public class JavadocReportTest /** flag to copy repo only one time */ private static boolean TEST_REPO_CREATED = false; - private File unit; + private Path unit; private File localRepo; @@ -88,7 +93,7 @@ protected void setUp() { super.setUp(); - unit = new File( getBasedir(), "src/test/resources/unit" ); + unit = new File( getBasedir(), "src/test/resources/unit" ).toPath(); localRepo = new File( getBasedir(), "target/local-repo/" ); @@ -96,10 +101,10 @@ protected void setUp() } - private JavadocReport lookupMojo( File testPom ) + private JavadocReport lookupMojo( Path testPom ) throws Exception { - JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom.toFile() ); MojoExecution mojoExec = new MojoExecution( new Plugin(), "javadoc", null ); @@ -133,42 +138,42 @@ private void createTestRepo() // UMLGraph // ---------------------------------------------------------------------- - File sourceDir = new File( unit, "doclet-test/artifact-doclet" ); - assertTrue( sourceDir.exists() ); - FileUtils.copyDirectoryStructure( sourceDir, localRepo ); + Path sourceDir = unit.resolve( "doclet-test/artifact-doclet" ); + assertThat( sourceDir ).exists(); + copyDirectory( sourceDir.toFile(), localRepo ); // ---------------------------------------------------------------------- // UMLGraph-bis // ---------------------------------------------------------------------- - sourceDir = new File( unit, "doclet-path-test/artifact-doclet" ); - assertTrue( sourceDir.exists() ); - FileUtils.copyDirectoryStructure( sourceDir, localRepo ); + sourceDir = unit.resolve( "doclet-path-test/artifact-doclet" ); + assertThat( sourceDir ).exists(); + copyDirectory( sourceDir.toFile(), localRepo ); // ---------------------------------------------------------------------- // commons-attributes-compiler // http://www.tullmann.org/pat/taglets/ // ---------------------------------------------------------------------- - sourceDir = new File( unit, "taglet-test/artifact-taglet" ); - assertTrue( sourceDir.exists() ); - FileUtils.copyDirectoryStructure( sourceDir, localRepo ); + sourceDir = unit.resolve( "taglet-test/artifact-taglet" ); + assertThat( sourceDir ).exists(); + copyDirectory( sourceDir.toFile(), localRepo ); // ---------------------------------------------------------------------- // stylesheetfile-test // ---------------------------------------------------------------------- - sourceDir = new File( unit, "stylesheetfile-test/artifact-stylesheetfile" ); - assertTrue( sourceDir.exists() ); - FileUtils.copyDirectoryStructure( sourceDir, localRepo ); + sourceDir = unit.resolve( "stylesheetfile-test/artifact-stylesheetfile" ); + assertThat( sourceDir ).exists(); + copyDirectory( sourceDir.toFile(), localRepo ); // ---------------------------------------------------------------------- // helpfile-test // ---------------------------------------------------------------------- - sourceDir = new File( unit, "helpfile-test/artifact-helpfile" ); - assertTrue( sourceDir.exists() ); - FileUtils.copyDirectoryStructure( sourceDir, localRepo ); + sourceDir = unit.resolve( "helpfile-test/artifact-helpfile" ); + assertThat( sourceDir ).exists(); + copyDirectory( sourceDir.toFile(), localRepo ); // Remove SCM files List files = @@ -180,7 +185,7 @@ private void createTestRepo() if ( file.isDirectory() ) { - FileUtils.deleteDirectory( file ); + deleteDirectory( file ); } else { @@ -200,7 +205,7 @@ private void createTestRepo() * @return a String object that contains the contents of the file * @throws IOException if any */ - private static String readFile( File file ) + private static String readFile( Path file ) throws IOException { return readFile( file, StandardCharsets.UTF_8 ); @@ -216,12 +221,12 @@ private static String readFile( File file ) * @return a String object that contains the contents of the file * @throws IOException if any */ - private static String readFile( File file, Charset cs ) + private static String readFile( Path file, Charset cs ) throws IOException { - StringBuilder str = new StringBuilder( (int) file.length() ); + StringBuilder str = new StringBuilder( (int) Files.size( file ) ); - for ( String strTmp : Files.readAllLines( file.toPath(), cs ) ) + for ( String strTmp : Files.readAllLines( file, cs ) ) { str.append( LINE_SEPARATOR); str.append( strTmp ); @@ -238,20 +243,20 @@ private static String readFile( File file, Charset cs ) public void testDefaultConfiguration() throws Exception { - File testPom = new File( unit, "default-configuration/default-configuration-plugin-config.xml" ); + Path testPom = unit.resolve( "default-configuration/default-configuration-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); // package level generated javadoc files - File apidocs = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs" ).toPath(); String appHtml = "def/configuration/App.html"; - File generatedFile = new File( apidocs, appHtml ); - assertTrue( generatedFile.exists() ); + Path generatedFile = apidocs.resolve( appHtml ); + assertThat( generatedFile ).exists(); // only test when URL can be reached - String url = mojo.getDefaultJavadocApiLink().getUrl(); + String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl(); HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection(); connection.setRequestMethod( "HEAD" ); if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK ) @@ -261,8 +266,8 @@ public void testDefaultConfiguration() assumeThat( connection.getURL().toString(), is( url ) ); // https://bugs.openjdk.java.net/browse/JDK-8216497 - assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object", - FileUtils.fileRead( generatedFile, "UTF-8" ), + MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object", + new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ), anyOf( containsString( "/docs/api/java/lang/Object.html" ), containsString( "/docs/api/java.base/java/lang/Object.html" ) ) ); } @@ -272,39 +277,39 @@ public void testDefaultConfiguration() } } - assertTrue( new File( apidocs, "def/configuration/AppSample.html" ).exists() ); - assertTrue( new File( apidocs, "def/configuration/package-summary.html" ).exists() ); - assertTrue( new File( apidocs, "def/configuration/package-tree.html" ).exists() ); - assertTrue( new File( apidocs, "def/configuration/package-use.html" ).exists() ); + assertThat( apidocs.resolve( "def/configuration/AppSample.html" )).exists(); + assertThat( apidocs.resolve( "def/configuration/package-summary.html" )).exists(); + assertThat( apidocs.resolve( "def/configuration/package-tree.html" )).exists(); + assertThat( apidocs.resolve( "def/configuration/package-use.html" )).exists(); // package-frame and allclasses-(no)frame not generated anymore since Java 11 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) ) { - assertTrue( new File( apidocs, "def/configuration/package-frame.html" ).exists() ); - assertTrue( new File( apidocs, "allclasses-frame.html" ).exists() ); - assertTrue( new File( apidocs, "allclasses-noframe.html" ).exists() ); + assertThat( apidocs.resolve( "def/configuration/package-frame.html" )).exists();; + assertThat( apidocs.resolve( "allclasses-frame.html" )).exists(); + assertThat( apidocs.resolve( "allclasses-noframe.html" )).exists(); } // class level generated javadoc files - assertTrue( new File( apidocs, "def/configuration/class-use/App.html" ).exists() ); - assertTrue( new File( apidocs, "def/configuration/class-use/AppSample.html" ).exists() ); + assertThat( apidocs.resolve( "def/configuration/class-use/App.html" )).exists(); + assertThat( apidocs.resolve( "def/configuration/class-use/AppSample.html" )).exists(); // project level generated javadoc files - assertTrue( new File( apidocs, "constant-values.html" ).exists() ); - assertTrue( new File( apidocs, "deprecated-list.html" ).exists() ); - assertTrue( new File( apidocs, "help-doc.html" ).exists() ); - assertTrue( new File( apidocs, "index-all.html" ).exists() ); - assertTrue( new File( apidocs, "index.html" ).exists() ); - assertTrue( new File( apidocs, "overview-tree.html" ).exists() ); - assertTrue( new File( apidocs, "stylesheet.css" ).exists() ); + assertThat( apidocs.resolve( "constant-values.html" )).exists(); + assertThat( apidocs.resolve( "deprecated-list.html" ) ).exists(); + assertThat( apidocs.resolve( "help-doc.html" )).exists(); + assertThat( apidocs.resolve( "index-all.html" )).exists(); + assertThat( apidocs.resolve( "index.html" )).exists(); + assertThat( apidocs.resolve( "overview-tree.html" )).exists(); + assertThat( apidocs.resolve( "stylesheet.css" )).exists(); if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) { - assertTrue( new File( apidocs, "element-list" ).exists() ); + assertThat( apidocs.resolve( "element-list" )).exists(); } else { - assertTrue( new File( apidocs, "package-list" ).exists() ); + assertThat( apidocs.resolve( "package-list" )).exists(); } } @@ -316,38 +321,38 @@ public void testDefaultConfiguration() public void testSubpackages() throws Exception { - File testPom = new File( unit, "subpackages-test/subpackages-test-plugin-config.xml" ); + Path testPom = unit.resolve( "subpackages-test/subpackages-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/subpackages-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/subpackages-test/target/site/apidocs" ).toPath(); // check the excluded packages - assertFalse( new File( apidocs, "subpackages/test/excluded" ).exists() ); - assertFalse( new File( apidocs, "subpackages/test/included/exclude" ).exists() ); + assertThat( apidocs.resolve( "subpackages/test/excluded" ) ).doesNotExist(); + assertThat( apidocs.resolve( "subpackages/test/included/exclude" ) ).doesNotExist(); // check if the classes in the specified subpackages were included - assertTrue( new File( apidocs, "subpackages/test/App.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/AppSample.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/included/IncludedApp.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/included/IncludedAppSample.html" ).exists() ); + assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists(); } public void testIncludesExcludes() throws Exception { - File testPom = new File( unit, "file-include-exclude-test/file-include-exclude-plugin-config.xml" ); + Path testPom = unit.resolve( "file-include-exclude-test/file-include-exclude-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/file-include-exclude-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/file-include-exclude-test/target/site/apidocs" ).toPath(); // check if the classes in the specified subpackages were included - assertTrue( new File( apidocs, "subpackages/test/App.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/AppSample.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/included/IncludedApp.html" ).exists() ); - assertTrue( new File( apidocs, "subpackages/test/included/IncludedAppSample.html" ).exists() ); - assertFalse( new File( apidocs, "subpackages/test/PariahApp.html" ).exists() ); + assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists(); + assertThat( apidocs.resolve( "subpackages/test/PariahApp.html" ) ).doesNotExist(); } /** @@ -365,20 +370,20 @@ public void testDocfiles() return; } - File testPom = new File( unit, "docfiles-test/docfiles-test-plugin-config.xml" ); + Path testPom = unit.resolve( "docfiles-test/docfiles-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/" ); + Path apidocs = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/" ).toPath(); // check if the doc-files subdirectories were copied - assertTrue( new File( apidocs, "docfiles/test/doc-files" ).exists() ); - assertTrue( new File( apidocs, "docfiles/test/doc-files/included-dir1/sample-included1.gif" ).exists() ); - assertTrue( new File( apidocs, "docfiles/test/doc-files/included-dir2/sample-included2.gif" ).exists() ); - assertFalse( new File( apidocs, "docfiles/test/doc-files/excluded-dir1" ).exists() ); - assertFalse( new File( apidocs, "docfiles/test/doc-files/excluded-dir2" ).exists() ); + assertThat( apidocs.resolve( "docfiles/test/doc-files" )).exists(); + assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir1/sample-included1.gif" )).exists(); + assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir2/sample-included2.gif" )).exists(); + assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir1" )).doesNotExist(); + assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir2" )).doesNotExist(); - testPom = new File( unit, "docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" ); + testPom = unit.resolve( "docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); mojo.execute(); } @@ -392,28 +397,28 @@ public void testDocfiles() public void testCustomConfiguration() throws Exception { - File testPom = new File( unit, "custom-configuration/custom-configuration-plugin-config.xml" ); + Path testPom = unit.resolve( "custom-configuration/custom-configuration-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs" ).toPath(); // check if there is a tree page generated (notree == true) - assertFalse( new File( apidocs, "overview-tree.html" ).exists() ); - assertFalse( new File( apidocs, "custom/configuration/package-tree.html" ).exists() ); + assertThat( apidocs.resolve( "overview-tree.html" ) ).doesNotExist(); + assertThat( apidocs.resolve( "custom/configuration/package-tree.html" ) ).doesNotExist(); // check if the main index page was generated (noindex == true) - assertFalse( new File( apidocs, "index-all.html" ).exists() ); + assertThat( apidocs.resolve( "index-all.html" ) ).doesNotExist(); // check if the deprecated list and the deprecated api were generated (nodeprecated == true) // @todo Fix: the class-use of the deprecated api is still created eventhough the deprecated api of that class // is no longer generated - assertFalse( new File( apidocs, "deprecated-list.html" ).exists() ); - assertFalse( new File( apidocs, "custom/configuration/App.html" ).exists() ); + assertThat( apidocs.resolve( "deprecated-list.html" ) ).doesNotExist(); + assertThat( apidocs.resolve( "custom/configuration/App.html" ) ).doesNotExist(); // read the contents of the html files based on some of the parameter values // author == false - String str = readFile( new File( apidocs, "custom/configuration/AppSample.html" ) ); + String str = readFile( apidocs.resolve( "custom/configuration/AppSample.html" ) ); assertFalse( str.toLowerCase().contains( "author" ) ); // bottom @@ -422,35 +427,38 @@ public void testCustomConfiguration() // offlineLinks if ( JavaVersion.JAVA_VERSION.isBefore( "11.0.2" ) ) { - assertTrue( str.toLowerCase().contains( "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/string.html" ) ); + assertThat( str ).containsIgnoringCase( + "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/string.html" ); } else { - assertTrue( str.toLowerCase().contains( "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java.base/java/lang/string.html" ) ); + assertTrue( str.toLowerCase().contains( + "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java.base/java/lang/string.html" ) ); } // header assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST" ) ); // footer - assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) ); + if ( JavaVersion.JAVA_VERSION.isBefore( "16-ea" ) ) + { + assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) ); + } // nohelp == true assertFalse( str.toUpperCase().contains( "/HELP-DOC.HTML" ) ); // check the wildcard (*) package exclusions -- excludePackageNames parameter - assertTrue( new File( apidocs, "custom/configuration/exclude1/Exclude1App.html" ).exists() ); - assertFalse( new File( apidocs, "custom/configuration/exclude1/subexclude/SubexcludeApp.html" ).exists() ); - assertFalse( new File( apidocs, "custom/configuration/exclude2/Exclude2App.html" ).exists() ); + assertThat( apidocs.resolve( "custom/configuration/exclude1/Exclude1App.html" ) ).exists(); + assertThat( apidocs.resolve( "custom/configuration/exclude1/subexclude/SubexcludeApp.html" ) ).doesNotExist(); + assertThat( apidocs.resolve( "custom/configuration/exclude2/Exclude2App.html" ) ).doesNotExist(); - File options = new File( apidocs, "options" ); - assertTrue( options.isFile() ); + assertThat( apidocs.resolve( "options" ) ).isRegularFile(); - String contentOptions = FileUtils.fileRead( options ); + String contentOptions = new String( Files.readAllBytes( apidocs.resolve( "options" ) ), StandardCharsets.UTF_8 ); assertNotNull( contentOptions ); - assertTrue( contentOptions.contains( "-link" ) ); - assertTrue( contentOptions.contains( "http://java.sun.com/j2se/" ) ); + assertThat( contentOptions ).contains( "-link" ).contains( "http://java.sun.com/j2se/" ); } /** @@ -466,15 +474,15 @@ public void testDoclets() // As of JDK 13, the com.sun.javadoc API is no longer supported. return; } - + // ---------------------------------------------------------------------- // doclet-test: check if the file generated by UmlGraph exists and if // doclet path contains the UmlGraph artifact // ---------------------------------------------------------------------- - File testPom = new File( unit, "doclet-test/doclet-test-plugin-config.xml" ); + Path testPom = unit.resolve( "doclet-test/doclet-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); - + MavenSession session = spy( newMavenSession( mojo.project ) ); ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class ); when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() ); @@ -490,36 +498,34 @@ public void testDoclets() mojo.execute(); - File generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + Path generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath(); + assertThat( generatedFile ).exists(); - File optionsFile = new File( mojo.getOutputDirectory(), "options" ); - assertTrue( optionsFile.exists() ); + Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath(); + assertThat( optionsFile ).exists(); String options = readFile( optionsFile ); - assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) ); + assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ); // ---------------------------------------------------------------------- // doclet-path: check if the file generated by UmlGraph exists and if // doclet path contains the twice UmlGraph artifacts // ---------------------------------------------------------------------- - testPom = new File( unit, "doclet-path-test/doclet-path-test-plugin-config.xml" ); + testPom = unit.resolve( "doclet-path-test/doclet-path-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); setVariableValueToObject( mojo, "session", session ); mojo.execute(); - generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath(); + assertThat( generatedFile ).exists(); - optionsFile = new File( mojo.getOutputDirectory(), "options" ); - assertTrue( optionsFile.exists() ); + optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath(); + assertThat( optionsFile ).exists(); options = readFile( optionsFile ); - assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) ); - assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) ); + assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) + .contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ); } - - /** * Method to test when the path to the project sources has an apostrophe (') * @@ -528,29 +534,29 @@ public void testDoclets() public void testQuotedPath() throws Exception { - File testPom = new File( unit, "quotedpath'test/quotedpath-test-plugin-config.xml" ); + Path testPom = unit.resolve( "quotedpath'test/quotedpath-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" ).toPath(); // package level generated javadoc files - assertTrue( new File( apidocs, "quotedpath/test/App.html" ).exists() ); - assertTrue( new File( apidocs, "quotedpath/test/AppSample.html" ).exists() ); + assertThat( apidocs.resolve( "quotedpath/test/App.html" ) ).exists(); + assertThat( apidocs.resolve( "quotedpath/test/AppSample.html" ) ).exists(); // project level generated javadoc files - assertTrue( new File( apidocs, "index-all.html" ).exists() ); - assertTrue( new File( apidocs, "index.html" ).exists() ); - assertTrue( new File( apidocs, "overview-tree.html" ).exists() ); - assertTrue( new File( apidocs, "stylesheet.css" ).exists() ); + assertThat( apidocs.resolve( "index-all.html" ) ).exists(); + assertThat( apidocs.resolve( "index.html" ) ).exists(); + assertThat( apidocs.resolve( "overview-tree.html" ) ).exists(); + assertThat( apidocs.resolve( "stylesheet.css" ) ).exists(); if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) ) { - assertTrue( new File( apidocs, "package-list" ).exists() ); + assertThat( apidocs.resolve( "package-list" ) ).exists(); } else { - assertTrue( new File( apidocs, "element-list" ).exists() ); + assertThat( apidocs.resolve( "element-list" ) ).exists(); } } @@ -562,12 +568,12 @@ public void testQuotedPath() public void testOptionsUmlautEncoding() throws Exception { - File testPom = new File( unit, "optionsumlautencoding-test/optionsumlautencoding-test-plugin-config.xml" ); + Path testPom = unit.resolve( "optionsumlautencoding-test/optionsumlautencoding-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File optionsFile = new File( mojo.getOutputDirectory(), "options" ); - assertTrue( optionsFile.exists() ); + Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath(); + assertThat( optionsFile ).exists(); // check for a part of the window title String content; @@ -583,27 +589,27 @@ public void testOptionsUmlautEncoding() expected = new String( OPTIONS_UMLAUT_ENCODING.getBytes( Charset.defaultCharset() ) ); } - assertTrue( content.contains( expected ) ); + assertThat( content ).contains( expected ); - File apidocs = new File( getBasedir(), "target/test/unit/optionsumlautencoding-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/optionsumlautencoding-test/target/site/apidocs" ).toPath(); // package level generated javadoc files - assertTrue( new File( apidocs, "optionsumlautencoding/test/App.html" ).exists() ); - assertTrue( new File( apidocs, "optionsumlautencoding/test/AppSample.html" ).exists() ); + assertThat( apidocs.resolve( "optionsumlautencoding/test/App.html" ) ).exists(); + assertThat( apidocs.resolve( "optionsumlautencoding/test/AppSample.html" ) ).exists(); // project level generated javadoc files - assertTrue( new File( apidocs, "index-all.html" ).exists() ); - assertTrue( new File( apidocs, "index.html" ).exists() ); - assertTrue( new File( apidocs, "overview-tree.html" ).exists() ); - assertTrue( new File( apidocs, "stylesheet.css" ).exists() ); + assertThat( apidocs.resolve( "index-all.html" ) ).exists(); + assertThat( apidocs.resolve( "index.html" ) ).exists(); + assertThat( apidocs.resolve( "overview-tree.html" ) ).exists(); + assertThat( apidocs.resolve( "stylesheet.css" ) ).exists(); if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) ) { - assertTrue( new File( apidocs, "package-list" ).exists() ); + assertThat( apidocs.resolve( "package-list" )).exists(); } else { - assertTrue( new File( apidocs, "element-list" ).exists() ); + assertThat( apidocs.resolve( "element-list" )).exists(); } } @@ -615,7 +621,7 @@ public void testExceptions() { try { - File testPom = new File( unit, "default-configuration/exception-test-plugin-config.xml" ); + Path testPom = unit.resolve( "default-configuration/exception-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); @@ -627,7 +633,7 @@ public void testExceptions() try { - FileUtils.deleteDirectory( new File( getBasedir(), "exception" ) ); + deleteDirectory( new File( getBasedir(), "exception" ) ); } catch ( IOException ie ) { @@ -656,7 +662,7 @@ public void testTaglets() return; } - File testPom = new File( unit, "taglet-test/taglet-test-plugin-config.xml" ); + Path testPom = unit.resolve( "taglet-test/taglet-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); MavenSession session = spy( newMavenSession( mojo.project ) ); @@ -674,14 +680,14 @@ public void testTaglets() mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" ).toPath(); - assertTrue( new File( apidocs, "index.html" ).exists() ); + assertThat( apidocs.resolve( "index.html" )).exists(); - File appFile = new File( apidocs, "taglet/test/App.html" ); - assertTrue( appFile.exists() ); + Path appFile = apidocs.resolve( "taglet/test/App.html" ); + assertThat( appFile ).exists(); String appString = readFile( appFile ); - assertTrue( appString.contains( "To Do:" ) ); + assertThat( appString ).contains( "To Do:" ); } /** @@ -699,24 +705,23 @@ public void testJdk5() return; } - File testPom = new File( unit, "jdk5-test/jdk5-test-plugin-config.xml" ); + Path testPom = unit.resolve( "jdk5-test/jdk5-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" ).toPath(); - File index = new File( apidocs, "index.html" ); - assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) ); + assertThat( apidocs.resolve( "index.html" ) ).exists(); - File overviewSummary = new File( apidocs, "overview-summary.html" ); - assertTrue( overviewSummary.exists() ); + Path overviewSummary = apidocs.resolve( "overview-summary.html" ); + assertThat( overviewSummary ).exists(); String content = readFile( overviewSummary ); - assertTrue( content.contains( "Test the package-info" ) ); + assertThat( content ).contains( "Test the package-info" ); - File packageSummary = new File( apidocs, "jdk5/test/package-summary.html" ); - assertTrue( packageSummary.exists() ); + Path packageSummary = apidocs.resolve( "jdk5/test/package-summary.html" ); + assertThat( packageSummary ).exists(); content = readFile( packageSummary ); - assertTrue( content.contains( "Test the package-info" ) ); + assertThat( content ).contains( "Test the package-info" ); } /** @@ -731,7 +736,7 @@ public void testToFindJavadoc() String oldJreHome = System.getProperty( "java.home" ); System.setProperty( "java.home", "foo/bar" ); - File testPom = new File( unit, "javaHome-test/javaHome-test-plugin-config.xml" ); + Path testPom = unit.resolve( "javaHome-test/javaHome-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); @@ -746,55 +751,57 @@ public void testToFindJavadoc() public void testJavadocResources() throws Exception { - File testPom = new File( unit, "resources-test/resources-test-plugin-config.xml" ); + Path testPom = unit.resolve( "resources-test/resources-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" ); + Path apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" ).toPath(); - File app = new File( apidocs, "resources/test/App.html" ); - assertTrue( app.exists() ); + Path app = apidocs.resolve( "resources/test/App.html" ); + assertThat( app ).exists(); String content = readFile( app ); - assertTrue( content.contains( "\"Maven\"" ) ); - assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() ); + assertThat( content ).contains( "\"Maven\"" ); + assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" )).exists(); - File app2 = new File( apidocs, "resources/test2/App2.html" ); - assertTrue( app2.exists() ); + Path app2 = apidocs.resolve( "resources/test2/App2.html" ); + assertThat( app2 ).exists(); content = readFile( app2 ); - assertTrue( content.contains( "\"Maven\"" ) ); - assertFalse( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() ); + assertThat( content ).contains( "\"Maven\"" ); + assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" )).doesNotExist(); // with excludes - testPom = new File( unit, "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" ); + testPom = unit.resolve( "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); mojo.execute(); - apidocs = new File( getBasedir(), "target/test/unit/resources-with-excludes-test/target/site/apidocs" ); + apidocs = new File( getBasedir(), + "target/test/unit/resources-with-excludes-test/target/site/apidocs" ).toPath(); - app = new File( apidocs, "resources/test/App.html" ); - assertTrue( app.exists() ); + app = apidocs.resolve( "resources/test/App.html" ); + assertThat( app ).exists(); content = readFile( app ); - assertTrue( content.contains( "\"Maven\"" ) ); + assertThat( content ).contains( "\"Maven\"" ); JavaVersion javadocVersion = (JavaVersion) getVariableValueFromObject( mojo, "javadocRuntimeVersion" ); if( javadocVersion.isAtLeast( "1.8" ) /* && javadocVersion.isBefore( "14" ) */ ) { // https://bugs.openjdk.java.net/browse/JDK-8032205 - assertTrue( "Javadoc runtime version: " + javadocVersion - + "\nThis bug appeared in JDK8 and was planned to be fixed in JDK9, see JDK-8032205", - new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() ); + assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" )) + .as("Javadoc runtime version: " + javadocVersion + + "\nThis bug appeared in JDK8 and was planned to be fixed in JDK9, see JDK-8032205") + .exists(); } else { - assertFalse( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() ); + assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" ) ).doesNotExist(); } - assertTrue( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() ); + assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists(); - app2 = new File( apidocs, "resources/test2/App2.html" ); - assertTrue( app2.exists() ); + app2 = apidocs.resolve( "resources/test2/App2.html" ); + assertThat( app2 ).exists(); content = readFile( app2 ); - assertTrue( content.contains( "\"Maven\"" ) ); - assertTrue( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() ); + assertThat( content ).contains( "\"Maven\"" ); + assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists(); } /** @@ -805,11 +812,11 @@ public void testJavadocResources() public void testPom() throws Exception { - File testPom = new File( unit, "pom-test/pom-test-plugin-config.xml" ); + Path testPom = unit.resolve( "pom-test/pom-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - assertFalse( new File( getBasedir(), "target/test/unit/pom-test/target/site" ).exists() ); + assertThat( new File( getBasedir(), "target/test/unit/pom-test/target/site" )).doesNotExist(); } /** @@ -820,23 +827,22 @@ public void testPom() public void testTag() throws Exception { - File testPom = new File( unit, "tag-test/tag-test-plugin-config.xml" ); + Path testPom = unit.resolve( "tag-test/tag-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" ); - assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) ); + Path app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" ).toPath(); + assertThat( app ).exists(); String readed = readFile( app ); - assertTrue( readed.contains( ">To do something:Generator Class:To do something:Generator Class:Version:" + LINE_SEPARATOR + "
1.0
" ) - || readed.toLowerCase().contains( "" + LINE_SEPARATOR + "
1.0
" /* JDK 8 */) ); + assertThat( readed ).contains( ">Version:" + LINE_SEPARATOR + "
1.0
" ) || readed.toLowerCase().contains( + "" + LINE_SEPARATOR + "
1.0
" /* JDK 8 */ ) ); } } @@ -848,7 +854,7 @@ public void testTag() public void testHeaderFooter() throws Exception { - File testPom = new File( unit, "header-footer-test/header-footer-test-plugin-config.xml" ); + Path testPom = unit.resolve( "header-footer-test/header-footer-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); try { @@ -870,7 +876,7 @@ public void testHeaderFooter() public void testNewline() throws Exception { - File testPom = new File( unit, "newline-test/newline-test-plugin-config.xml" ); + Path testPom = unit.resolve( "newline-test/newline-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); try { @@ -899,35 +905,35 @@ public void testJdk6() return; } - File testPom = new File( unit, "jdk6-test/jdk6-test-plugin-config.xml" ); + Path testPom = unit.resolve( "jdk6-test/jdk6-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); mojo.execute(); - File apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" ); - assertTrue( new File( apidocs, "index.html" ).exists() ); + Path apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" ).toPath(); + assertThat( apidocs.resolve( "index.html" ) ).exists(); - File overview; + Path overview; if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) ) { - overview = new File( apidocs, "overview-summary.html" ); + overview = apidocs.resolve( "overview-summary.html" ); } else { - overview = new File( apidocs, "index.html" ); + overview = apidocs.resolve( "index.html" ); } - assertTrue( overview.exists() ); + assertThat( overview ).exists(); String content = readFile( overview ); - assertTrue( content.contains( "Top - Copyright © All rights reserved." ) ); - assertTrue( content.contains( "Header - Copyright © All rights reserved." ) ); - assertTrue( content.contains( "Footer - Copyright © All rights reserved." ) ); + assertThat( content ).contains( "Top - Copyright © All rights reserved." ) + .contains( "Header - Copyright © All rights reserved." ) + .contains( "Footer - Copyright © All rights reserved." ); - File packageSummary = new File( apidocs, "jdk6/test/package-summary.html" ); - assertTrue( packageSummary.exists() ); + Path packageSummary = apidocs.resolve( "jdk6/test/package-summary.html" ); + assertThat( packageSummary ).exists(); content = readFile( packageSummary ); - assertTrue( content.contains( "Top - Copyright © All rights reserved." ) ); - assertTrue( content.contains( "Header - Copyright © All rights reserved." ) ); - assertTrue( content.contains( "Footer - Copyright © All rights reserved." ) ); + assertThat( content ).contains( "Top - Copyright © All rights reserved." ) + .contains( "Header - Copyright © All rights reserved." ) + .contains( "Footer - Copyright © All rights reserved." ); } /** @@ -940,7 +946,10 @@ public void testProxy() throws Exception { // ignore test as annotation doesn't ignore anything.. - if(true) return; + if ( true ) + { + return; + } Settings settings = new Settings(); Proxy proxy = new Proxy(); @@ -954,7 +963,7 @@ public void testProxy() proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" ); settings.addProxy( proxy ); - File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" ); + Path testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" ).toPath(); JavadocReport mojo = lookupMojo( testPom ); MavenSession session = spy( newMavenSession( mojo.project ) ); @@ -972,18 +981,17 @@ public void testProxy() setVariableValueToObject( mojo, "session", session ); mojo.execute(); - File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) ); - assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) ); + Path commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) ).toPath(); + assertThat( commandLine ).exists(); String readed = readFile( commandLine ); - assertTrue( readed.contains( "-J-Dhttp.proxyHost=127.0.0.1" ) ); - assertTrue( readed.contains( "-J-Dhttp.proxyPort=80" ) ); - assertTrue( readed.contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com^|*.somewhere.com\\\"" ) ); + assertThat( readed ).contains( "-J-Dhttp.proxyHost=127.0.0.1" ).contains( "-J-Dhttp.proxyPort=80" ) + .contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com^|*.somewhere.com\\\"" ); - File options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" ); - assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) ); + Path options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" ).toPath(); + assertThat( options ).exists(); String optionsContent = readFile( options ); // NO -link expected - assertFalse( optionsContent.contains( "-link" ) ); + assertThat( optionsContent ).doesNotContain( "-link" ); // real proxy ProxyServer proxyServer = null; @@ -1012,15 +1020,15 @@ public void testProxy() optionsContent = readFile( options ); // -link expected -// TODO: This got disabled for now! -// This test fails since the last commit but I actually think it only ever worked by accident. -// It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously. -// But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in -// target/local-repo anymore, thus the javadoc link info cannot get built and the test fails -// I'll for now just disable this line of code, because the test as far as I can see _never_ -// did go upstream. The remoteRepository list used is always empty!. -// -// assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); + // TODO: This got disabled for now! + // This test fails since the last commit but I actually think it only ever worked by accident. + // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously. + // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in + // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails + // I'll for now just disable this line of code, because the test as far as I can see _never_ + // did go upstream. The remoteRepository list used is always empty!. + // + // assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); } finally { @@ -1054,13 +1062,13 @@ public void testProxy() setVariableValueToObject( mojo, "session", session ); mojo.execute(); readed = readFile( commandLine ); - assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) ); - assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) ); + assertThat( readed ).contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) + .contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ); optionsContent = readFile( options ); // -link expected -// see comment above (line 829) -// assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); + // see comment above (line 829) + // assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); } finally { @@ -1080,7 +1088,7 @@ public void testValidateOptions() throws Exception { // encoding - File testPom = new File( unit, "validate-options-test/wrong-encoding-test-plugin-config.xml" ); + Path testPom = unit.resolve( "validate-options-test/wrong-encoding-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); try { @@ -1091,7 +1099,7 @@ public void testValidateOptions() { assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option " ) ); } - testPom = new File( unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml" ); + testPom = unit.resolve( "validate-options-test/wrong-docencoding-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); try { @@ -1102,7 +1110,7 @@ public void testValidateOptions() { assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option " ) ); } - testPom = new File( unit, "validate-options-test/wrong-charset-test-plugin-config.xml" ); + testPom = unit.resolve( "validate-options-test/wrong-charset-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); try { @@ -1115,7 +1123,7 @@ public void testValidateOptions() } // locale - testPom = new File( unit, "validate-options-test/wrong-locale-test-plugin-config.xml" ); + testPom = unit.resolve( "validate-options-test/wrong-locale-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); try { @@ -1126,13 +1134,13 @@ public void testValidateOptions() { assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option " ) ); } - testPom = new File( unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" ); + testPom = unit.resolve( "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); mojo.execute(); assertTrue( "No wrong locale catch", true ); // conflict options - testPom = new File( unit, "validate-options-test/conflict-options-test-plugin-config.xml" ); + testPom = unit.resolve( "validate-options-test/conflict-options-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); try { @@ -1160,7 +1168,7 @@ public void testTagletArtifacts() return; } - File testPom = new File( unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" ); + Path testPom = unit.resolve( "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" ); JavadocReport mojo = lookupMojo( testPom ); MavenSession session = spy( newMavenSession( mojo.project ) ); @@ -1177,31 +1185,31 @@ public void testTagletArtifacts() mojo.execute(); - File optionsFile = new File( mojo.getOutputDirectory(), "options" ); - assertTrue( optionsFile.exists() ); + Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath(); + assertThat( optionsFile ).exists(); String options = readFile( optionsFile ); // count -taglet - assertEquals( 22, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) ); - assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) ); - assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) ); - assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) ); - assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) ); + assertThat( StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) ).isEqualTo( 22 ); + assertThat( options ).contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) + .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) + .contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) + .contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) + .contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ); } /** @@ -1212,7 +1220,7 @@ public void testTagletArtifacts() public void testStylesheetfile() throws Exception { - File testPom = new File( unit, "stylesheetfile-test/pom.xml" ); + Path testPom = unit.resolve( "stylesheetfile-test/pom.xml" ); JavadocReport mojo = lookupMojo( testPom ); assertNotNull( mojo ); @@ -1229,10 +1237,10 @@ public void testStylesheetfile() legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); - File apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" ).toPath(); - File stylesheetfile = new File( apidocs, "stylesheet.css" ); - File options = new File( apidocs, "options" ); + Path stylesheetfile = apidocs.resolve( "stylesheet.css" ); + Path options = apidocs.resolve( "options" ); // stylesheet == maven OR java setVariableValueToObject( mojo, "stylesheet", "javamaven" ); @@ -1282,7 +1290,7 @@ else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-stylesheetfile" ) ); - assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); // stylesheetfile defined as a project resource setVariableValueToObject( mojo, "stylesheet", null ); @@ -1294,9 +1302,9 @@ else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-stylesheetfile" ) ); - File stylesheetResource = - new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" ); - assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" ) + Path stylesheetResource = + unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" ); + assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); // stylesheetfile defined in a javadoc plugin dependency @@ -1308,12 +1316,12 @@ else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-stylesheetfile" ) ); - assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); // stylesheetfile defined as file - File css = - new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" ); - setVariableValueToObject( mojo, "stylesheetfile", css.getAbsolutePath() ); + Path css = + unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" ); + setVariableValueToObject( mojo, "stylesheetfile", css.toFile().getAbsolutePath() ); mojo.execute(); content = readFile( stylesheetfile ); @@ -1322,8 +1330,8 @@ else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-stylesheetfile" ) ); stylesheetResource = - new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" ); - assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" ); + assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); } /** @@ -1334,7 +1342,7 @@ else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) ) public void testHelpfile() throws Exception { - File testPom = new File( unit, "helpfile-test/pom.xml" ); + Path testPom = unit.resolve( "helpfile-test/pom.xml" ); JavadocReport mojo = lookupMojo( testPom ); assertNotNull( mojo ); @@ -1351,10 +1359,10 @@ public void testHelpfile() legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); - File apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" ); + Path apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" ).toPath(); - File helpfile = new File( apidocs, "help-doc.html" ); - File options = new File( apidocs, "options" ); + Path helpfile = apidocs.resolve( "help-doc.html" ); + Path options = apidocs.resolve( "options" ); // helpfile by default mojo.execute(); @@ -1377,8 +1385,8 @@ public void testHelpfile() optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-helpfile" ) ); - File help = new File( apidocs, "help-doc.html" ); - assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + Path help = apidocs.resolve( "help-doc.html" ); + assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); // helpfile defined as a project resource setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" ); @@ -1389,12 +1397,12 @@ public void testHelpfile() optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-helpfile" ) ); - help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" ); - assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" ); + assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); // helpfile defined as file - help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" ); - setVariableValueToObject( mojo, "helpfile", help.getAbsolutePath() ); + help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" ); + setVariableValueToObject( mojo, "helpfile", help.toFile().getAbsolutePath() ); mojo.execute(); content = readFile( helpfile ); @@ -1402,6 +1410,6 @@ public void testHelpfile() optionsContent = readFile( options ); assertTrue( optionsContent.contains( "-helpfile" ) ); - assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); + assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) ); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java index e3a00d1b..8260d66d 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java @@ -1,7 +1,5 @@ package org.apache.maven.plugins.javadoc; -import static org.junit.Assert.assertArrayEquals; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -39,11 +37,9 @@ import java.util.Set; import java.util.regex.PatternSyntaxException; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.plugins.javadoc.ProxyServer.AuthAsyncProxyServlet; import org.apache.maven.settings.Proxy; @@ -55,6 +51,8 @@ import org.mortbay.jetty.handler.MovedContextHandler; import org.mortbay.util.ByteArrayISO8859Writer; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Vincent Siveton */ @@ -64,10 +62,8 @@ public class JavadocUtilTest /** * Method to test the javadoc version parsing. * - * @throws Exception if any */ public void testParseJavadocVersion() - throws Exception { String version = null; try @@ -174,10 +170,8 @@ public void testParseJavadocVersion() /** * Method to test the javadoc memory parsing. * - * @throws Exception if any */ public void testParseJavadocMemory() - throws Exception { String memory = null; try @@ -248,10 +242,8 @@ public void testParseJavadocMemory() /** * Method to test the validate encoding parsing. * - * @throws Exception if any */ public void testValidateEncoding() - throws Exception { assertFalse( "Not catch null", JavadocUtil.validateEncoding( null ) ); assertTrue( "UTF-8 not supported on this plateform", JavadocUtil.validateEncoding( "UTF-8" ) ); @@ -369,10 +361,7 @@ public void testIsValidPackageList() } finally { - if ( proxyServer != null ) - { - proxyServer.stop(); - } + proxyServer.stop(); } // auth proxy @@ -406,10 +395,7 @@ public void testIsValidPackageList() } finally { - if ( proxyServer != null ) - { - proxyServer.stop(); - } + proxyServer.stop(); } // timeout @@ -438,10 +424,7 @@ public void testIsValidPackageList() } finally { - if ( proxyServer != null ) - { - proxyServer.stop(); - } + proxyServer.stop(); } // nonProxyHosts @@ -466,10 +449,7 @@ public void testIsValidPackageList() } finally { - if ( proxyServer != null ) - { - proxyServer.stop(); - } + proxyServer.stop(); } } @@ -498,7 +478,7 @@ public void testGetRedirectUrl() @Override public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) - throws IOException, ServletException + throws IOException { response.setStatus( HttpServletResponse.SC_OK ); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 ); @@ -547,7 +527,7 @@ public void testGetRedirectUrlWithNoRedirects() @Override public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) - throws IOException, ServletException + throws IOException { response.setStatus( HttpServletResponse.SC_OK ); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 ); @@ -589,7 +569,7 @@ public void testGetRedirectUrlVerifyHeaders() @Override public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) - throws IOException, ServletException + throws IOException { if ( request.getHeader( "Accept" ) == null ) { @@ -622,7 +602,7 @@ public void testCopyJavadocResources() throws Exception { File input = new File( getBasedir(), "src/test/resources/unit/docfiles-test/docfiles/" ); - assertTrue( input.exists() ); + assertThat( input ).exists(); File output = new File( getBasedir(), "target/test/unit/docfiles-test/target/output" ); if ( output.exists() ) @@ -632,26 +612,17 @@ public void testCopyJavadocResources() assertTrue( output.mkdirs() ); JavadocUtil.copyJavadocResources( output, input, null ); - List expected = new ArrayList<>(); - expected.add( "test" + File.separator + "doc-files" + File.separator + "excluded-dir1" + File.separator - + "sample-excluded1.gif" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "excluded-dir2" + File.separator - + "sample-excluded2.gif" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir1" + File.separator - + "sample-included1.gif" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir2" + File.separator - + "sample-included2.gif" ); - assertTrue( EqualsBuilder.reflectionEquals( expected, FileUtils.getFiles( output, null, null, false ) ) ); - expected = new ArrayList<>(); - expected.add( "" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "excluded-dir1" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "excluded-dir1" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir1" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir2" ); - assertTrue( EqualsBuilder.reflectionEquals( expected, - FileUtils.getDirectoryNames( new File( output, - "test/doc-files" ), - null, null, false ) ) ); + + assertThat( FileUtils.getFiles( output, null, null, false ) ) + .containsExactlyInAnyOrder( + Paths.get( "test", "doc-files", "excluded-dir1", "sample-excluded1.gif" ).toFile(), + Paths.get( "test", "doc-files", "excluded-dir2", "sample-excluded2.gif" ).toFile(), + Paths.get( "test", "doc-files", "included-dir1", "sample-included1.gif" ).toFile(), + Paths.get( "test", "doc-files", "included-dir2", "sample-included2.gif" ).toFile() + ); + + assertThat( FileUtils.getDirectoryNames( new File( output, "test/doc-files" ), null, null, false ) ) + .containsExactlyInAnyOrder( "", "excluded-dir1", "excluded-dir2", "included-dir1", "included-dir2" ); input = new File( getBasedir(), "src/test/resources/unit/docfiles-test/docfiles/" ); assertTrue( input.exists() ); @@ -664,29 +635,22 @@ public void testCopyJavadocResources() assertTrue( output.mkdirs() ); JavadocUtil.copyJavadocResources( output, input, "excluded-dir1:excluded-dir2" ); - expected = new ArrayList<>(); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir1" + File.separator - + "sample-included1.gif" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir2" + File.separator - + "sample-included2.gif" ); - assertTrue( EqualsBuilder.reflectionEquals( expected, FileUtils.getFiles( output, null, null, false ) ) ); - expected = new ArrayList<>(); - expected.add( "" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir1" ); - expected.add( "test" + File.separator + "doc-files" + File.separator + "included-dir2" ); - assertTrue( EqualsBuilder.reflectionEquals( expected, - FileUtils.getDirectoryNames( new File( output, - "test/doc-files" ), - null, null, false ) ) ); + + assertThat( FileUtils.getFiles( output, null, null, false ) ) + .containsExactlyInAnyOrder( + Paths.get( "test", "doc-files", "included-dir1", "sample-included1.gif" ).toFile(), + Paths.get( "test", "doc-files", "included-dir2", "sample-included2.gif" ).toFile() + ); + + assertThat( FileUtils.getDirectoryNames( new File( output, "test/doc-files" ), null, null, false ) ) + .containsExactlyInAnyOrder( "", "included-dir1", "included-dir2" ); } /** * Method to test pruneDirs() * - * @throws Exception if any */ public void testPruneDirs() - throws Exception { List list = new ArrayList<>(); list.add( getBasedir() + "/target/classes" ); @@ -704,10 +668,8 @@ public void testPruneDirs() /** * Method to test unifyPathSeparator() * - * @throws Exception if any */ public void testUnifyPathSeparator() - throws Exception { assertNull( JavadocUtil.unifyPathSeparator( null ) ); @@ -736,7 +698,7 @@ public void testUnifyPathSeparator() } - public void testGetIncludedFiles() throws Exception + public void testGetIncludedFiles() { File sourceDirectory = new File("target/it").getAbsoluteFile(); String[] fileList = new String[] { "Main.java" }; @@ -744,7 +706,7 @@ public void testGetIncludedFiles() throws Exception List includedFiles = JavadocUtil.getIncludedFiles( sourceDirectory, fileList, excludePackages ); - assertArrayEquals( fileList, includedFiles.toArray( new String[0] ) ); + assertThat( includedFiles.toArray( new String[0] ) ).isEqualTo( fileList ); } private void stopSilently( Server server ) diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java index 0f0bc233..ac63c249 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java @@ -19,50 +19,51 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class JavadocVersionTest { /** * Parsing is lazy, only triggered when comparing * - * @throws Exception + * @noinspection deprecation */ @Test - public void testParse() throws Exception + public void testParse() { - assertTrue( JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.4.2" ) ) < 0 ); - assertTrue( JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.5" ) ) < 0 ); - assertTrue( JavadocVersion.parse( "1.8" ).compareTo( JavadocVersion.parse( "9" ) ) < 0 ); + assertThat( JavadocVersion.parse( "1.4" ) ) + .isLessThan( JavadocVersion.parse( "1.4.2" ) ) + .isLessThan( JavadocVersion.parse( "1.5" ) ); + + assertThat( JavadocVersion.parse( "1.8" ) ).isLessThan( JavadocVersion.parse( "9" ) ); - assertEquals( 0, JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.4" ) ) ); - assertEquals( 0, JavadocVersion.parse( "1.4.2" ).compareTo( JavadocVersion.parse( "1.4.2" ) ) ); - assertEquals( 0, JavadocVersion.parse( "9" ).compareTo( JavadocVersion.parse( "9" ) ) ); + assertThat( JavadocVersion.parse( "1.4" ) ).isEqualByComparingTo( JavadocVersion.parse( "1.4" ) ); + assertThat( JavadocVersion.parse( "1.4.2" ) ).isEqualByComparingTo( JavadocVersion.parse( "1.4.2" ) ); + assertThat( JavadocVersion.parse( "9" ) ).isEqualByComparingTo( JavadocVersion.parse( "9" ) ); - assertTrue( JavadocVersion.parse( "1.4.2" ).compareTo( JavadocVersion.parse( "1.4" ) ) > 0 ); - assertTrue( JavadocVersion.parse( "1.5" ).compareTo( JavadocVersion.parse( "1.4" ) ) > 0 ); - assertTrue( JavadocVersion.parse( "9" ).compareTo( JavadocVersion.parse( "1.8" ) ) > 0 ); + assertThat( JavadocVersion.parse( "1.4.2" ) ).isGreaterThan( JavadocVersion.parse( "1.4" ) ); + assertThat( JavadocVersion.parse( "1.5" ) ).isGreaterThan( JavadocVersion.parse( "1.4" ) ); + assertThat( JavadocVersion.parse( "9" ) ).isGreaterThan( JavadocVersion.parse( "1.8" ) ); } @Test public void testApiVersion() { Pattern p = Pattern.compile( "(1\\.\\d|\\d\\d*)" ); Matcher m = p.matcher( "9" ); - assertTrue(m.find()); - assertEquals( "9", m.group( 1 )); + assertThat( m.find() ).isTrue(); + assertThat( m.group( 1 ) ).isEqualTo( "9" ); m = p.matcher( "1.4" ); - assertTrue(m.find()); - assertEquals( "1.4", m.group( 1 )); + assertThat( m.find() ).isTrue(); + assertThat( m.group( 1 ) ).isEqualTo( "1.4" ); m = p.matcher( "1.4.2" ); - assertTrue(m.find()); - assertEquals( "1.4", m.group( 1 )); + assertThat( m.find() ).isTrue(); + assertThat( m.group( 1 ) ).isEqualTo( "1.4" ); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java index 7ada0dac..450db323 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java @@ -28,6 +28,8 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Vincent Siveton */ @@ -61,9 +63,9 @@ public void testTestJavadoc() File generatedFile = new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/maven/AppTest.html" ); - assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + assertThat( generatedFile ).exists(); File options = new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/options"); - FileUtils.fileRead( options ).contains( "junit-3.8.1.jar" ); + assertThat( FileUtils.fileRead( options ) ).contains( "junit-3.8.1.jar" ); } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/options/io/xpp3/JavadocOptionsXpp3ReaderTest.java b/src/test/java/org/apache/maven/plugins/javadoc/options/io/xpp3/JavadocOptionsXpp3ReaderTest.java index 1966492e..118b26ad 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/options/io/xpp3/JavadocOptionsXpp3ReaderTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/options/io/xpp3/JavadocOptionsXpp3ReaderTest.java @@ -19,14 +19,14 @@ * under the License. */ -import static org.junit.Assert.assertEquals; - import java.io.StringReader; import org.apache.maven.plugins.javadoc.options.JavadocOptions; import org.apache.maven.plugins.javadoc.options.Tag; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class JavadocOptionsXpp3ReaderTest { @@ -37,10 +37,10 @@ public void testNameAndHead() throws Exception { StringReader reader = new StringReader(testString); JavadocOptions options = parser.read(reader); - assertEquals(1, options.getTags().size()); + assertThat( options.getTags().size() ).isEqualTo( 1 ); Tag tag = options.getTags().get(0); - assertEquals("foo", tag.getName()); - assertEquals("bar", tag.getHead()); + assertThat( tag.getName() ).isEqualTo( "foo" ); + assertThat( tag.getHead() ).isEqualTo( "bar" ); } @Test @@ -50,10 +50,10 @@ public void testPlacement() throws Exception { StringReader reader = new StringReader(testString); JavadocOptions options = parser.read(reader); - assertEquals(1, options.getTags().size()); + assertThat( options.getTags().size() ).isEqualTo( 1 ); Tag tag = options.getTags().get(0); - assertEquals("foo", tag.getName()); - assertEquals("Xaoptcmf", tag.getPlacement()); + assertThat( tag.getName() ).isEqualTo( "foo" ); + assertThat( tag.getPlacement() ).isEqualTo( "Xaoptcmf" ); } } diff --git a/src/test/resources/unit/default-configuration/def/configuration/App.java b/src/test/resources/unit/default-configuration/def/configuration/App.java index b7ab0b2d..4bf85360 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/App.java +++ b/src/test/resources/unit/default-configuration/def/configuration/App.java @@ -22,6 +22,9 @@ public class App { + @Deprecated + public int notUsed = 0; + public static void main( String[] args ) { System.out.println( "Sample Application." ); diff --git a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java index 411094cc..6f047094 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java +++ b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java @@ -26,7 +26,7 @@ */ public class AppSample { - + public static final String CONST = "My Constant"; /** * The main method *