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 3fe51f4 commit 5c591a8
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 139 deletions.
10 changes: 2 additions & 8 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,10 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<groupId>junit</groupId>
<artifactId>junit</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
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 @@ -55,17 +51,17 @@ public abstract class AbstractJxrTestCase extends AbstractMojoTestCase {
*/
private MavenProject testMavenProject;

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@
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:oching@apache.org">Maria Odea Ching</a>
* @author <a href="mailto:dennisl@apache.org">Dennis Lundberg</a>
*/
class JxrReportTest extends AbstractJxrTestCase {
public class JxrReportTest extends AbstractJxrTestCase {
/**
* Test the plugin with original configuration
*
* @throws Exception
*/
@Test
void defaultConfiguration() throws Exception {
public void testDefaultConfiguration() 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 @@ -74,9 +69,10 @@ void defaultConfiguration() throws Exception {

/**
* Test the plugin with jdk-4 configuration
*
* @throws Exception
*/
@Test
void jdk4Configuration() throws Exception {
public void testJdk4Configuration() 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 @@ -110,9 +106,10 @@ void jdk4Configuration() throws Exception {

/**
* Test the plugin with jdk-6 configuration
*
* @throws Exception
*/
@Test
void jdk6Configuration() throws Exception {
public void testJdk6Configuration() 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 @@ -146,9 +143,10 @@ void jdk6Configuration() throws Exception {

/**
* Test the plugin with jdk-7 configuration
*
* @throws Exception
*/
@Test
void jdk7Configuration() throws Exception {
public void testJdk7Configuration() 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 @@ -186,9 +184,10 @@ void jdk7Configuration() throws Exception {

/**
* Test the plugin with jdk-8 configuration
*
* @throws Exception
*/
@Test
void jdk8Configuration() throws Exception {
public void testJdk8Configuration() 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 @@ -222,9 +221,10 @@ void jdk8Configuration() throws Exception {

/**
* Test when javadocLink is disabled in the configuration
*
* @throws Exception
*/
@Test
void noJavadocLink() throws Exception {
public void testNoJavadocLink() 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,23 +246,24 @@ void noJavadocLink() throws Exception {
// check if there's a link to the javadoc files
String str = readFile(xrefDir, "nojavadoclink/configuration/AppSample.html");
assertEquals(
-1, str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""));
str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""), -1);

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

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

// 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
*/
@Test
void aggregate() throws Exception {
public void testAggregate() 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 @@ -282,9 +283,10 @@ void aggregate() throws Exception {

/**
* Method for testing plugin when the specified javadocDir does not exist
*
* @throws Exception
*/
@Test
void noJavadocDir() throws Exception {
public void testNoJavadocDir() 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 @@ -299,9 +301,10 @@ void noJavadocDir() throws Exception {

/**
* Test the plugin with an exclude configuration.
*
* @throws Exception
*/
@Test
void exclude() throws Exception {
public void testExclude() 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 @@ -315,9 +318,10 @@ void exclude() throws Exception {

/**
* Test the plugin with an include configuration.
*
* @throws Exception
*/
@Test
void include() throws Exception {
public void testInclude() 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 @@ -329,8 +333,7 @@ void include() throws Exception {
assertFalse(Files.exists(xrefDir.resolve("include/configuration/AppSample.html")));
}

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

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

/**
* Test the jxr for a POM project.
*
* @throws Exception
*/
@Test
void pom() throws Exception {
public void testPom() 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,20 +20,16 @@

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:oching@apache.org">Maria Odea Ching</a>
*/
class JxrTestReportTest extends AbstractJxrTestCase {
public class JxrTestReportTest extends AbstractJxrTestCase {
/**
* Method to test when the source dir is the test source dir
*
* @throws Exception
*/
@Test
void sourceDir() throws Exception {
public void testSourceDir() 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 = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
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 = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
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 = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
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 = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
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:oching@apache.org">Maria Odea Ching</a>
*/
public class NoJavadocDirMavenProjectStub extends JxrProjectStub {
private final List<ReportPlugin> reportPlugins;
private List<ReportPlugin> reportPlugins;

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

try (InputStream is = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
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 = Files.newInputStream(new File(getBasedir() + "/" + getPOM()).toPath())) {
try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
model = pomReader.read(is);
setModel(model);
} catch (Exception ignored) {
Expand Down
Loading

0 comments on commit 5c591a8

Please sign in to comment.