Skip to content

Commit

Permalink
[SUREFIRE-2161] Align Mojo class names and output names
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Aug 21, 2024
1 parent c0784ab commit 5e14d4f
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
* Abstract base class for running tests using Surefire.
*
* @author Stephen Connolly
* @version $Id: SurefirePlugin.java 945065 2010-05-17 10:26:22Z stephenc $
*/
public abstract class AbstractSurefireMojo extends AbstractMojo implements SurefireExecutionParameters {
private static final Map<String, String> JAVA_9_MATCHER_OLD_NOTATION = singletonMap("version", "[1.9,)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
defaultPhase = LifecyclePhase.TEST,
threadSafe = true,
requiresDependencyResolution = ResolutionScope.TEST)
public class SurefirePlugin extends AbstractSurefireMojo implements SurefireReportParameters {
public class SurefireMojo extends AbstractSurefireMojo implements SurefireReportParameters {

/**
* The directory containing generated classes of the project being tested. This will be included after the test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@
/**
*
*/
public class SurefirePluginTest extends TestCase {
public class SurefireMojoTest extends TestCase {
@Rule
public final ExpectedException e = ExpectedException.none();

public void testDefaultIncludes() {
assertThat(new SurefirePlugin().getDefaultIncludes())
assertThat(new SurefireMojo().getDefaultIncludes())
.containsOnly("**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java");
}

public void testReportSchemaLocation() {
assertThat(new SurefirePlugin().getReportSchemaLocation())
assertThat(new SurefireMojo().getReportSchemaLocation())
.isEqualTo("https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd");
}

public void testFailIfNoTests() throws Exception {
RunResult runResult = new RunResult(0, 0, 0, 0);
try {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailIfNoTests(true);
plugin.handleSummary(runResult, null);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailIfNoTests(true);
mojo.handleSummary(runResult, null);
} catch (MojoFailureException e) {
assertThat(e.getLocalizedMessage())
.isEqualTo("No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)");
Expand All @@ -63,8 +63,8 @@ public void testFailIfNoTests() throws Exception {
public void testTestFailure() throws Exception {
RunResult runResult = new RunResult(1, 0, 1, 0);
try {
SurefirePlugin plugin = new SurefirePlugin();
plugin.handleSummary(runResult, null);
SurefireMojo mojo = new SurefireMojo();
mojo.handleSummary(runResult, null);
} catch (MojoFailureException e) {
assertThat(e.getLocalizedMessage())
.isEqualTo("There are test failures.\n\nPlease refer to null "
Expand All @@ -79,47 +79,47 @@ public void testTestFailure() throws Exception {
}

public void testPluginName() {
assertThat(new SurefirePlugin().getPluginName()).isEqualTo("surefire");
assertThat(new SurefireMojo().getPluginName()).isEqualTo("surefire");
}

public void testShouldGetNullEnv() {
SurefirePlugin plugin = new SurefirePlugin();
assertThat(plugin.getExcludedEnvironmentVariables()).hasSize(0);
SurefireMojo mojo = new SurefireMojo();
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(0);
}

public void testShouldGetEnv() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
assertThat(plugin.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
SurefireMojo mojo = new SurefireMojo();
mojo.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
}

public void testShouldGetPropertyFile() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
assertThat(plugin.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
SurefireMojo mojo = new SurefireMojo();
mojo.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
assertThat(mojo.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
}

public void testNegativeFailOnFlakeCount() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailOnFlakeCount(-1);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailOnFlakeCount(-1);
e.expect(MojoFailureException.class);
e.expectMessage("Parameter \"failOnFlakeCount\" should not be negative.");
}

public void testFailOnFlakeCountWithoutRerun() {
SurefirePlugin plugin = new SurefirePlugin();
plugin.setFailOnFlakeCount(1);
SurefireMojo mojo = new SurefireMojo();
mojo.setFailOnFlakeCount(1);
e.expect(MojoFailureException.class);
e.expectMessage("\"failOnFlakeCount\" requires rerunFailingTestsCount to be at least 1.");
}

public void testShouldHaveJUnit5EnginesFilter() {
SurefirePlugin plugin = new SurefirePlugin();
SurefireMojo mojo = new SurefireMojo();

plugin.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(plugin.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
mojo.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});

plugin.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(plugin.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
mojo.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
assertThat(mojo.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*
* @author Stephen Connolly
*/
public abstract class AbstractSurefireReportMojo extends AbstractMavenReport {
public abstract class AbstractSurefireReport extends AbstractMavenReport {

/**
* If set to false, only failures are shown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
*/
@Mojo(name = "failsafe-report-only")
@SuppressWarnings("unused")
public class FailsafeReportMojo extends AbstractSurefireReportMojo {
public class FailsafeOnlyReport extends AbstractSurefireReport {

/**
* The filename to use for the report.
*/
@Parameter(defaultValue = "failsafe-report", property = "outputName", required = true)
@Parameter(defaultValue = "failsafe", property = "outputName", required = true)
private String outputName;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
@Mojo(name = "report-only")
@Execute(phase = LifecyclePhase.NONE)
@SuppressWarnings("unused")
public class SurefireReportOnlyMojo extends SurefireReportMojo {}
public class SurefireOnlyReport extends SurefireReport {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
@Mojo(name = "report", inheritByDefault = false)
@Execute(lifecycle = "surefire", phase = LifecyclePhase.TEST)
@SuppressWarnings("unused")
public class SurefireReportMojo extends AbstractSurefireReportMojo {
public class SurefireReport extends AbstractSurefireReport {

/**
* The filename to use for the report.
*/
@Parameter(defaultValue = "surefire-report", property = "outputName", required = true)
@Parameter(defaultValue = "surefire", property = "outputName", required = true)
private String outputName;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Changing the Report Name

In order to configure the file name of the generated report (which is
"<surefire-report>" by default), the <<outputName>> property should
"<<<surefire>>>" by default), the <<<outputName>>> property should
be set to the desired name.

+----+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new JUnit4TestAdapter(Surefire597Test.class));
suite.addTest(new JUnit4TestAdapter(SurefireSchemaValidationTest.class));
suite.addTestSuite(SurefireReportMojoTest.class);
suite.addTestSuite(SurefireReportTest.class);
return suite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
*/
@SuppressWarnings("checkstyle:linelength")
public class SurefireReportMojoTest extends AbstractMojoTestCase {
public class SurefireReportTest extends AbstractMojoTestCase {
private ArtifactStubFactory artifactStubFactory;

// Can be removed with Doxia 2.0.0
Expand All @@ -64,8 +64,8 @@ protected void tearDown() throws Exception {
super.tearDown();
}

protected SurefireReportMojo createReportMojo(File pluginXmlFile) throws Exception {
SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo("report", pluginXmlFile);
protected SurefireReport createReportMojo(File pluginXmlFile) throws Exception {
SurefireReport mojo = (SurefireReport) lookupMojo("report", pluginXmlFile);
assertNotNull("Mojo found.", mojo);

LegacySupport legacySupport = lookup(LegacySupport.class);
Expand All @@ -82,7 +82,7 @@ protected SurefireReportMojo createReportMojo(File pluginXmlFile) throws Excepti

public void testBasicSurefireReport() throws Exception {
File testPom = new File(getUnitBaseDir(), "basic-surefire-report-test/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
File reportsDir = (File) getVariableValueFromObject(mojo, "reportsDirectory");
Expand All @@ -96,14 +96,14 @@ public void testBasicSurefireReport() throws Exception {
new File(getBasedir() + "/src/test/resources/unit/basic-surefire-report-test/surefire-reports")
.getAbsolutePath(),
reportsDir.getAbsolutePath());
assertEquals("surefire-report", outputName);
assertEquals("surefire", outputName);
assertEquals(
new File(getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test").getAbsolutePath(),
xrefLocation.getAbsolutePath());
assertTrue(linkXRef);

mojo.execute();
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-test/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-test/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand All @@ -119,12 +119,11 @@ private File getUnitBaseDir() throws UnsupportedEncodingException {

public void testBasicSurefireReportIfShowSuccessIsFalse() throws Exception {
File testPom = new File(getUnitBaseDir(), "basic-surefire-report-success-false/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
boolean showSuccess = (Boolean) getVariableValueFromObject(mojo, "showSuccess");
assertFalse(showSuccess);
mojo.execute();
File report =
new File(getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand All @@ -134,12 +133,11 @@ public void testBasicSurefireReportIfShowSuccessIsFalse() throws Exception {

public void testBasicSurefireReportIfLinkXrefIsFalse() throws Exception {
File testPom = new File(getUnitBaseDir(), "basic-surefire-report-linkxref-false/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
boolean linkXRef = (Boolean) getVariableValueFromObject(mojo, "linkXRef");
assertFalse(linkXRef);
mojo.execute();
File report =
new File(getBasedir(), "target/site/unit/basic-surefire-report-linkxref-false/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-linkxref-false/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand All @@ -149,10 +147,9 @@ public void testBasicSurefireReportIfLinkXrefIsFalse() throws Exception {

public void testBasicSurefireReportIfReportingIsNull() throws Exception {
File testPom = new File(getUnitBaseDir(), "basic-surefire-report-reporting-null/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report =
new File(getBasedir(), "target/site/unit/basic-surefire-report-reporting-null/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-reporting-null/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand All @@ -163,10 +160,9 @@ public void testBasicSurefireReportIfReportingIsNull() throws Exception {
@SuppressWarnings("checkstyle:methodname")
public void testBasicSurefireReport_AnchorTestCases() throws Exception {
File testPom = new File(getUnitBaseDir(), "basic-surefire-report-anchor-test-cases/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report =
new File(getBasedir(), "target/site/unit/basic-surefire-report-anchor-test-cases/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/basic-surefire-report-anchor-test-cases/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand All @@ -180,9 +176,9 @@ public void testBasicSurefireReport_AnchorTestCases() throws Exception {

public void testSurefireReportSingleError() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-report-single-error/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report = new File(getBasedir(), "target/site/unit/surefire-report-single-error/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/surefire-report-single-error/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand Down Expand Up @@ -267,10 +263,10 @@ public void testSurefireReportSingleError() throws Exception {

public void testSurefireReportNestedClassTrimStackTrace() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-report-nestedClass-trimStackTrace/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report = new File(
getBasedir(), "target/site/unit/surefire-report-nestedClass-trimStackTrace/surefire-report.html");
File report =
new File(getBasedir(), "target/site/unit/surefire-report-nestedClass-trimStackTrace/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand Down Expand Up @@ -331,9 +327,9 @@ public void testSurefireReportNestedClassTrimStackTrace() throws Exception {

public void testSurefireReportNestedClass() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-report-nestedClass/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report = new File(getBasedir(), "target/site/unit/surefire-report-nestedClass/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/surefire-report-nestedClass/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand Down Expand Up @@ -418,10 +414,9 @@ public void testSurefireReportNestedClass() throws Exception {

public void testSurefireReportEnclosedTrimStackTrace() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-report-enclosed-trimStackTrace/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report =
new File(getBasedir(), "target/site/unit/surefire-report-enclosed-trimStackTrace/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/surefire-report-enclosed-trimStackTrace/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand Down Expand Up @@ -482,9 +477,9 @@ public void testSurefireReportEnclosedTrimStackTrace() throws Exception {

public void testSurefireReportEnclosed() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-report-enclosed/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);
mojo.execute();
File report = new File(getBasedir(), "target/site/unit/surefire-report-enclosed/surefire-report.html");
File report = new File(getBasedir(), "target/site/unit/surefire-report-enclosed/surefire.html");
assertTrue(report.exists());
String htmlContent = FileUtils.fileRead(report);

Expand Down Expand Up @@ -579,7 +574,7 @@ public void testSurefireReportEnclosed() throws Exception {

public void testCustomTitleAndDescriptionReport() throws Exception {
File testPom = new File(getUnitBaseDir(), "surefire-1183/plugin-config.xml");
SurefireReportMojo mojo = createReportMojo(testPom);
SurefireReport mojo = createReportMojo(testPom);

File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
String outputName = (String) getVariableValueFromObject(mojo, "outputName");
Expand All @@ -590,11 +585,11 @@ public void testCustomTitleAndDescriptionReport() throws Exception {
new File(getBasedir() + "/src/test/resources/unit/surefire-1183/acceptancetest-reports")
.getAbsolutePath(),
reportsDir.getAbsolutePath());
assertEquals("acceptance-test-report", outputName);
assertEquals("acceptance-test", outputName);

mojo.execute();

File report = new File(getBasedir(), "target/site/unit/surefire-1183/acceptance-test-report.html");
File report = new File(getBasedir(), "target/site/unit/surefire-1183/acceptance-test.html");

assertTrue(report.exists());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
*/
public class SurefireRepMavenProjectStub extends MavenProjectStub {
public class SurefireReportMavenProjectStub extends MavenProjectStub {
/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
*/
public class SurefireRepMavenProjectStub2 extends MavenProjectStub {
public class SurefireReportMavenProjectStub2 extends MavenProjectStub {
/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit 5e14d4f

Please sign in to comment.