KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > coding > FallThroughCheckTest


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 JavaDoc;
7
8 public class FallThroughCheckTest extends BaseCheckTestCase
9 {
10
11     public void testDefault() throws Exception JavaDoc
12     {
13         DefaultConfiguration checkConfig = createCheckConfig(FallThroughCheck.class);
14         final String JavaDoc[] expected = {
15             "12:13: Fall through from previous branch of the switch statement.",
16             "36:13: Fall through from previous branch of the switch statement.",
17             "51:13: Fall through from previous branch of the switch statement.",
18             "68:13: Fall through from previous branch of the switch statement.",
19             "85:13: Fall through from previous branch of the switch statement.",
20             "103:13: Fall through from previous branch of the switch statement.",
21             "121:13: Fall through from previous branch of the switch statement.",
22             "367:11: Fall through from previous branch of the switch statement.",
23             "370:11: Fall through from previous branch of the switch statement.",
24             "372:40: Fall through from previous branch of the switch statement.",
25         };
26         verify(checkConfig,
27                getPath("coding" + File.separator + "InputFallThrough.java"),
28                expected);
29     }
30     
31     public void testLastCaseGroup() throws Exception JavaDoc
32     {
33         DefaultConfiguration checkConfig = createCheckConfig(FallThroughCheck.class);
34         checkConfig.addAttribute("checkLastCaseGroup", "true");
35         final String JavaDoc[] expected = {
36             "12:13: Fall through from previous branch of the switch statement.",
37             "36:13: Fall through from previous branch of the switch statement.",
38             "51:13: Fall through from previous branch of the switch statement.",
39             "68:13: Fall through from previous branch of the switch statement.",
40             "85:13: Fall through from previous branch of the switch statement.",
41             "103:13: Fall through from previous branch of the switch statement.",
42             "121:13: Fall through from previous branch of the switch statement.",
43             "121:13: Fall through from the last branch of the switch statement.",
44             "367:11: Fall through from previous branch of the switch statement.",
45             "370:11: Fall through from previous branch of the switch statement.",
46             "372:40: Fall through from previous branch of the switch statement.",
47             "374:11: Fall through from the last branch of the switch statement.",
48         };
49         verify(checkConfig,
50                getPath("coding" + File.separator + "InputFallThrough.java"),
51                expected);
52     }
53
54     public void testOwnPattern() throws Exception JavaDoc
55     {
56         final String JavaDoc ownPattern = "Continue with next case";
57         final DefaultConfiguration checkConfig =
58             createCheckConfig(FallThroughCheck.class);
59         checkConfig.addAttribute("reliefPattern", ownPattern);
60         
61         final String JavaDoc[] expected = {
62             "12:13: Fall through from previous branch of the switch statement.",
63             "36:13: Fall through from previous branch of the switch statement.",
64             "51:13: Fall through from previous branch of the switch statement.",
65             "68:13: Fall through from previous branch of the switch statement.",
66             "85:13: Fall through from previous branch of the switch statement.",
67             "103:13: Fall through from previous branch of the switch statement.",
68             "121:13: Fall through from previous branch of the switch statement.",
69             "143:11: Fall through from previous branch of the switch statement.",
70             "168:11: Fall through from previous branch of the switch statement.",
71             "184:11: Fall through from previous branch of the switch statement.",
72             "202:11: Fall through from previous branch of the switch statement.",
73             "220:11: Fall through from previous branch of the switch statement.",
74             "239:11: Fall through from previous branch of the switch statement.",
75             "250:26: Fall through from previous branch of the switch statement.",
76             "264:11: Fall through from previous branch of the switch statement.",
77             "279:11: Fall through from previous branch of the switch statement.",
78             "282:11: Fall through from previous branch of the switch statement.",
79             "286:11: Fall through from previous branch of the switch statement.",
80             "288:25: Fall through from previous branch of the switch statement.",
81             "304:11: Fall through from previous branch of the switch statement.",
82             "307:11: Fall through from previous branch of the switch statement.",
83             "309:25: Fall through from previous branch of the switch statement.",
84             "325:11: Fall through from previous branch of the switch statement.",
85             "328:11: Fall through from previous branch of the switch statement.",
86             "330:23: Fall through from previous branch of the switch statement.",
87             "346:11: Fall through from previous branch of the switch statement.",
88             "349:11: Fall through from previous branch of the switch statement.",
89             "351:30: Fall through from previous branch of the switch statement.",
90         };
91         verify(checkConfig,
92                getPath("coding" + File.separator + "InputFallThrough.java"),
93                expected);
94         
95     }
96 }
97
Popular Tags