diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java index af1eee72aa..7d13a82a16 100644 --- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java +++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java @@ -38,6 +38,14 @@ class CpdCliTest extends BaseCliTest { private static final String SRC_DIR = BASE_RES_PATH + "files/"; private static final Path SRC_PATH = Paths.get(SRC_DIR).toAbsolutePath(); + private static final String CPD_REPORT_HEADER_PATTERN = "<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n" + + "\n"; + private static final Map NUMBER_OF_TOKENS; static { @@ -68,8 +76,11 @@ class CpdCliTest extends BaseCliTest { void testEmptyResultRendering() throws Exception { final String expectedFilesXml = getExpectedFileEntriesXml(NUMBER_OF_TOKENS.keySet()); runCliSuccessfully("--minimum-tokens", "340", "--language", "java", "--dir", SRC_DIR, "--format", "xml") - .verify(result -> result.checkStdOut(equalTo( - "" + "\n" + "\n" + expectedFilesXml + "\n" + .verify(result -> result.checkStdOut(containsPattern(CPD_REPORT_HEADER_PATTERN + + "\\Q" // quote start + + expectedFilesXml + + "\n" + + "\\E" // quote end ))); } @@ -176,8 +187,8 @@ class CpdCliTest extends BaseCliTest { @Test void testNoDuplicatesResultRendering() throws Exception { - String expectedReport = "\n" - + "\n" + String expectedReportPattern = CPD_REPORT_HEADER_PATTERN + + "\\Q" // quote start + " \n" + " \n" + " \n" - + "\n"; + + "\n" + + "\\E"; // quote end runCliSuccessfully("--minimum-tokens", "340", "--language", "java", "--dir", SRC_DIR, "--format", "xml") - .verify(result -> result.checkStdOut(equalTo(expectedReport))); + .verify(result -> result.checkStdOut(containsPattern(expectedReportPattern))); } /** @@ -251,9 +263,7 @@ class CpdCliTest extends BaseCliTest { runCli(OK, "--minimum-tokens", "5", "--language", "ecmascript", "-f", "xml", "-d", BASE_RES_PATH + "tsFiles/") - .checkStdOut(equalTo( - "\n\n" - )); + .checkStdOut(containsPattern(CPD_REPORT_HEADER_PATTERN.substring(0, CPD_REPORT_HEADER_PATTERN.length() - 2) + "/>")); } @Test