1 package com.puppycrawl.tools.checkstyle.checks.naming; 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.CheckstyleException; 8 9 public class ConstantNameCheckTest 10 extends BaseCheckTestCase 11 { 12 public void testIllegalRegexp() 13 throws Exception 14 { 15 final DefaultConfiguration checkConfig = 16 createCheckConfig(ConstantNameCheck.class); 17 checkConfig.addAttribute("format", "\\"); 18 try { 19 createChecker(checkConfig); 20 fail(); 21 } 22 catch (CheckstyleException ex) { 23 } 25 } 26 27 public void testDefault() 28 throws Exception 29 { 30 final DefaultConfiguration checkConfig = 31 createCheckConfig(ConstantNameCheck.class); 32 final String [] expected = { 33 "25:29: Name 'badConstant' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.", 34 "142:30: Name 'BAD__NAME' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'." 35 }; 36 verify(checkConfig, getPath("InputSimple.java"), expected); 37 } 38 39 public void testInterfaceAndAnnotation() 40 throws Exception 41 { 42 final DefaultConfiguration checkConfig = 43 createCheckConfig(ConstantNameCheck.class); 44 final String [] expected = { 45 "24:16: Name 'data' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.", 46 "64:16: Name 'data' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'." 47 }; 48 verify(checkConfig, getPath("InputInner.java"), expected); 49 } 50 51 public void testDefault1() 52 throws Exception 53 { 54 final DefaultConfiguration checkConfig = 55 createCheckConfig(ConstantNameCheck.class); 56 final String [] expected = { 57 }; 58 verify(checkConfig, getPath("naming" + File.separator + "InputConstantNames.java"), expected); 59 } 60 } 61 | Popular Tags |