KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > duplicates > StrictDuplicateCodeCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.duplicates;
2
3 import java.io.File JavaDoc;
4
5 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
6 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
7 import com.puppycrawl.tools.checkstyle.api.Configuration;
8
9 public class StrictDuplicateCodeCheckTest extends BaseCheckTestCase {
10
11     protected DefaultConfiguration createCheckerConfig(
12             Configuration aCheckConfig)
13     {
14         final DefaultConfiguration dc = new DefaultConfiguration("root");
15         dc.addChild(aCheckConfig);
16         return dc;
17     }
18
19     public void testDefaultSettings() throws Exception JavaDoc
20     {
21         final Configuration checkConfig = createCheckConfig(StrictDuplicateCodeCheck.class);
22         final String JavaDoc innerDupPath = getPath("duplicates/InnerDup.java");
23         final String JavaDoc[] expected = {
24                 "6: Found duplicate of 13 lines in " + innerDupPath + ", starting from line 22",
25                 };
26         final File JavaDoc[] checkedFiles = new File JavaDoc[] {
27                 new File JavaDoc(innerDupPath),
28                 new File JavaDoc(getPath("duplicates/Shorty.java")),
29                 };
30         verify(createChecker(checkConfig), checkedFiles, innerDupPath, expected);
31     }
32
33     public void testSmallMin() throws Exception JavaDoc
34     {
35         final DefaultConfiguration checkConfig = createCheckConfig(StrictDuplicateCodeCheck.class);
36         checkConfig.addAttribute("min", "3");
37         final String JavaDoc aPath = getPath("duplicates/A.java");
38         final String JavaDoc bPath = getPath("duplicates/B.java");
39         final String JavaDoc[] expected = {
40                 // imports should not be marked because developer cannot avoid them
41
// same constant def should not be marked because order is important for this check
42
};
43         final File JavaDoc[] checkedFiles = new File JavaDoc[] {
44                 new File JavaDoc(aPath),
45                 new File JavaDoc(bPath),
46                 };
47         verify(createChecker(checkConfig), checkedFiles, aPath, expected);
48     }
49
50 }
51
Popular Tags