KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > javadoc > JavadocStyleCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.javadoc;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5
6
7 public class JavadocStyleCheckTest
8     extends BaseCheckTestCase
9 {
10     public void testDefaultSettings()
11         throws Exception JavaDoc
12     {
13         final DefaultConfiguration checkConfig =
14             createCheckConfig(JavadocStyleCheck.class);
15         final String JavaDoc[] expected =
16         {
17             "20: First sentence should end with a period.",
18             "53: First sentence should end with a period.",
19             "63:11: Unclosed HTML tag found: <b>This guy is missing end of bold tag",
20             "66:7: Extra HTML tag found: </td>Extra tag shouldn't be here",
21             "68:19: Unclosed HTML tag found: <code>dummy.",
22             "74: First sentence should end with a period.",
23             "75:23: Unclosed HTML tag found: <b>should fail",
24             "81: First sentence should end with a period.",
25             "82:31: Unclosed HTML tag found: <b>should fail",
26             "88: First sentence should end with a period.",
27             "89:31: Extra HTML tag found: </code>",
28             "90: Incomplete HTML tag found: * should fail <",
29             "109:39: Extra HTML tag found: </img>",
30             "186:8: Unclosed HTML tag found: <blockquote>",
31             "193: First sentence should end with a period.",
32             "238: First sentence should end with a period.",
33         };
34
35         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
36     }
37
38     public void testFirstSentence() throws Exception JavaDoc
39     {
40         final DefaultConfiguration checkConfig =
41             createCheckConfig(JavadocStyleCheck.class);
42         checkConfig.addAttribute("checkFirstSentence", "true");
43         checkConfig.addAttribute("checkHtml", "false");
44         final String JavaDoc[] expected =
45         {
46             "20: First sentence should end with a period.",
47             "53: First sentence should end with a period.",
48             "74: First sentence should end with a period.",
49             "81: First sentence should end with a period.",
50             "88: First sentence should end with a period.",
51             "193: First sentence should end with a period.",
52             "238: First sentence should end with a period.",
53         };
54
55         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
56     }
57
58     public void testHtml() throws Exception JavaDoc
59     {
60         final DefaultConfiguration checkConfig = createCheckConfig(JavadocStyleCheck.class);
61         checkConfig.addAttribute("checkFirstSentence", "false");
62         checkConfig.addAttribute("checkHtml", "true");
63         final String JavaDoc[] expected =
64         {
65             "63:11: Unclosed HTML tag found: <b>This guy is missing end of bold tag",
66             "66:7: Extra HTML tag found: </td>Extra tag shouldn't be here",
67             "68:19: Unclosed HTML tag found: <code>dummy.",
68             "75:23: Unclosed HTML tag found: <b>should fail",
69             "82:31: Unclosed HTML tag found: <b>should fail",
70             "89:31: Extra HTML tag found: </code>",
71             "90: Incomplete HTML tag found: * should fail <",
72             "109:39: Extra HTML tag found: </img>",
73             "186:8: Unclosed HTML tag found: <blockquote>",
74         };
75
76         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
77     }
78
79     public void testScopePublic()
80         throws Exception JavaDoc
81     {
82         final DefaultConfiguration checkConfig =
83             createCheckConfig(JavadocStyleCheck.class);
84         checkConfig.addAttribute("checkFirstSentence", "true");
85         checkConfig.addAttribute("checkHtml", "true");
86         checkConfig.addAttribute("checkEmptyJavadoc", "true");
87         checkConfig.addAttribute("scope", "public");
88         final String JavaDoc[] expected =
89         {
90             "88: First sentence should end with a period.",
91             "89:31: Extra HTML tag found: </code>",
92             "90: Incomplete HTML tag found: * should fail <",
93             "205: Javadoc has empty description section.",
94             "230: Javadoc has empty description section.",
95             "238: First sentence should end with a period.",
96         };
97
98         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
99     }
100
101     public void testScopeProtected()
102         throws Exception JavaDoc
103     {
104         final DefaultConfiguration checkConfig =
105             createCheckConfig(JavadocStyleCheck.class);
106         checkConfig.addAttribute("checkFirstSentence", "true");
107         checkConfig.addAttribute("checkHtml", "true");
108         checkConfig.addAttribute("checkEmptyJavadoc", "true");
109         checkConfig.addAttribute("scope", "protected");
110         final String JavaDoc[] expected =
111         {
112             "74: First sentence should end with a period.",
113             "75:23: Unclosed HTML tag found: <b>should fail",
114             "88: First sentence should end with a period.",
115             "89:31: Extra HTML tag found: </code>",
116             "90: Incomplete HTML tag found: * should fail <",
117             "205: Javadoc has empty description section.",
118             "211: Javadoc has empty description section.",
119             "230: Javadoc has empty description section.",
120             "238: First sentence should end with a period.",
121         };
122
123         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
124     }
125
126     public void testScopePackage()
127         throws Exception JavaDoc
128     {
129         final DefaultConfiguration checkConfig =
130             createCheckConfig(JavadocStyleCheck.class);
131         checkConfig.addAttribute("checkFirstSentence", "true");
132         checkConfig.addAttribute("checkHtml", "true");
133         checkConfig.addAttribute("checkEmptyJavadoc", "true");
134         checkConfig.addAttribute("scope", "package");
135         final String JavaDoc[] expected =
136         {
137             "74: First sentence should end with a period.",
138             "75:23: Unclosed HTML tag found: <b>should fail",
139             "81: First sentence should end with a period.",
140             "82:31: Unclosed HTML tag found: <b>should fail",
141             "88: First sentence should end with a period.",
142             "89:31: Extra HTML tag found: </code>",
143             "90: Incomplete HTML tag found: * should fail <",
144             "205: Javadoc has empty description section.",
145             "211: Javadoc has empty description section.",
146             "218: Javadoc has empty description section.",
147             "230: Javadoc has empty description section.",
148             "238: First sentence should end with a period.",
149         };
150
151         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
152     }
153
154     public void testEmptyJavadoc() throws Exception JavaDoc
155     {
156         final DefaultConfiguration checkConfig = createCheckConfig(JavadocStyleCheck.class);
157         checkConfig.addAttribute("checkFirstSentence", "false");
158         checkConfig.addAttribute("checkHtml", "false");
159         checkConfig.addAttribute("checkEmptyJavadoc", "true");
160         final String JavaDoc[] expected =
161         {
162             "205: Javadoc has empty description section.",
163             "211: Javadoc has empty description section.",
164             "218: Javadoc has empty description section.",
165             "225: Javadoc has empty description section.",
166             "230: Javadoc has empty description section.",
167         };
168
169         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
170     }
171
172     public void testExcludeScope()
173         throws Exception JavaDoc
174     {
175         final DefaultConfiguration checkConfig =
176             createCheckConfig(JavadocStyleCheck.class);
177         checkConfig.addAttribute("scope", "private");
178         checkConfig.addAttribute("excludeScope", "protected");
179         final String JavaDoc[] expected =
180         {
181             "20: First sentence should end with a period.",
182             "53: First sentence should end with a period.",
183             "63:11: Unclosed HTML tag found: <b>This guy is missing end of bold tag",
184             "66:7: Extra HTML tag found: </td>Extra tag shouldn't be here",
185             "68:19: Unclosed HTML tag found: <code>dummy.",
186             "81: First sentence should end with a period.",
187             "82:31: Unclosed HTML tag found: <b>should fail",
188             "109:39: Extra HTML tag found: </img>",
189             "186:8: Unclosed HTML tag found: <blockquote>",
190             "193: First sentence should end with a period.",
191         };
192
193         verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
194     }
195 }
196
Popular Tags