Skip to content

Commit

Permalink
[JXR-195] Convert tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Dec 24, 2024
1 parent ab8c5aa commit 16b39d5
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 142 deletions.
17 changes: 14 additions & 3 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,19 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -209,7 +220,7 @@ under the License.
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredDependencies>junit:junit:*,org.apache.maven:maven-compat:*,org.apache.maven.resolver:maven-resolver-connector-basic:*,org.apache.maven.resolver:maven-resolver-transport-wagon:*,org.apache.maven.wagon:wagon-http-lightweight:*</ignoredDependencies>
<ignoredDependencies>org.apache.maven:maven-compat:*,org.apache.maven.resolver:maven-resolver-connector-basic:*,org.apache.maven.resolver:maven-resolver-transport-wagon:*,org.apache.maven.wagon:wagon-http-lightweight:*,org.junit.vintage:*,org.slf4j:slf4j-simple</ignoredDependencies>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Abstract class to test reports generation.
Expand All @@ -51,17 +55,17 @@ public abstract class AbstractJxrTestCase extends AbstractMojoTestCase {
*/
private MavenProject testMavenProject;

@Override
protected void setUp() throws Exception {
@BeforeEach
public void setUp() throws Exception {
// required for mojo lookups to work
super.setUp();

artifactStubFactory = new DependencyArtifactStubFactory(getTestFile("target"), true, false);
artifactStubFactory.getWorkingDir().mkdirs();
}

@Override
protected void tearDown() throws Exception {
@AfterEach
public void tearDown() throws Exception {
super.tearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
import java.util.Locale;

import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
* @author <a href="mailto:[email protected]">Dennis Lundberg</a>
*/
public class JxrReportTest extends AbstractJxrTestCase {
class JxrReportTest extends AbstractJxrTestCase {
/**
* Test the plugin with original configuration
*
* @throws Exception
*/
public void testDefaultConfiguration() throws Exception {
@Test
void defaultConfiguration() throws Exception {
File resourcesDir = new File(getBasedir(), "src/test/resources/unit/default-configuration");

File outputDir = new File(getBasedir(), "target/test/unit/default-configuration/target/site");
Expand Down Expand Up @@ -69,10 +74,9 @@ public void testDefaultConfiguration() throws Exception {

/**
* Test the plugin with jdk-4 configuration
*
* @throws Exception
*/
public void testJdk4Configuration() throws Exception {
@Test
void jdk4Configuration() throws Exception {
File resourcesDir = new File(getBasedir(), "src/test/resources/unit/default-configuration");

File outputDir = new File(getBasedir(), "target/test/unit/default-configuration/target/site/4");
Expand Down Expand Up @@ -106,10 +110,9 @@ public void testJdk4Configuration() throws Exception {

/**
* Test the plugin with jdk-6 configuration
*
* @throws Exception
*/
public void testJdk6Configuration() throws Exception {
@Test
void jdk6Configuration() throws Exception {
File resourcesDir = new File(getBasedir(), "src/test/resources/unit/default-configuration");

File outputDir = new File(getBasedir(), "target/test/unit/default-configuration/target/site/6");
Expand Down Expand Up @@ -143,10 +146,9 @@ public void testJdk6Configuration() throws Exception {

/**
* Test the plugin with jdk-7 configuration
*
* @throws Exception
*/
public void testJdk7Configuration() throws Exception {
@Test
void jdk7Configuration() throws Exception {
File resourcesDir = new File(getBasedir(), "src/test/resources/unit/default-configuration");

File outputDir = new File(getBasedir(), "target/test/unit/default-configuration/target/site/7");
Expand Down Expand Up @@ -184,10 +186,9 @@ public void testJdk7Configuration() throws Exception {

/**
* Test the plugin with jdk-8 configuration
*
* @throws Exception
*/
public void testJdk8Configuration() throws Exception {
@Test
void jdk8Configuration() throws Exception {
File resourcesDir = new File(getBasedir(), "src/test/resources/unit/default-configuration");

File outputDir = new File(getBasedir(), "target/test/unit/default-configuration/target/site/8");
Expand Down Expand Up @@ -221,10 +222,9 @@ public void testJdk8Configuration() throws Exception {

/**
* Test when javadocLink is disabled in the configuration
*
* @throws Exception
*/
public void testNoJavadocLink() throws Exception {
@Test
void noJavadocLink() throws Exception {
generateReport(getGoal(), "nojavadoclink-configuration/nojavadoclink-configuration-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/nojavadoclink-configuration/target/site/xref");
Expand All @@ -246,24 +246,23 @@ public void testNoJavadocLink() throws Exception {
// check if there's a link to the javadoc files
String str = readFile(xrefDir, "nojavadoclink/configuration/AppSample.html");
assertEquals(
str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""), -1);
-1, str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""));

str = readFile(xrefDir, "nojavadoclink/configuration/App.html");
assertEquals(str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/app.html\""), -1);
assertEquals(-1, str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/app.html\""));

str = readFile(xrefDir, "nojavadoclink/configuration/sample/Sample.html");
assertEquals(str.toLowerCase().indexOf("/apidocs/nojavadoclink/configuration/sample/sample.html\""), -1);
assertEquals(-1, str.toLowerCase().indexOf("/apidocs/nojavadoclink/configuration/sample/sample.html\""));

// check if encoding is ISO-8859-1, like specified in the plugin configuration
assertTrue(str.contains("text/html; charset=ISO-8859-1"));
}

/**
* Method for testing plugin when aggregate parameter is set to true
*
* @throws Exception
*/
public void testAggregate() throws Exception {
@Test
void aggregate() throws Exception {
generateReport(getGoal(), "aggregate-test/aggregate-test-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/aggregate-test/target/site/xref");
Expand All @@ -283,10 +282,9 @@ public void testAggregate() throws Exception {

/**
* Method for testing plugin when the specified javadocDir does not exist
*
* @throws Exception
*/
public void testNoJavadocDir() throws Exception {
@Test
void noJavadocDir() throws Exception {
generateReport(getGoal(), "nojavadocdir-test/nojavadocdir-test-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/nojavadocdir-test/target/site/xref");
Expand All @@ -301,10 +299,9 @@ public void testNoJavadocDir() throws Exception {

/**
* Test the plugin with an exclude configuration.
*
* @throws Exception
*/
public void testExclude() throws Exception {
@Test
void exclude() throws Exception {
generateReport(getGoal(), "exclude-configuration/exclude-configuration-plugin-config.xml");

Path xrefDir = new File(getBasedir(), "target/test/unit/exclude-configuration/target/site/xref").toPath();
Expand All @@ -318,10 +315,9 @@ public void testExclude() throws Exception {

/**
* Test the plugin with an include configuration.
*
* @throws Exception
*/
public void testInclude() throws Exception {
@Test
void include() throws Exception {
generateReport(getGoal(), "include-configuration/include-configuration-plugin-config.xml");

Path xrefDir = new File(getBasedir(), "target/test/unit/include-configuration/target/site/xref").toPath();
Expand All @@ -333,7 +329,8 @@ public void testInclude() throws Exception {
assertFalse(Files.exists(xrefDir.resolve("include/configuration/AppSample.html")));
}

public void testExceptions() {
@Test
void exceptions() {
try {
generateReport(getGoal(), "default-configuration/exception-test-plugin-config.xml");

Expand All @@ -345,10 +342,9 @@ public void testExceptions() {

/**
* Test the jxr for a POM project.
*
* @throws Exception
*/
public void testPom() throws Exception {
@Test
void pom() throws Exception {
generateReport(getGoal(), "pom-test/pom-test-plugin-config.xml");

assertFalse(new File(getBasedir(), "target/test/unit/pom-test").exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@

import java.io.File;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
*/
public class JxrTestReportTest extends AbstractJxrTestCase {
class JxrTestReportTest extends AbstractJxrTestCase {
/**
* Method to test when the source dir is the test source dir
*
* @throws Exception
*/
public void testSourceDir() throws Exception {
@Test
void sourceDir() throws Exception {
generateReport(getGoal(), "testsourcedir-test/testsourcedir-test-plugin-config.xml");

File xrefTestDir = new File(getBasedir(), "target/test/unit/testsourcedir-test/target/site/xref-test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +39,7 @@ public AggregateTestMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +39,7 @@ public DefaultConfigurationMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +39,7 @@ public ExcludeConfigurationMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +39,7 @@ public IncludeConfigurationMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -33,13 +33,13 @@
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
*/
public class NoJavadocDirMavenProjectStub extends JxrProjectStub {
private List<ReportPlugin> reportPlugins;
private final List<ReportPlugin> reportPlugins;

public NoJavadocDirMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.maven.plugin.jxr.stubs;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -39,7 +39,7 @@ public NoJavadocLinkConfigurationMavenProjectStub() {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;

try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Loading

0 comments on commit 16b39d5

Please sign in to comment.