1 package com.puppycrawl.tools.checkstyle.checks.duplicates; 2 3 import java.io.File ; 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 20 { 21 final Configuration checkConfig = createCheckConfig(StrictDuplicateCodeCheck.class); 22 final String innerDupPath = getPath("duplicates/InnerDup.java"); 23 final String [] expected = { 24 "6: Found duplicate of 13 lines in " + innerDupPath + ", starting from line 22", 25 }; 26 final File [] checkedFiles = new File [] { 27 new File (innerDupPath), 28 new File (getPath("duplicates/Shorty.java")), 29 }; 30 verify(createChecker(checkConfig), checkedFiles, innerDupPath, expected); 31 } 32 33 public void testSmallMin() throws Exception 34 { 35 final DefaultConfiguration checkConfig = createCheckConfig(StrictDuplicateCodeCheck.class); 36 checkConfig.addAttribute("min", "3"); 37 final String aPath = getPath("duplicates/A.java"); 38 final String bPath = getPath("duplicates/B.java"); 39 final String [] expected = { 40 }; 43 final File [] checkedFiles = new File [] { 44 new File (aPath), 45 new File (bPath), 46 }; 47 verify(createChecker(checkConfig), checkedFiles, aPath, expected); 48 } 49 50 } 51 | Popular Tags |