Skip to content

Commit d2296e7

Browse files
committed
refactor: inline method
Signed-off-by: Sandra Parsick <[email protected]>
1 parent 764f3b2 commit d2296e7

File tree

2 files changed

+33
-45
lines changed

2 files changed

+33
-45
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ under the License.
226226
<dependency>
227227
<groupId>org.apache.maven.plugin-testing</groupId>
228228
<artifactId>maven-plugin-testing-harness</artifactId>
229-
<version>3.3.0</version>
229+
<version>3.4.0</version>
230230
<scope>test</scope>
231231
<exclusions>
232232
<exclusion>

src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
*/
1919
package org.apache.maven.plugins.checkstyle;
2020

21-
import java.io.File;
22-
import java.io.IOException;
23-
import java.nio.charset.StandardCharsets;
24-
import java.nio.file.Files;
25-
import java.util.Collections;
26-
import java.util.List;
27-
import java.util.ResourceBundle;
28-
2921
import org.apache.maven.artifact.DependencyResolutionRequiredException;
3022
import org.apache.maven.doxia.tools.SiteTool;
3123
import org.apache.maven.model.Plugin;
@@ -47,6 +39,14 @@
4739
import org.junit.jupiter.api.BeforeEach;
4840
import org.junit.jupiter.api.Test;
4941

42+
import java.io.File;
43+
import java.io.IOException;
44+
import java.nio.charset.StandardCharsets;
45+
import java.nio.file.Files;
46+
import java.util.Collections;
47+
import java.util.List;
48+
import java.util.ResourceBundle;
49+
5050
/**
5151
* @author Edwin Punzalan
5252
*/
@@ -69,7 +69,30 @@ public void setUp() throws Exception {
6969

7070
@Test
7171
public void testNoSource() throws Exception {
72-
File generatedReport = generateReport("checkstyle", "no-source-plugin-config.xml");
72+
File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + "no-source-plugin-config.xml");
73+
CheckstyleReport mojo1 = (CheckstyleReport) lookupMojo("checkstyle", pluginXmlFile);
74+
Assertions.assertNotNull(mojo1, "Mojo not found.");
75+
76+
LegacySupport legacySupport = lookup(LegacySupport.class);
77+
legacySupport.setSession(newMavenSession(new MavenProjectStub()));
78+
DefaultRepositorySystemSession repoSession =
79+
(DefaultRepositorySystemSession) legacySupport.getRepositorySession();
80+
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
81+
.newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));
82+
83+
List<MavenProject> reactorProjects =
84+
mojo1.getReactorProjects() != null ? mojo1.getReactorProjects() : Collections.emptyList();
85+
86+
setVariableValueToObject(mojo1, "mojoExecution", getMockMojoExecution());
87+
setVariableValueToObject(mojo1, "session", legacySupport.getSession());
88+
setVariableValueToObject(mojo1, "repoSession", legacySupport.getRepositorySession());
89+
setVariableValueToObject(mojo1, "reactorProjects", reactorProjects);
90+
setVariableValueToObject(
91+
mojo1, "remoteProjectRepositories", mojo1.getProject().getRemoteProjectRepositories());
92+
setVariableValueToObject(
93+
mojo1, "siteDirectory", new File(mojo1.getProject().getBasedir(), "src/site"));
94+
CheckstyleReport mojo = mojo1;
95+
File generatedReport = generateReport(mojo, pluginXmlFile);
7396
assertFalse(new File(generatedReport.getAbsolutePath()).exists());
7497
}
7598

@@ -815,41 +838,6 @@ protected File getGeneratedReport(String name) throws IOException {
815838
return report;
816839
}
817840

818-
/**
819-
* Generate the report and return the generated file
820-
*
821-
* @param goal the mojo goal.
822-
* @param pluginXml the name of the XML file in "src/test/resources/plugin-configs/"
823-
* @return the generated HTML file
824-
* @throws Exception if any
825-
*/
826-
protected File generateReport(String goal, String pluginXml) throws Exception {
827-
File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + pluginXml);
828-
CheckstyleReport mojo1 = (CheckstyleReport) lookupMojo(goal, pluginXmlFile);
829-
Assertions.assertNotNull(mojo1, "Mojo not found.");
830-
831-
LegacySupport legacySupport = lookup(LegacySupport.class);
832-
legacySupport.setSession(newMavenSession(new MavenProjectStub()));
833-
DefaultRepositorySystemSession repoSession =
834-
(DefaultRepositorySystemSession) legacySupport.getRepositorySession();
835-
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
836-
.newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));
837-
838-
List<MavenProject> reactorProjects =
839-
mojo1.getReactorProjects() != null ? mojo1.getReactorProjects() : Collections.emptyList();
840-
841-
setVariableValueToObject(mojo1, "mojoExecution", getMockMojoExecution());
842-
setVariableValueToObject(mojo1, "session", legacySupport.getSession());
843-
setVariableValueToObject(mojo1, "repoSession", legacySupport.getRepositorySession());
844-
setVariableValueToObject(mojo1, "reactorProjects", reactorProjects);
845-
setVariableValueToObject(
846-
mojo1, "remoteProjectRepositories", mojo1.getProject().getRemoteProjectRepositories());
847-
setVariableValueToObject(
848-
mojo1, "siteDirectory", new File(mojo1.getProject().getBasedir(), "src/site"));
849-
CheckstyleReport mojo = mojo1;
850-
return generateReport(mojo, pluginXmlFile);
851-
}
852-
853841
protected File generateReport(CheckstyleReport mojo, File pluginXmlFile) throws Exception {
854842
mojo.execute();
855843

0 commit comments

Comments
 (0)