KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class RedundantThrowsCheckTest extends BaseCheckTestCase
7 {
8     private DefaultConfiguration mCheckConfig;
9
10     public void setUp()
11     {
12         mCheckConfig = createCheckConfig(RedundantThrowsCheck.class);
13     }
14
15     public void testDefaults() throws Exception JavaDoc
16     {
17         final String JavaDoc[] expected = {
18             "7:37: Redundant throws: 'java.io.FileNotFoundException' is subclass of 'java.io.IOException'.",
19             "13:16: Redundant throws: 'RuntimeException' is unchecked exception.",
20             "19:29: Redundant throws: 'java.io.IOException' listed more then one time.",
21             "39:27: Redundant throws: 'NullPointerException' is subclass of 'RuntimeException'.",
22             "39:27: Redundant throws: 'NullPointerException' is unchecked exception.",
23             "39:49: Redundant throws: 'RuntimeException' is unchecked exception.",
24         };
25         verify(mCheckConfig, getPath("InputRedundantThrows.java"), expected);
26     }
27
28     public void testAllowUnchecked() throws Exception JavaDoc
29     {
30         mCheckConfig.addAttribute("allowUnchecked", "true");
31         final String JavaDoc[] expected = {
32             "7:37: Redundant throws: 'java.io.FileNotFoundException' is subclass of 'java.io.IOException'.",
33             "19:29: Redundant throws: 'java.io.IOException' listed more then one time.",
34 // "35:27: Unable to get class information for WrongException.",
35
"39:27: Redundant throws: 'NullPointerException' is subclass of 'RuntimeException'.",
36         };
37         verify(mCheckConfig, getPath("InputRedundantThrows.java"), expected);
38     }
39
40     public void testAllowSubclasses() throws Exception JavaDoc
41     {
42         mCheckConfig.addAttribute("allowSubclasses", "true");
43         final String JavaDoc[] expected = {
44             "13:16: Redundant throws: 'RuntimeException' is unchecked exception.",
45             "19:29: Redundant throws: 'java.io.IOException' listed more then one time.",
46             "39:27: Redundant throws: 'NullPointerException' is unchecked exception.",
47             "39:49: Redundant throws: 'RuntimeException' is unchecked exception.",
48         };
49         verify(mCheckConfig, getPath("InputRedundantThrows.java"), expected);
50     }
51
52     public void testRejectDuplicatesOnly() throws Exception JavaDoc
53     {
54         mCheckConfig.addAttribute("allowSubclasses", "true");
55         mCheckConfig.addAttribute("allowUnchecked", "true");
56         final String JavaDoc[] expected = {
57             "19:29: Redundant throws: 'java.io.IOException' listed more then one time.",
58         };
59         verify(mCheckConfig, getPath("InputRedundantThrows.java"), expected);
60     }
61
62     public void test_1168408_1() throws Exception JavaDoc
63     {
64         final String JavaDoc[] expected = {};
65         verify(mCheckConfig, getPath("javadoc/Test1.java"), expected);
66     }
67
68     public void test_1168408_2() throws Exception JavaDoc
69     {
70         final String JavaDoc[] expected = {};
71         verify(mCheckConfig, getPath("javadoc/Test2.java"), expected);
72     }
73
74     public void test_1168408_3() throws Exception JavaDoc
75     {
76         final String JavaDoc[] expected = {};
77         verify(mCheckConfig, getPath("javadoc/Test3.java"), expected);
78     }
79
80     public void test_1220726() throws Exception JavaDoc
81     {
82         final String JavaDoc[] expected = {};
83         verify(mCheckConfig, getPath("javadoc/BadCls.java"), expected);
84     }
85
86     public void test_generics_params() throws Exception JavaDoc
87     {
88         final String JavaDoc[] expected = {
89             "15:34: Redundant throws: 'RE' is unchecked exception.",
90             "23:37: Redundant throws: 'RE' is subclass of 'E'.",
91             "23:37: Redundant throws: 'RE' is unchecked exception.",
92             "31:69: Redundant throws: 'NPE' is subclass of 'RE'.",
93             "31:69: Redundant throws: 'NPE' is unchecked exception.",
94             "31:74: Redundant throws: 'RE' is unchecked exception.",
95             "41:38: Redundant throws: 'RuntimeException' is subclass of 'RE'.",
96             "41:38: Redundant throws: 'RuntimeException' is unchecked exception.",
97             "41:56: Redundant throws: 'RE' is unchecked exception.",
98             "42:13: Redundant throws: 'java.lang.RuntimeException' is unchecked exception.",
99             "42:13: Redundant throws: 'java.lang.RuntimeException' listed more then one time.",
100         };
101         verify(mCheckConfig, getPath("javadoc/TestGenerics.java"), expected);
102     }
103
104     public void test_1379666() throws Exception JavaDoc
105     {
106         final String JavaDoc[] expected = {};
107         verify(mCheckConfig, getPath("javadoc/Test_1379666.java"), expected);
108     }
109 }
110
Popular Tags