This is an automated email from the ASF dual-hosted git repository.

sparsick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 3936a4d  chore: migration AbstractMojoTestcase based tests to using 
MojoTest (#645)
3936a4d is described below

commit 3936a4d4497252aa16c7d21225902905d11d29d3
Author: Sandra Parsick <[email protected]>
AuthorDate: Tue Nov 11 07:22:43 2025 +0000

    chore: migration AbstractMojoTestcase based tests to using MojoTest (#645)
    
    * chore: migrate junit3/4 to junit 5
    
    AbstractMojoTestCase based test will be migrate in a seperate PR
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: inline class
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: inline method
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: inline method
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore (wip): migrate to mojotest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * Prepare real Maven session
    
    * Spotless
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: inline method, clean up unused code
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: migrate to mojotest - CeckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * chore: spottless
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: clean up CheckstyleReportTest
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: spotless
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    * refactor: code review feedback
    
    Signed-off-by: Sandra Parsick <[email protected]>
    
    ---------
    
    Signed-off-by: Sandra Parsick <[email protected]>
    Co-authored-by: Slawomir Jaranowski <[email protected]>
---
 pom.xml                                            |   1 +
 .../checkstyle/AbstractCheckstyleTestCase.java     | 172 ---------------
 .../plugins/checkstyle/CheckstyleReportTest.java   | 235 ++++++++++++++++-----
 .../CheckstyleViolationCheckMojoTest.java          | 171 ++++++---------
 .../checkstyle/exec/CheckstyleExecutorTest.java    |  17 +-
 .../src/test/test-sources/README.txt               |   1 +
 6 files changed, 269 insertions(+), 328 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1444cd1..f7d63be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -213,6 +213,7 @@ under the License.
       <artifactId>junit-jupiter-api</artifactId>
       <scope>test</scope>
     </dependency>
+    <!-- is needed because of MavenProjectStub-->
     <dependency>
       <groupId>org.junit.vintage</groupId>
       <artifactId>junit-vintage-engine</artifactId>
diff --git 
a/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
 
b/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
deleted file mode 100644
index a0b2380..0000000
--- 
a/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.plugins.checkstyle;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.LegacySupport;
-import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.descriptor.MojoDescriptor;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugin.testing.ArtifactStubFactory;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuilder;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.junit.jupiter.api.Assertions;
-
-/**
- * Abstract class to test reports generation.
- */
-public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
-    private ArtifactStubFactory artifactStubFactory;
-
-    /**
-     * The project to test.
-     */
-    private MavenProject testMavenProject;
-
-    public void setUp() throws Exception {
-        // required for mojo lookups to work
-        super.setUp();
-
-        artifactStubFactory = new 
DependencyArtifactStubFactory(getTestFile("target"), true, false);
-        artifactStubFactory.getWorkingDir().mkdirs();
-    }
-
-    /**
-     * Get the current Maven project
-     *
-     * @return the maven project
-     */
-    protected MavenProject getTestMavenProject() {
-        return testMavenProject;
-    }
-
-    /**
-     * Get the generated report as file in the test maven project.
-     *
-     * @param name the name of the report
-     * @return the generated report as file
-     * @throws IOException if the return file doesn't exist
-     */
-    protected File getGeneratedReport(String name) throws IOException {
-        String outputDirectory = getBasedir() + "/target/test/test-harness/"
-                + getTestMavenProject().getArtifactId();
-
-        File report = new File(outputDirectory, name);
-        if (!report.exists()) {
-            throw new IOException("File not found. Attempted: " + report);
-        }
-
-        return report;
-    }
-
-    /**
-     * Generate the report and return the generated file
-     *
-     * @param goal the mojo goal.
-     * @param pluginXml the name of the XML file in 
"src/test/resources/plugin-configs/"
-     * @return the generated HTML file
-     * @throws Exception if any
-     */
-    protected File generateReport(String goal, String pluginXml) throws 
Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/" + pluginXml);
-        CheckstyleReport mojo = createReportMojo(goal, pluginXmlFile);
-        return generateReport(mojo, pluginXmlFile);
-    }
-
-    protected CheckstyleReport createReportMojo(String goal, File 
pluginXmlFile) throws Exception {
-        CheckstyleReport mojo = (CheckstyleReport) lookupMojo(goal, 
pluginXmlFile);
-        Assertions.assertNotNull(mojo, "Mojo not found.");
-
-        LegacySupport legacySupport = lookup(LegacySupport.class);
-        legacySupport.setSession(newMavenSession(new MavenProjectStub()));
-        DefaultRepositorySystemSession repoSession =
-                (DefaultRepositorySystemSession) 
legacySupport.getRepositorySession();
-        repoSession.setLocalRepositoryManager(new 
SimpleLocalRepositoryManagerFactory()
-                .newInstance(repoSession, new 
LocalRepository(artifactStubFactory.getWorkingDir())));
-
-        List<MavenProject> reactorProjects =
-                mojo.getReactorProjects() != null ? mojo.getReactorProjects() 
: Collections.emptyList();
-
-        setVariableValueToObject(mojo, "mojoExecution", 
getMockMojoExecution());
-        setVariableValueToObject(mojo, "session", legacySupport.getSession());
-        setVariableValueToObject(mojo, "repoSession", 
legacySupport.getRepositorySession());
-        setVariableValueToObject(mojo, "reactorProjects", reactorProjects);
-        setVariableValueToObject(
-                mojo, "remoteProjectRepositories", 
mojo.getProject().getRemoteProjectRepositories());
-        setVariableValueToObject(
-                mojo, "siteDirectory", new 
File(mojo.getProject().getBasedir(), "src/site"));
-        return mojo;
-    }
-
-    protected File generateReport(CheckstyleReport mojo, File pluginXmlFile) 
throws Exception {
-        mojo.execute();
-
-        ProjectBuilder builder = lookup(ProjectBuilder.class);
-
-        ProjectBuildingRequest buildingRequest = new 
DefaultProjectBuildingRequest();
-        
buildingRequest.setRepositorySession(lookup(LegacySupport.class).getRepositorySession());
-
-        testMavenProject = builder.build(pluginXmlFile, 
buildingRequest).getProject();
-
-        File outputDir = mojo.getReportOutputDirectory();
-        String filename = mojo.getOutputName() + ".html";
-
-        File file = new File(outputDir, filename);
-
-        return file;
-    }
-
-    /**
-     * Read the contents of the specified file object into a string
-     */
-    protected String readFile(File checkstyleTestDir, String fileName) throws 
IOException {
-        return new 
String(Files.readAllBytes(checkstyleTestDir.toPath().resolve(fileName)));
-    }
-
-    private MojoExecution getMockMojoExecution() {
-        MojoDescriptor md = new MojoDescriptor();
-        md.setGoal(getGoal());
-
-        MojoExecution me = new MojoExecution(md);
-
-        PluginDescriptor pd = new PluginDescriptor();
-        Plugin p = new Plugin();
-        p.setGroupId("org.apache.maven.plugins");
-        p.setArtifactId("maven-checkstyle-plugin");
-        pd.setPlugin(p);
-        md.setPluginDescriptor(pd);
-
-        return me;
-    }
-
-    protected abstract String getGoal();
-}
diff --git 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
index a82bcc1..94e5211 100644
--- 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
@@ -18,61 +18,193 @@
  */
 package org.apache.maven.plugins.checkstyle;
 
