KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > design > VisibilityModifierCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.design;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.Checker;
5 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
6
7 public class VisibilityModifierCheckTest
8     extends BaseCheckTestCase
9 {
10     private Checker getChecker() throws Exception JavaDoc
11     {
12         final DefaultConfiguration checkConfig =
13             createCheckConfig(VisibilityModifierCheck.class);
14         checkConfig.addAttribute("publicMemberPattern", "^f[A-Z][a-zA-Z0-9]*$");
15         return createChecker(checkConfig);
16     }
17
18     public void testInner()
19         throws Exception JavaDoc
20     {
21         final String JavaDoc[] expected = {
22             "30:24: Variable 'rData' must be private and have accessor methods.",
23             "33:27: Variable 'protectedVariable' must be private and have accessor methods.",
24             "36:17: Variable 'packageVariable' must be private and have accessor methods.",
25             "41:29: Variable 'sWeird' must be private and have accessor methods.",
26             "43:19: Variable 'sWeird2' must be private and have accessor methods.",
27             "77:20: Variable 'someValue' must be private and have accessor methods.",
28         };
29         verify(getChecker(), getPath("InputInner.java"), expected);
30     }
31
32     public void testIgnoreAccess()
33         throws Exception JavaDoc
34     {
35         final DefaultConfiguration checkConfig =
36             createCheckConfig(VisibilityModifierCheck.class);
37         checkConfig.addAttribute("publicMemberPattern", "^r[A-Z]");
38         checkConfig.addAttribute("protectedAllowed", "true");
39         checkConfig.addAttribute("packageAllowed", "true");
40         final String JavaDoc[] expected = {
41             "17:20: Variable 'fData' must be private and have accessor methods.",
42             "77:20: Variable 'someValue' must be private and have accessor methods.",
43         };
44         verify(checkConfig, getPath("InputInner.java"), expected);
45     }
46
47     public void testSimple() throws Exception JavaDoc {
48         final String JavaDoc[] expected = {
49             "39:19: Variable 'mNumCreated2' must be private and have accessor methods.",
50             "49:23: Variable 'sTest1' must be private and have accessor methods.",
51             "51:26: Variable 'sTest3' must be private and have accessor methods.",
52             "53:16: Variable 'sTest2' must be private and have accessor methods.",
53             "56:9: Variable 'mTest1' must be private and have accessor methods.",
54             "58:16: Variable 'mTest2' must be private and have accessor methods.",
55         };
56         verify(getChecker(), getPath("InputSimple.java"), expected);
57     }
58
59     public void testStrictJavadoc()
60             throws Exception JavaDoc
61     {
62         final String JavaDoc[] expected = {
63             "44:9: Variable 'mLen' must be private and have accessor methods.",
64             "45:19: Variable 'mDeer' must be private and have accessor methods.",
65             "46:16: Variable 'aFreddo' must be private and have accessor methods.",
66         };
67         verify(getChecker(), getPath("InputPublicOnly.java"), expected);
68     }
69 }
70
Popular Tags