michael-o commented on code in PR #150: URL: https://github.com/apache/maven-pmd-plugin/pull/150#discussion_r1629937539
########## src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java: ########## @@ -240,4 +241,30 @@ public void testExclusionsConfiguration() throws Exception { String str = readFile(generatedFile); assertEquals(0, StringUtils.countMatches(str, "<duplication")); } + + public void testWithCpdErrors() throws Exception { + try { + File generatedReport = generateReport("cpd", "CpdReportTest/with-cpd-errors/pom.xml"); + fail("MavenReportException must be thrown"); + } catch (Exception e) { + assertMavenReportException("There was 1 error while executing CPD", e); + assertLogOutputContains("Lexical error in file"); + assertLogOutputContains("BadFile.java"); + } + } + + private static void assertMavenReportException(String expectedMessage, Exception exception) { + // The maven report exception might be wrapped in a RuntimeException + assertTrue( + "Expected MavenReportException, but was: " + exception, + exception instanceof MavenReportException || exception.getCause() instanceof MavenReportException); + assertTrue( + "Wrong message: expected: " + expectedMessage + ", but was: " + exception.toString(), + exception.toString().contains(expectedMessage)); + } + + private static void assertLogOutputContains(String expectedMessage) { + String log = CapturingPrintStream.getOutput(); + assertTrue("Expected '" + expectedMessage + "' in log, but was:\n" + log, log.contains(expectedMessage)); Review Comment: Is the `\n` also portable on Windows? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org