Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/checks/ConstantNameCheckTest.java


1   package com.puppycrawl.tools.checkstyle.checks;
2   
3   import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4   import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5   import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
6   
7   public class ConstantNameCheckTest
8       extends BaseCheckTestCase
9   {
10      public void testIllegalRegexp()
11          throws Exception
12      {
13          final DefaultConfiguration checkConfig =
14              createCheckConfig(ConstantNameCheck.class);
15          checkConfig.addAttribute("format", "\\");
16          try {
17              createChecker(checkConfig);
18              fail();
19          }
20          catch (CheckstyleException ex) {
21              // expected exception
22          }
23      }
24  
25      public void testDefault()
26          throws Exception
27      {
28          final DefaultConfiguration checkConfig =
29              createCheckConfig(ConstantNameCheck.class);
30          final String[] expected = {
31              "25:29: Name 'badConstant' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
32              "142:30: Name 'BAD__NAME' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'."
33          };
34          verify(checkConfig, getPath("InputSimple.java"), expected);
35      }
36  
37      public void testInterface()
38          throws Exception
39      {
40          final DefaultConfiguration checkConfig =
41              createCheckConfig(ConstantNameCheck.class);
42          final String[] expected = {
43              "24:16: Name 'data' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'."
44          };
45          verify(checkConfig, getPath("InputInner.java"), expected);
46      }
47  }