KickJava   Java API By Example, From Geeks To Geeks.

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


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 IllegalCatchCheckTest extends BaseCheckTestCase
9 {
10     public void testDefault() throws Exception JavaDoc
11     {
12         DefaultConfiguration checkConfig = createCheckConfig(IllegalCatchCheck.class);
13
14         String JavaDoc[] expected = {
15             "6:11: Catching 'RuntimeException' is not allowed.",
16             "7:11: Catching 'Exception' is not allowed.",
17             "8:11: Catching 'Throwable' is not allowed.",
18             "14:11: Catching 'java.lang.RuntimeException' is not allowed.",
19             "15:11: Catching 'java.lang.Exception' is not allowed.",
20             "16:11: Catching 'java.lang.Throwable' is not allowed.",
21         };
22
23         verify(checkConfig, getPath("coding" + File.separator + "InputIllegalCatchCheck.java"), expected);
24     }
25
26     public void testIllegalClassNames() throws Exception JavaDoc
27     {
28         DefaultConfiguration checkConfig = createCheckConfig(IllegalCatchCheck.class);
29         checkConfig.addAttribute("illegalClassNames",
30                                  "java.lang.Error, java.lang.Exception, java.lang.Throwable");
31
32         String JavaDoc[] expected = {
33             "7:11: Catching 'Exception' is not allowed.",
34             "8:11: Catching 'Throwable' is not allowed.",
35             "15:11: Catching 'java.lang.Exception' is not allowed.",
36             "16:11: Catching 'java.lang.Throwable' is not allowed.",
37         };
38
39         verify(checkConfig, getPath("coding" + File.separator + "InputIllegalCatchCheck.java"), expected);
40     }
41 }
42
Popular Tags