Skip to content

Commit 729ec95

Browse files
committed
refactor: inline method
Signed-off-by: Sandra Parsick <sandra@parsick.dev>
1 parent 263017f commit 729ec95

File tree

4 files changed

+52
-68
lines changed

4 files changed

+52
-68
lines changed

src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected void setUp() throws Exception {
9292
*/
9393
public void testDefaultConfiguration() throws Exception {
9494
File generatedReport =
95-
generateReport(getGoal(), "default-configuration/cpd-default-configuration-plugin-config.xml");
95+
generateReport("cpd", "default-configuration/cpd-default-configuration-plugin-config.xml");
9696
assertTrue(new File(generatedReport.getAbsolutePath()).exists());
9797

9898
// check if the CPD files were generated
@@ -111,7 +111,7 @@ public void testDefaultConfiguration() throws Exception {
111111
* Test CPDReport with the text renderer given as "format=txt"
112112
*/
113113
public void testTxtFormat() throws Exception {
114-
generateReport(getGoal(), "custom-configuration/cpd-txt-format-configuration-plugin-config.xml");
114+
generateReport("cpd", "custom-configuration/cpd-txt-format-configuration-plugin-config.xml");
115115

116116
// check if the CPD files were generated
117117
File xmlFile = new File(getBasedir(), "target/test/unit/custom-configuration/target/cpd.xml");
@@ -132,7 +132,7 @@ public void testTxtFormat() throws Exception {
132132
*/
133133
public void testCustomConfiguration() throws Exception {
134134
File generatedReport =
135-
generateReport(getGoal(), "custom-configuration/cpd-custom-configuration-plugin-config.xml");
135+
generateReport("cpd", "custom-configuration/cpd-custom-configuration-plugin-config.xml");
136136
assertTrue(generatedReport.exists());
137137

138138
// check if the CPD files were generated
@@ -156,7 +156,7 @@ public void testInvalidFormat() throws Exception {
156156
try {
157157
File testPom = new File(
158158
getBasedir(), "src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml");
159-
AbstractPmdReport mojo = createReportMojo(getGoal(), testPom);
159+
AbstractPmdReport mojo = createReportMojo("cpd", testPom);
160160
setVariableValueToObject(
161161
mojo, "compileSourceRoots", mojo.getProject().getCompileSourceRoots());
162162
generateReport(mojo, testPom);
@@ -169,7 +169,7 @@ public void testInvalidFormat() throws Exception {
169169
}
170170

171171
public void testWriteNonHtml() throws Exception {
172-
generateReport(getGoal(), "default-configuration/cpd-default-configuration-plugin-config.xml");
172+
generateReport("cpd", "default-configuration/cpd-default-configuration-plugin-config.xml");
173173

174174
// check if the CPD files were generated
175175
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
@@ -192,7 +192,7 @@ public void testWriteNonHtml() throws Exception {
192192
* @throws Exception
193193
*/
194194
public void testIncludeXmlInReports() throws Exception {
195-
generateReport(getGoal(), "default-configuration/cpd-report-include-xml-in-reports-config.xml");
195+
generateReport("cpd", "default-configuration/cpd-report-include-xml-in-reports-config.xml");
196196

197197
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
198198
assertTrue(generatedFile.exists());
@@ -213,13 +213,13 @@ public void testIncludeXmlInReports() throws Exception {
213213

214214
public void testSkipEmptyReportConfiguration() throws Exception {
215215
// verify the generated files do not exist because PMD was skipped
216-
File generatedReport = generateReport(getGoal(), "empty-report/cpd-skip-empty-report-plugin-config.xml");
216+
File generatedReport = generateReport("cpd", "empty-report/cpd-skip-empty-report-plugin-config.xml");
217217
assertFalse(new File(generatedReport.getAbsolutePath()).exists());
218218
}
219219

220220
public void testEmptyReportConfiguration() throws Exception {
221221
// verify the generated files do exist, even if there are no violations
222-
File generatedReport = generateReport(getGoal(), "empty-report/cpd-empty-report-plugin-config.xml");
222+
File generatedReport = generateReport("cpd", "empty-report/cpd-empty-report-plugin-config.xml");
223223
assertTrue(
224224
generatedReport.getAbsolutePath() + " does not exist",
225225
new File(generatedReport.getAbsolutePath()).exists());
@@ -234,7 +234,7 @@ public void testCpdEncodingConfiguration() throws Exception {
234234
try {
235235
System.setProperty("file.encoding", "UTF-16");
236236

237-
generateReport(getGoal(), "default-configuration/cpd-default-configuration-plugin-config.xml");
237+
generateReport("cpd", "default-configuration/cpd-default-configuration-plugin-config.xml");
238238

239239
// check if the CPD files were generated
240240
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
@@ -247,7 +247,7 @@ public void testCpdEncodingConfiguration() throws Exception {
247247
}
248248

249249
public void testCpdJavascriptConfiguration() throws Exception {
250-
generateReport(getGoal(), "default-configuration/cpd-javascript-plugin-config.xml");
250+
generateReport("cpd", "default-configuration/cpd-javascript-plugin-config.xml");
251251

252252
// verify the generated file exists and violations are reported
253253
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
@@ -258,7 +258,7 @@ public void testCpdJavascriptConfiguration() throws Exception {
258258
}
259259

260260
public void testCpdJspConfiguration() throws Exception {
261-
generateReport(getGoal(), "default-configuration/cpd-jsp-plugin-config.xml");
261+
generateReport("cpd", "default-configuration/cpd-jsp-plugin-config.xml");
262262

263263
// verify the generated file exists and violations are reported
264264
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
@@ -269,7 +269,7 @@ public void testCpdJspConfiguration() throws Exception {
269269
}
270270

271271
public void testExclusionsConfiguration() throws Exception {
272-
generateReport(getGoal(), "default-configuration/cpd-report-cpd-exclusions-configuration-plugin-config.xml");
272+
generateReport("cpd", "default-configuration/cpd-report-cpd-exclusions-configuration-plugin-config.xml");
273273

274274
// verify the generated file exists and no duplications are reported
275275
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
@@ -280,7 +280,7 @@ public void testExclusionsConfiguration() throws Exception {
280280

281281
public void testWithCpdErrors() throws Exception {
282282
try {
283-
generateReport(getGoal(), "CpdReportTest/with-cpd-errors/pom.xml");
283+
generateReport("cpd", "CpdReportTest/with-cpd-errors/pom.xml");
284284

285285
fail("MojoExecutionException must be thrown");
286286
} catch (MojoExecutionException e) {
@@ -306,10 +306,6 @@ private static void assertReportContains(String expectedMessage) throws IOExcept
306306
"Expected '" + expectedMessage + "' in cpd.xml, but was:\n" + report, report.contains(expectedMessage));
307307
}
308308

309-
protected String getGoal() {
310-
return "cpd";
311-
}
312-
313309
@Override
314310
protected void tearDown() throws Exception {
315311
SessionScope lookup = lookup(SessionScope.class);
@@ -379,7 +375,7 @@ protected String readFile(File file) throws IOException {
379375

380376
private MojoExecution getMockMojoExecution() {
381377
MojoDescriptor mojoDescriptor = new MojoDescriptor();
382-
mojoDescriptor.setGoal(getGoal());
378+
mojoDescriptor.setGoal("cpd");
383379

384380
MojoExecution execution = new MojoExecution(mojoDescriptor);
385381

src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testDefaultConfiguration() throws Exception {
7070
File testPom = new File(
7171
getBasedir(),
7272
"src/test/resources/unit/default-configuration/cpd-check-default-configuration-plugin-config.xml");
73-
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo(getGoal(), testPom);
73+
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo("cpd-check", testPom);
7474
cpdViolationCheckMojo.execute();
7575

7676
fail("MojoFailureException should be thrown.");
@@ -85,7 +85,7 @@ public void testNotFailOnViolation() throws Exception {
8585
File testPom = new File(
8686
getBasedir(),
8787
"src/test/resources/unit/default-configuration/cpd-check-notfailonviolation-plugin-config.xml");
88-
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo(getGoal(), testPom);
88+
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo("cpd-check", testPom);
8989
cpdViolationCheckMojo.execute();
9090
}
9191

@@ -94,7 +94,7 @@ public void testException() throws Exception {
9494
File testPom = new File(
9595
getBasedir(),
9696
"src/test/resources/unit/custom-configuration/cpd-check-exception-test-plugin-config.xml");
97-
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo(getGoal(), testPom);
97+
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo("cpd-check", testPom);
9898
cpdViolationCheckMojo.project = new MavenProject();
9999
cpdViolationCheckMojo.execute();
100100

@@ -110,16 +110,12 @@ public void testExclusionsConfiguration() throws Exception {
110110
File testPom = new File(
111111
getBasedir(),
112112
"src/test/resources/unit/default-configuration/cpd-check-cpd-exclusions-configuration-plugin-config.xml");
113-
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo(getGoal(), testPom);
113+
CpdViolationCheckMojo cpdViolationCheckMojo = lookupMojo("cpd-check", testPom);
114114

115115
// this call shouldn't throw an exception, as the classes with duplications have been excluded
116116
cpdViolationCheckMojo.execute();
117117
}
118118

119-
protected String getGoal() {
120-
return "cpd-check";
121-
}
122-
123119
@Override
124120
protected void setUp() throws Exception {
125121
super.setUp();
@@ -200,7 +196,7 @@ protected String readFile(File file) throws IOException {
200196

201197
private MojoExecution getMockMojoExecution() {
202198
MojoDescriptor mojoDescriptor = new MojoDescriptor();
203-
mojoDescriptor.setGoal(getGoal());
199+
mojoDescriptor.setGoal("cpd-check");
204200

205201
MojoExecution execution = new MojoExecution(mojoDescriptor);
206202

0 commit comments

Comments
 (0)