Skip to content

Commit 2bc5682

Browse files
authored
[MPMD-412] More specific catch blocks (#642)
* [MPMD-412] More specific catch blocks * remove debugging stacktrace * better TODO
1 parent 8f15d77 commit 2bc5682

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportConsumer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public void accept(CPDReport report) {
6464
writeFormattedReport(report);
6565
}
6666
} catch (IOException | MavenReportException e) {
67+
// TODO this should be a more specific subclass; or just have the accept method
68+
// build the objects in memory and write them to a stream later after the
69+
// accept method returns
6770
throw new RuntimeException(e);
6871
}
6972
}

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ protected void setUp() throws Exception {
5050

5151
/**
5252
* Test CPDReport given the default configuration
53-
*
54-
* @throws Exception
5553
*/
5654
public void testDefaultConfiguration() throws Exception {
5755
File generatedReport =
@@ -72,8 +70,6 @@ public void testDefaultConfiguration() throws Exception {
7270

7371
/**
7472
* Test CPDReport with the text renderer given as "format=txt"
75-
*
76-
* @throws Exception
7773
*/
7874
public void testTxtFormat() throws Exception {
7975
generateReport(getGoal(), "custom-configuration/cpd-txt-format-configuration-plugin-config.xml");
@@ -94,8 +90,6 @@ public void testTxtFormat() throws Exception {
9490

9591
/**
9692
* Test CpdReport using custom configuration
97-
*
98-
* @throws Exception
9993
*/
10094
public void testCustomConfiguration() throws Exception {
10195
File generatedReport =
@@ -118,8 +112,6 @@ public void testCustomConfiguration() throws Exception {
118112

119113
/**
120114
* Test CPDReport with invalid format
121-
*
122-
* @throws Exception
123115
*/
124116
public void testInvalidFormat() throws Exception {
125117
try {
@@ -130,8 +122,9 @@ public void testInvalidFormat() throws Exception {
130122
mojo, "compileSourceRoots", mojo.getProject().getCompileSourceRoots());
131123
generateReport(mojo, testPom);
132124

133-
fail("MavenReportException must be thrown");
134-
} catch (Exception e) {
125+
// TODO this should be a more specific subclass
126+
fail("RuntimeException must be thrown");
127+
} catch (RuntimeException e) {
135128
assertMavenReportException("Can't find CPD custom format xhtml", e);
136129
}
137130
}
@@ -259,13 +252,11 @@ public void testWithCpdErrors() throws Exception {
259252
}
260253

261254
private static void assertMavenReportException(String expectedMessage, Exception exception) {
255+
MavenReportException cause = (MavenReportException) exception.getCause();
256+
String message = cause.getMessage();
262257
assertTrue(
263-
"Expected MavenReportException, but was: " + exception,
264-
exception.getCause() instanceof MavenReportException);
265-
exception = (Exception) exception.getCause();
266-
assertTrue(
267-
"Wrong message: expected: " + expectedMessage + ", but was: " + exception.toString(),
268-
exception.toString().contains(expectedMessage));
258+
"Wrong message: expected: " + expectedMessage + ", but was: " + message,
259+
message.contains(expectedMessage));
269260
}
270261

271262
private static void assertReportContains(String expectedMessage) throws IOException {

0 commit comments

Comments
 (0)