+import javax.inject.Inject;
+
 import java.io.File;
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.util.Collections;
 import java.util.ResourceBundle;
 
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.tools.SiteTool;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static 
org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * @author Edwin Punzalan
  */
-public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
-    public void testNoSource() throws Exception {
-        File generatedReport = generateReport(getGoal(), 
"no-source-plugin-config.xml");
-        assertFalse(new File(generatedReport.getAbsolutePath()).exists());
+@MojoTest
+public class CheckstyleReportTest {
+
+    /**
+     * The project to test.
+     */
+    @Inject
+    private MavenProject testMavenProject;
+
+    @Inject
+    private MavenSession mavenSession;
+
+    @Inject
+    private DefaultRepositorySystemSessionFactory repoSessionFactory;
+
+    @Inject
+    private MojoExecution mojoExecution;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        // prepare realistic repository session
+        ArtifactRepository localRepo = Mockito.mock(ArtifactRepository.class);
+        Mockito.when(localRepo.getBasedir()).thenReturn(new File(getBasedir(), 
"target/local-repo").getAbsolutePath());
+
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        request.setLocalRepository(localRepo);
+
+        RemoteRepository centralRepo =
+                new RemoteRepository.Builder("central", "default", 
"https://repo.maven.apache.org/maven2";).build();
+
+        DefaultRepositorySystemSession systemSession = 
repoSessionFactory.newRepositorySession(request);
+        
Mockito.when(mavenSession.getRepositorySession()).thenReturn(systemSession);
+        Mockito.when(testMavenProject.getRemoteProjectRepositories())
+                .thenReturn(Collections.singletonList(centralRepo));
+
+        Mockito.when(mojoExecution.getPlugin()).thenReturn(new Plugin());
     }
 
-    public void testMinConfiguration() throws Exception {
-        generateReport("min-plugin-config.xml");
+    @InjectMojo(goal = "checkstyle", pom = 
"src/test/resources/plugin-configs/no-source-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testNoSource(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+
+        File outputDir = mojo.getReportOutputDirectory();
+        String filename = mojo.getOutputName() + ".html";
+        File generatedReport = new File(outputDir, filename);
+        assertFalse(new File(generatedReport.getAbsolutePath()).exists());
     }
 
-    public void testCustomConfiguration() throws Exception {
-        generateReport("custom-plugin-config.xml");
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "min-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testMinConfiguration(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+
+        assertGeneratedReport(mojo);
     }
 
-    public void testUseFile() throws Exception {
-        generateReport("useFile-plugin-config.xml");
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "custom-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testCustomConfiguration(CheckstyleReport mojo) throws 
Exception {
+        mojo.execute();
+
+        assertGeneratedReport(mojo);
+    }
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "useFile-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testUseFile(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+        assertGeneratedReport(mojo);
     }
 
-    public void testNoRulesSummary() throws Exception {
-        generateReport("no-rules-plugin-config.xml");
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "no-rules-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testNoRulesSummary(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+
+        assertGeneratedReport(mojo);
     }
 
-    public void testNoSeveritySummary() throws Exception {
-        generateReport("no-severity-plugin-config.xml");
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "no-severity-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testNoSeveritySummary(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+
+        assertGeneratedReport(mojo);
     }
 
-    public void testNoFilesSummary() throws Exception {
-        generateReport("no-files-plugin-config.xml");
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "no-files-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testNoFilesSummary(CheckstyleReport mojo) throws Exception {
+        mojo.execute();
+
+        assertGeneratedReport(mojo);
     }
 
-    public void testFailOnError() {
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = "fail-on-error-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    @Disabled // TODO the junit 3 version produce a false exception (see 
description in PR
+    // https://github.com/apache/maven-checkstyle-plugin/pull/645)
+    public void testFailOnError(CheckstyleReport mojo) {
         try {
-            generateReport("fail-on-error-plugin-config.xml");
-
+            mojo.execute();
+            assertGeneratedReport(mojo); // TODO if this necessary
             fail("Must throw exception on errors");
         } catch (Exception e) {
             assertNotNull(e.getMessage());
         }
     }
 
-    public void testDependencyResolutionException() {
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = 
"dep-resolution-exception-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testDependencyResolutionException(CheckstyleReport mojo) {
         try {
-            generateReport("dep-resolution-exception-plugin-config.xml");
+            mojo.execute();
 
             fail("Must throw exception on errors");
         } catch (Exception e) {
@@ -84,72 +216,73 @@ public class CheckstyleReportTest extends 
AbstractCheckstyleTestCase {
         }
     }
 
-    public void testTestSourceDirectory() throws Exception {
-        generateReport("test-source-directory-plugin-config.xml");
-    }
+    // We need to change the basedir to point to test repositor with out 
site.xml file
+    // without it test will use real project site.xml without skin 
configuration
+    @Basedir("/plugin-configs")
+    @InjectMojo(goal = "checkstyle", pom = 
"test-source-directory-plugin-config.xml")
+    @MojoParameter(name = "siteDirectory", value = "src/site")
+    @Test
+    public void testTestSourceDirectory(CheckstyleReport mojo) throws 
Exception {
+        mojo.execute();
 
-    private void generateReport(String pluginXml) throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/" + pluginXml);
-        ResourceBundle bundle =
-                ResourceBundle.getBundle("checkstyle-report", 
SiteTool.DEFAULT_LOCALE, this.getClassLoader());
-
-        CheckstyleReport mojo = createReportMojo(getGoal(), pluginXmlFile);
+        assertGeneratedReport(mojo);
+    }
 
-        PluginDescriptor descriptorStub = new PluginDescriptor();
-        descriptorStub.setGroupId("org.apache.maven.plugins");
-        descriptorStub.setArtifactId("maven-checkstyle-plugin");
-        setVariableValueToObject(mojo, "plugin", descriptorStub);
+    private void assertGeneratedReport(CheckstyleReport mojo) throws 
IllegalAccessException, IOException {
+        File outputDir = mojo.getReportOutputDirectory();
+        String filename = mojo.getOutputName() + ".html";
 
-        File generatedReport = generateReport(mojo, pluginXmlFile);
+        File generatedReport = new File(outputDir, filename);
         assertTrue(new File(generatedReport.getAbsolutePath()).exists());
 
         File outputFile = (File) getVariableValueFromObject(mojo, 
"outputFile");
-        assertNotNull("Test output file", outputFile);
-        assertTrue("Test output file exists", outputFile.exists());
+        assertNotNull(outputFile, "Test output file");
+        assertTrue(outputFile.exists(), "Test output file exists");
 
         String cacheFile = (String) getVariableValueFromObject(mojo, 
"cacheFile");
         if (cacheFile != null) {
-            assertTrue("Test cache file exists", new File(cacheFile).exists());
+            assertTrue(new File(cacheFile).exists(), "Test cache file exists");
         }
 
         File useFile = (File) getVariableValueFromObject(mojo, "useFile");
         if (useFile != null) {
-            assertTrue("Test useFile exists", useFile.exists());
+            assertTrue(useFile.exists(), "Test useFile exists");
         }
 
         String str = new String(Files.readAllBytes(generatedReport.toPath()), 
StandardCharsets.UTF_8);
 
+        ResourceBundle bundle =
+                ResourceBundle.getBundle("checkstyle-report", 
SiteTool.DEFAULT_LOCALE, getClassLoader());
         boolean searchHeaderFound = 
str.contains(getHtmlHeader(bundle.getString("report.checkstyle.rules")));
         Boolean rules = (Boolean) getVariableValueFromObject(mojo, 
"enableRulesSummary");
         if (rules) {
-            assertTrue("Test for Rules Summary", searchHeaderFound);
+            assertTrue(searchHeaderFound, "Test for Rules Summary");
         } else {
-            assertFalse("Test for Rules Summary", searchHeaderFound);
+            assertFalse(searchHeaderFound, "Test for Rules Summary");
         }
 
         searchHeaderFound = 
str.contains(getHtmlHeader(bundle.getString("report.checkstyle.summary")));
         Boolean severity = (Boolean) getVariableValueFromObject(mojo, 
"enableSeveritySummary");
         if (severity) {
-            assertTrue("Test for Severity Summary", searchHeaderFound);
+            assertTrue(searchHeaderFound, "Test for Severity Summary");
         } else {
-            assertFalse("Test for Severity Summary", searchHeaderFound);
+            assertFalse(searchHeaderFound, "Test for Severity Summary");
         }
 
         searchHeaderFound = 
str.contains(getHtmlHeader(bundle.getString("report.checkstyle.files")));
         Boolean files = (Boolean) getVariableValueFromObject(mojo, 
"enableFilesSummary");
         if (files) {
-            assertTrue("Test for Files Summary", searchHeaderFound);
+            assertTrue(searchHeaderFound, "Test for Files Summary");
         } else {
-            assertFalse("Test for Files Summary", searchHeaderFound);
+            assertFalse(searchHeaderFound, "Test for Files Summary");
         }
     }
 
-    private static String getHtmlHeader(String s) {
-        return ">" + s + "</h2>";
+    private ClassLoader getClassLoader() {
+        return this.getClass().getClassLoader();
     }
 
-    @Override
-    protected String getGoal() {
-        return "checkstyle";
+    private static String getHtmlHeader(String s) {
+        return ">" + s + "</h2>";
     }
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java
 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java
index 8ab8644..676a517 100644
--- 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java
@@ -18,33 +18,41 @@
  */
 package org.apache.maven.plugins.checkstyle;
 
-import java.io.File;
-import java.util.Arrays;
+import javax.inject.Inject;
 
-import org.apache.maven.model.Build;
-import org.apache.maven.plugin.Mojo;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * @author Edwin Punzalan
  *
  */
-public class CheckstyleViolationCheckMojoTest extends AbstractMojoTestCase {
-    public void testDefaultConfig() throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/check-plugin-config.xml");
-
-        CheckstyleViolationCheckMojo mojo = (CheckstyleViolationCheckMojo) 
lookupMojo("check", pluginXmlFile);
-
-        mojoSetup(mojo);
-
-        assertNotNull("Mojo not found.", mojo);
-
-        assertNotNull("project null.", mojo.project);
-
+@MojoTest
+public class CheckstyleViolationCheckMojoTest {
+
+    @Inject
+    private MavenProject project;
+
+    @Inject
+    private PluginDescriptor plugin;
+
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-config.xml")
+    @MojoParameter(name = "configLocation", value = "sun_checks.xml")
+    @MojoParameter(name = "cacheFile", value = 
"/target/classes/checkstyle-cachefile")
+    @MojoParameter(name = "sourceDirectories", value = 
"/src/test/plugin-configs/src")
+    @MojoParameter(name = "inputEncoding", value = "UTF-8")
+    @MojoParameter(name = "skipExec", value = "true")
+    @Test
+    public void testDefaultConfig(CheckstyleViolationCheckMojo mojo) throws 
Exception {
         try {
             mojo.execute();
 
@@ -54,17 +62,15 @@ public class CheckstyleViolationCheckMojoTest extends 
AbstractMojoTestCase {
         }
     }
 
-    public void testInvalidFormatWithSkipExec() throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/check-plugin-config.xml");
-
-        Mojo mojo = lookupMojo("check", pluginXmlFile);
-
-        assertNotNull("Mojo not found.", mojo);
-
-        mojoSetup(mojo);
-
-        setVariableValueToObject(mojo, "outputFileFormat", "plain");
-
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-config.xml")
+    @MojoParameter(name = "configLocation", value = "sun_checks.xml")
+    @MojoParameter(name = "cacheFile", value = 
"/target/classes/checkstyle-cachefile")
+    @MojoParameter(name = "sourceDirectories", value = 
"/src/test/plugin-configs/src")
+    @MojoParameter(name = "inputEncoding", value = "UTF-8")
+    @MojoParameter(name = "skipExec", value = "true")
+    @MojoParameter(name = "outputFileFormat", value = "plain")
+    @Test
+    public void testInvalidFormatWithSkipExec(CheckstyleViolationCheckMojo 
mojo) throws Exception {
         try {
             mojo.execute();
 
@@ -74,40 +80,24 @@ public class CheckstyleViolationCheckMojoTest extends 
AbstractMojoTestCase {
         }
     }
 
-    public void testNoOutputFile() throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/check-plugin-config.xml");
-
-        Mojo mojo = lookupMojo("check", pluginXmlFile);
-
-        assertNotNull("Mojo not found.", mojo);
-
-        mojoSetup(mojo);
-
-        setVariableValueToObject(mojo, "outputFile", new 
File("target/NoSuchFile.xml"));
-
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-config.xml")
+    @MojoParameter(name = "configLocation", value = "sun_checks.xml")
+    @MojoParameter(name = "cacheFile", value = 
"/target/classes/checkstyle-cachefile")
+    @MojoParameter(name = "sourceDirectories", value = 
"/src/test/plugin-configs/src")
+    @MojoParameter(name = "inputEncoding", value = "UTF-8")
+    @MojoParameter(name = "skipExec", value = "true")
+    @MojoParameter(name = "outputFile", value = "target/NoSuchFile.xml")
+    @Test
+    public void testNoOutputFile(CheckstyleViolationCheckMojo mojo) throws 
Exception {
         mojo.execute();
     }
 
-    private void doTestPlainOutputFile(boolean failsOnError) throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/check-plugin-plain-output.xml");
-
-        Mojo mojo = lookupMojo("check", pluginXmlFile);
-
-        assertNotNull("Mojo not found.", mojo);
-
-        PluginDescriptor descriptorStub = new PluginDescriptor();
-        descriptorStub.setGroupId("org.apache.maven.plugins");
-        descriptorStub.setArtifactId("maven-checkstyle-plugin");
-        setVariableValueToObject(mojo, "plugin", descriptorStub);
-
-        setVariableValueToObject(mojo, "failsOnError", failsOnError);
-
-        mojo.execute();
-    }
-
-    public void testPlainOutputFileFailOnError() throws Exception {
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-plain-output.xml")
+    @MojoParameter(name = "failsOnError", value = "true")
+    @Test
+    public void testPlainOutputFileFailOnError(CheckstyleViolationCheckMojo 
mojo) throws Exception {
         try {
-            doTestPlainOutputFile(true);
+            mojo.execute();
 
             fail("Must fail on violations");
         } catch (MojoExecutionException e) {
@@ -115,52 +105,31 @@ public class CheckstyleViolationCheckMojoTest extends 
AbstractMojoTestCase {
         }
     }
 
-    public void testPlainOutputFile() throws Exception {
-        doTestPlainOutputFile(false);
+    @Provides
+    public PluginDescriptor getPluginDescriptor() {
+        PluginDescriptor descriptorStub = new PluginDescriptor();
+        descriptorStub.setGroupId("org.apache.maven.plugins");
+        descriptorStub.setArtifactId("maven-checkstyle-plugin");
+        return descriptorStub;
     }
 
-    public void testNoFail() throws Exception {
-        File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/check-plugin-config.xml");
-
-        Mojo mojo = lookupMojo("check", pluginXmlFile);
-
-        assertNotNull("Mojo not found.", mojo);
-
-        mojoSetup(mojo);
-
-        setVariableValueToObject(mojo, "failOnViolation", Boolean.FALSE);
-
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-plain-output.xml")
+    @MojoParameter(name = "failsOnError", value = "false")
+    @MojoParameter(name = "failOnViolation", value = "false")
+    @Test
+    public void testPlainOutputFile(CheckstyleViolationCheckMojo mojo) throws 
Exception {
         mojo.execute();
     }
 
-    protected void mojoSetup(Mojo mojo) throws Exception {
-        // mojo setup
-
-        setVariableValueToObject(mojo, "project", new MavenProjectStub() {
-
-            public File getFile() {
-                return new File(getBasedir(), "target/classes");
-            }
-
-            public Build getBuild() {
-                return new Build() {
-                    private static final long serialVersionUID = 
-743084937617131258L;
-
-                    public String getDirectory() {
-                        return getBasedir() + "/target/classes";
-                    }
-                };
-            }
-        });
-
-        setVariableValueToObject(mojo, "configLocation", "sun_checks.xml");
-        setVariableValueToObject(mojo, "cacheFile", getBasedir() + 
"/target/classes/checkstyle-cachefile");
-        setVariableValueToObject(
-                mojo,
-                "sourceDirectories",
-                Arrays.asList(
-                        getBasedir() + "/src/test/plugin-configs/src")); // 
new File( getBasedir() + "/target" ) );
-        setVariableValueToObject(mojo, "inputEncoding", "UTF-8");
-        setVariableValueToObject(mojo, "skipExec", Boolean.TRUE);
+    @InjectMojo(goal = "check", pom = 
"src/test/resources/plugin-configs/check-plugin-config.xml")
+    @MojoParameter(name = "configLocation", value = "sun_checks.xml")
+    @MojoParameter(name = "cacheFile", value = 
"/target/classes/checkstyle-cachefile")
+    @MojoParameter(name = "sourceDirectories", value = 
"/src/test/plugin-configs/src")
+    @MojoParameter(name = "inputEncoding", value = "UTF-8")
+    @MojoParameter(name = "skipExec", value = "true")
+    @MojoParameter(name = "failOnViolation", value = "false")
+    @Test
+    public void testNoFail(CheckstyleViolationCheckMojo mojo) throws Exception 
{
+        mojo.execute();
     }
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleExecutorTest.java
 
b/src/test/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleExecutorTest.java
index b292309..9705c7d 100644
--- 
a/src/test/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleExecutorTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/checkstyle/exec/CheckstyleExecutorTest.java
@@ -18,11 +18,20 @@
  */
 package org.apache.maven.plugins.checkstyle.exec;
 
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import javax.inject.Inject;
 
-public class CheckstyleExecutorTest extends AbstractMojoTestCase {
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@MojoTest
+public class CheckstyleExecutorTest {
+    @Inject
+    private CheckstyleExecutor executor;
+
+    @Test
     public void testDefaultConfig() throws Exception {
-        CheckstyleExecutor executor = (CheckstyleExecutor) 
lookup(CheckstyleExecutor.class);
-        assertNotNull("project null.", executor);
+        assertNotNull(executor, "project null.");
     }
 }
diff --git a/src/test/resources/plugin-configs/src/test/test-sources/README.txt 
b/src/test/resources/plugin-configs/src/test/test-sources/README.txt
new file mode 100644
index 0000000..ba9f086
--- /dev/null
+++ b/src/test/resources/plugin-configs/src/test/test-sources/README.txt
@@ -0,0 +1 @@
+mock source repository - need for testing purposes
\ No newline at end of file


Reply via email to