KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > FinalParametersCheckTest


1 package com.puppycrawl.tools.checkstyle.checks;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5
6 public class FinalParametersCheckTest extends BaseCheckTestCase
7 {
8     public void testDefaultTokens()
9             throws Exception JavaDoc
10     {
11         final DefaultConfiguration checkConfig =
12             createCheckConfig(FinalParametersCheck.class);
13         final String JavaDoc[] expected = {
14             "23:26: Parameter s should be final.",
15             "38:26: Parameter i should be final.",
16             "43:26: Parameter s should be final.",
17             "53:17: Parameter s should be final.",
18             "69:17: Parameter s should be final.",
19             "75:17: Parameter s should be final.",
20             "90:45: Parameter e should be final.",
21             "93:36: Parameter e should be final.",
22             "110:18: Parameter aParam should be final.",
23             "113:18: Parameter args should be final.",
24             "116:18: Parameter args should be final.",
25         };
26         verify(checkConfig, getPath("InputFinalParameters.java"), expected);
27     }
28
29     public void testCtorToken()
30             throws Exception JavaDoc
31     {
32         final DefaultConfiguration checkConfig =
33             createCheckConfig(FinalParametersCheck.class);
34         checkConfig.addAttribute("tokens", "CTOR_DEF");
35         final String JavaDoc[] expected = {
36             "23:26: Parameter s should be final.",
37             "38:26: Parameter i should be final.",
38             "43:26: Parameter s should be final.",
39         };
40         verify(checkConfig, getPath("InputFinalParameters.java"), expected);
41     }
42
43     public void testMethodToken()
44             throws Exception JavaDoc
45     {
46         final DefaultConfiguration checkConfig =
47             createCheckConfig(FinalParametersCheck.class);
48         checkConfig.addAttribute("tokens", "METHOD_DEF");
49         final String JavaDoc[] expected = {
50             "53:17: Parameter s should be final.",
51             "69:17: Parameter s should be final.",
52             "75:17: Parameter s should be final.",
53             "90:45: Parameter e should be final.",
54             "93:36: Parameter e should be final.",
55             "110:18: Parameter aParam should be final.",
56             "113:18: Parameter args should be final.",
57             "116:18: Parameter args should be final.",
58         };
59         verify(checkConfig, getPath("InputFinalParameters.java"), expected);
60     }
61
62     public void testCatchToken()
63             throws Exception JavaDoc
64     {
65         final DefaultConfiguration checkConfig =
66             createCheckConfig(FinalParametersCheck.class);
67         checkConfig.addAttribute("tokens", "LITERAL_CATCH");
68         final String JavaDoc[] expected = {
69             "125:16: Parameter npe should be final.",
70             "131:16: Parameter e should be final.",
71             "134:16: Parameter e should be final.",
72         };
73         verify(checkConfig, getPath("InputFinalParameters.java"), expected);
74     }
75
76     public void testForEachClauseToken()
77             throws Exception JavaDoc
78     {
79         final DefaultConfiguration checkConfig =
80             createCheckConfig(FinalParametersCheck.class);
81         checkConfig.addAttribute("tokens", "FOR_EACH_CLAUSE");
82         final String JavaDoc[] expected = {
83             "150:13: Parameter s should be final.",
84             "158:13: Parameter s should be final.",
85         };
86         verify(checkConfig, getPath("InputFinalParameters.java"), expected);
87     }
88 }
89
Popular Tags