1 package com.puppycrawl.tools.checkstyle.checks.coding; 2 3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; 4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration; 5 6 import java.io.File ; 7 8 public class RequireThisCheckTest extends BaseCheckTestCase 9 { 10 public void testIt() throws Exception 11 { 12 final DefaultConfiguration checkConfig = 13 createCheckConfig(RequireThisCheck.class); 14 final String [] expected = { 15 "6:9: Reference to instance variable 'i' needs \"this.\".", 16 "12:9: Method call to 'method1' needs \"this.\".", 17 "26:9: Reference to instance variable 'i' needs \"this.\".", 18 "51:9: Reference to instance variable 'z' needs \"this.\".", 19 }; 21 verify(checkConfig, 22 getPath("coding" + File.separator + "InputRequireThis.java"), 23 expected); 24 } 25 26 public void testMethodsOnly() throws Exception 27 { 28 final DefaultConfiguration checkConfig = 29 createCheckConfig(RequireThisCheck.class); 30 checkConfig.addAttribute("checkFields", "false"); 31 final String [] expected = { 32 "12:9: Method call to 'method1' needs \"this.\".", 33 }; 34 verify(checkConfig, 35 getPath("coding" + File.separator + "InputRequireThis.java"), 36 expected); 37 } 38 39 public void testFieldsOnly() throws Exception 40 { 41 final DefaultConfiguration checkConfig = 42 createCheckConfig(RequireThisCheck.class); 43 checkConfig.addAttribute("checkMethods", "false"); 44 final String [] expected = { 45 "6:9: Reference to instance variable 'i' needs \"this.\".", 46 "26:9: Reference to instance variable 'i' needs \"this.\".", 47 "51:9: Reference to instance variable 'z' needs \"this.\".", 48 }; 50 verify(checkConfig, 51 getPath("coding" + File.separator + "InputRequireThis.java"), 52 expected); 53 } 54 55 public void testGenerics() throws Exception 56 { 57 final DefaultConfiguration checkConfig = 58 createCheckConfig(RequireThisCheck.class); 59 final String [] expected = {}; 60 verify(checkConfig, getPath("Input15Extensions.java"), expected); 61 } 62 } 63 | Popular Tags |