-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPDTaskTest.java
More file actions
60 lines (49 loc) · 2.13 KB
/
CPDTaskTest.java
File metadata and controls
60 lines (49 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.ant;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.tools.ant.BuildException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.internal.util.IOUtil;
/**
*
* @author Romain Pelisse <belaran@gmail.com>
*
*/
class CPDTaskTest extends AbstractAntTest {
@BeforeEach void setUp() {
configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/cpdtasktest.xml");
}
@Test void testBasic() throws IOException {
executeTarget("testBasic");
assertReport("target/cpd.ant.tests");
}
@Test void failOnErrorDefault() throws IOException {
BuildException buildException = assertThrows(BuildException.class, () -> executeTarget("failOnErrorDefault"));
assertThat(buildException.getMessage(), containsString("There were 1 recovered errors during analysis."));
assertReport("target/cpd.ant.tests");
}
@Test void failOnErrorIgnore() throws IOException {
executeTarget("failOnErrorIgnore");
assertReport("target/cpd.ant.tests");
assertThat(log.toString(), containsString("There were 1 recovered errors during analysis."));
}
private static void assertReport(String path) throws IOException {
Path report = Paths.get(path);
assertTrue(Files.exists(report), "Report was not created");
String reportContent = IOUtil.readFileToString(report.toFile(), StandardCharsets.UTF_8);
assertThat(reportContent, containsString("Found a 1 line (21 tokens) duplication in the following files:"));
assertThat(reportContent, containsString("sample.dummy"));
assertThat(reportContent, containsString("sample2.dummy"));
}
}