Skip to content

Commit b03ad1d

Browse files
committed
chore: migrate to mojotest - PmdReportTest
Signed-off-by: Sandra Parsick <sandra@parsick.dev>
1 parent 8fc5bbd commit b03ad1d

30 files changed

+363
-322
lines changed

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

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

21+
import javax.inject.Inject;
22+
import javax.xml.parsers.DocumentBuilder;
23+
import javax.xml.parsers.DocumentBuilderFactory;
24+
25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.nio.file.Paths;
31+
import java.util.Collections;
32+
import java.util.Locale;
33+
2134
import org.apache.commons.lang3.StringUtils;
2235
import org.apache.maven.api.plugin.testing.Basedir;
2336
import org.apache.maven.api.plugin.testing.InjectMojo;
@@ -41,18 +54,6 @@
4154
import org.mockito.Mockito;
4255
import org.w3c.dom.Document;
4356

44-
import javax.inject.Inject;
45-
import javax.xml.parsers.DocumentBuilder;
46-
import javax.xml.parsers.DocumentBuilderFactory;
47-
import java.io.File;
48-
import java.io.IOException;
49-
import java.nio.charset.StandardCharsets;
50-
import java.nio.file.Files;
51-
import java.nio.file.Path;
52-
import java.nio.file.Paths;
53-
import java.util.Collections;
54-
import java.util.Locale;
55-
5657
import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
5758
import static org.junit.jupiter.api.Assertions.assertEquals;
5859
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -79,7 +80,6 @@ public class CpdReportTest {
7980
@Inject
8081
private MojoExecution mojoExecution;
8182

82-
8383
/**
8484
* Checks whether the string <code>contained</code> is contained in
8585
* the given <code>text</code>, ignoring case.
@@ -96,7 +96,7 @@ public static boolean lowerCaseContains(String text, String contains) {
9696
* {@inheritDoc}
9797
*/
9898
@BeforeEach
99-
public void setUp() throws Exception {
99+
public void setUp() {
100100
ArtifactRepository localRepo = Mockito.mock(ArtifactRepository.class);
101101
Mockito.when(localRepo.getBasedir())
102102
.thenReturn(new File(PlexusExtension.getBasedir(), "target/local-repo").getAbsolutePath());
@@ -208,8 +208,9 @@ public void testInvalidFormat(AbstractPmdReport mojo) {
208208
try {
209209
mojo.execute();
210210

211-
fail("MojoExecutionException must be thrown");
212-
} catch (MojoExecutionException e) {
211+
// TODO should have more specific exception
212+
fail("RuntimeException must be thrown");
213+
} catch (RuntimeException e) {
213214
assertMavenReportException("Can't find CPD custom format xhtml", e);
214215
}
215216
}
@@ -396,12 +397,10 @@ private static void assertReportContains(String expectedMessage) throws IOExcept
396397
report.contains(expectedMessage), "Expected '" + expectedMessage + "' in cpd.xml, but was:\n" + report);
397398
}
398399

399-
400400
/**
401401
* Read the contents of the specified file into a string.
402402
*/
403403
protected String readFile(File file) throws IOException {
404404
return new String(Files.readAllBytes(file.toPath()));
405405
}
406-
407406
}

0 commit comments

Comments
 (0)