1
2
3
4 package net.sourceforge.pmd.cpd;
5
6 import java.io.ByteArrayOutputStream;
7 import java.io.PrintStream;
8
9 import junit.framework.Assert;
10
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Test;
14
15
16
17
18
19 public class CPDCommandLineInterfaceTest {
20 private ByteArrayOutputStream buffer;
21 private PrintStream originalStdout;
22
23
24 @Before
25 public void setup() {
26 originalStdout = System.out;
27 buffer = new ByteArrayOutputStream();
28 System.setOut(new PrintStream(buffer));
29 }
30
31 @After
32 public void teardown() {
33 System.setOut(originalStdout);
34 }
35
36
37
38
39 @Test
40 public void testIgnoreIdentifiers() throws Exception {
41 runCPD("--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers");
42
43 String out = buffer.toString("UTF-8");
44 Assert.assertTrue(out.contains("Found a 7 line (34 tokens) duplication"));
45 }
46
47 private void runCPD(String... args) {
48 CPD.dontExitForTests = true;
49 CPD.main(args);
50 }
51 }