1 package com.puppycrawl.tools.checkstyle.checks.javadoc; 2 3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; 4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration; 5 import com.puppycrawl.tools.checkstyle.api.Scope; 6 7 import java.io.File ; 8 9 17 public class JavadocTypeCheckTest extends BaseCheckTestCase 18 { 19 public void testTags() throws Exception 20 { 21 final DefaultConfiguration checkConfig = 22 createCheckConfig(JavadocTypeCheck.class); 23 final String [] expected = 24 { 25 "8: Missing a Javadoc comment.", 26 "302: Missing a Javadoc comment.", 27 "327: Missing a Javadoc comment.", 28 }; 29 verify(checkConfig, getPath("InputTags.java"), expected); 30 } 31 32 public void testInner() throws Exception 33 { 34 final DefaultConfiguration checkConfig = 35 createCheckConfig(JavadocTypeCheck.class); 36 final String [] expected = 37 { 38 "14: Missing a Javadoc comment.", 39 "21: Missing a Javadoc comment.", 40 "27: Missing a Javadoc comment.", 41 }; 42 verify(checkConfig, getPath("InputInner.java"), expected); 43 } 44 45 public void testStrict() throws Exception 46 { 47 final DefaultConfiguration checkConfig = 48 createCheckConfig(JavadocTypeCheck.class); 49 final String [] expected = 50 { 51 "7: Missing a Javadoc comment.", 52 "9: Missing a Javadoc comment.", 53 "14: Missing a Javadoc comment.", 54 "34: Missing a Javadoc comment.", 55 }; 56 verify(checkConfig, getPath("InputPublicOnly.java"), expected); 57 } 58 59 public void testProtected() throws Exception 60 { 61 final DefaultConfiguration checkConfig = 62 createCheckConfig(JavadocTypeCheck.class); 63 checkConfig.addAttribute("scope", Scope.PROTECTED.getName()); 64 final String [] expected = 65 { 66 "7: Missing a Javadoc comment.", 67 }; 68 verify(checkConfig, getPath("InputPublicOnly.java"), expected); 69 } 70 71 public void testPublic() throws Exception 72 { 73 final DefaultConfiguration checkConfig = 74 createCheckConfig(JavadocTypeCheck.class); 75 checkConfig.addAttribute("scope", Scope.PUBLIC.getName()); 76 final String [] expected = 77 { 78 "7: Missing a Javadoc comment.", 79 "38: Missing a Javadoc comment.", 80 }; 81 verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); 82 } 83 84 public void testProtest() throws Exception 85 { 86 final DefaultConfiguration checkConfig = 87 createCheckConfig(JavadocTypeCheck.class); 88 checkConfig.addAttribute("scope", Scope.PROTECTED.getName()); 89 final String [] expected = 90 { 91 "7: Missing a Javadoc comment.", 92 "29: Missing a Javadoc comment.", 93 "38: Missing a Javadoc comment.", 94 "65: Missing a Javadoc comment.", 95 }; 96 verify(checkConfig, getPath("InputScopeInnerInterfaces.java"), expected); 97 } 98 99 public void testPkg() throws Exception 100 { 101 final DefaultConfiguration checkConfig = 102 createCheckConfig(JavadocTypeCheck.class); 103 checkConfig.addAttribute( 104 "scope", 105 Scope.getInstance("package").getName()); 106 final String [] expected = 107 { 108 "18: Missing a Javadoc comment.", 109 "20: Missing a Javadoc comment.", 110 "22: Missing a Javadoc comment.", 111 }; 112 verify(checkConfig, getPath("InputScopeInnerClasses.java"), expected); 113 } 114 115 public void testEclipse() throws Exception 116 { 117 final DefaultConfiguration checkConfig = 118 createCheckConfig(JavadocTypeCheck.class); 119 checkConfig.addAttribute( 120 "scope", 121 Scope.getInstance("public").getName()); 122 final String [] expected = 123 { 124 "18: Missing a Javadoc comment.", 125 }; 126 verify(checkConfig, getPath("InputScopeInnerClasses.java"), expected); 127 } 128 129 public void testAuthorRequired() throws Exception 130 { 131 final DefaultConfiguration checkConfig = 132 createCheckConfig(JavadocTypeCheck.class); 133 checkConfig.addAttribute("authorFormat", "\\S"); 134 final String [] expected = 135 { 136 "13: Type Javadoc comment is missing an @author tag.", 137 }; 138 verify(checkConfig, getPath("InputWhitespace.java"), expected); 139 } 140 141 public void testAuthorRegularEx() 142 throws Exception 143 { 144 final DefaultConfiguration checkConfig = 145 createCheckConfig(JavadocTypeCheck.class); 146 checkConfig.addAttribute("authorFormat", "0*"); 147 final String [] expected = { 148 "22: Type Javadoc comment is missing an @author tag.", 149 "58: Type Javadoc comment is missing an @author tag.", 150 "94: Type Javadoc comment is missing an @author tag.", 151 }; 152 verify(checkConfig, getPath("InputJavadoc.java"), expected); 153 } 154 155 public void testAuthorRegularExError() 156 throws Exception 157 { 158 final DefaultConfiguration checkConfig = 159 createCheckConfig(JavadocTypeCheck.class); 160 checkConfig.addAttribute("authorFormat", "ABC"); 161 final String [] expected = { 162 "13: Type Javadoc tag @author must match pattern 'ABC'.", 163 "22: Type Javadoc comment is missing an @author tag.", 164 "31: Type Javadoc tag @author must match pattern 'ABC'.", 165 "49: Type Javadoc tag @author must match pattern 'ABC'.", 166 "58: Type Javadoc comment is missing an @author tag.", 167 "67: Type Javadoc tag @author must match pattern 'ABC'.", 168 "85: Type Javadoc tag @author must match pattern 'ABC'.", 169 "94: Type Javadoc comment is missing an @author tag.", 170 "103: Type Javadoc tag @author must match pattern 'ABC'.", 171 }; 172 verify(checkConfig, getPath("InputJavadoc.java"), expected); 173 } 174 175 public void testVersionRequired() 176 throws Exception 177 { 178 final DefaultConfiguration checkConfig = 179 createCheckConfig(JavadocTypeCheck.class); 180 checkConfig.addAttribute("versionFormat", "\\S"); 181 final String [] expected = { 182 "13: Type Javadoc comment is missing an @version tag.", 183 }; 184 verify(checkConfig, getPath("InputWhitespace.java"), expected); 185 } 186 187 public void testVersionRegularEx() 188 throws Exception 189 { 190 final DefaultConfiguration checkConfig = 191 createCheckConfig(JavadocTypeCheck.class); 192 checkConfig.addAttribute("versionFormat", "^\\p{Digit}+\\.\\p{Digit}+$"); 193 final String [] expected = { 194 "22: Type Javadoc comment is missing an @version tag.", 195 "58: Type Javadoc comment is missing an @version tag.", 196 "94: Type Javadoc comment is missing an @version tag.", 197 }; 198 verify(checkConfig, getPath("InputJavadoc.java"), expected); 199 } 200 201 public void testVersionRegularExError() 202 throws Exception 203 { 204 final DefaultConfiguration checkConfig = 205 createCheckConfig(JavadocTypeCheck.class); 206 checkConfig.addAttribute("versionFormat", "\\$Revision.*\\$"); 207 final String [] expected = { 208 "13: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 209 "22: Type Javadoc comment is missing an @version tag.", 210 "31: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 211 "40: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 212 "49: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 213 "58: Type Javadoc comment is missing an @version tag.", 214 "67: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 215 "76: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 216 "85: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 217 "94: Type Javadoc comment is missing an @version tag.", 218 "103: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 219 "112: Type Javadoc tag @version must match pattern '\\$Revision.*\\$'.", 220 }; 221 verify(checkConfig, getPath("InputJavadoc.java"), expected); 222 } 223 224 public void testScopes() throws Exception 225 { 226 final DefaultConfiguration checkConfig = 227 createCheckConfig(JavadocTypeCheck.class); 228 final String [] expected = { 229 "1: Missing a Javadoc comment.", 230 "13: Missing a Javadoc comment.", 231 "25: Missing a Javadoc comment.", 232 "37: Missing a Javadoc comment.", 233 "50: Missing a Javadoc comment.", 234 "61: Missing a Javadoc comment.", 235 "73: Missing a Javadoc comment.", 236 "85: Missing a Javadoc comment.", 237 "97: Missing a Javadoc comment.", 238 }; 239 verify(checkConfig, 240 getPath("javadoc" + File.separator +"InputNoJavadoc.java"), 241 expected); 242 } 243 244 public void testScopes2() throws Exception 245 { 246 final DefaultConfiguration checkConfig = 247 createCheckConfig(JavadocTypeCheck.class); 248 checkConfig.addAttribute("scope", Scope.PROTECTED.getName()); 249 final String [] expected = { 250 "1: Missing a Javadoc comment.", 251 "13: Missing a Javadoc comment.", 252 }; 253 verify(checkConfig, 254 getPath("javadoc" + File.separator +"InputNoJavadoc.java"), 255 expected); 256 } 257 258 public void testExcludeScope() throws Exception 259 { 260 final DefaultConfiguration checkConfig = 261 createCheckConfig(JavadocTypeCheck.class); 262 checkConfig.addAttribute("scope", Scope.PRIVATE.getName()); 263 checkConfig.addAttribute("excludeScope", Scope.PROTECTED.getName()); 264 final String [] expected = { 265 "25: Missing a Javadoc comment.", 266 "37: Missing a Javadoc comment.", 267 "50: Missing a Javadoc comment.", 268 "61: Missing a Javadoc comment.", 269 "73: Missing a Javadoc comment.", 270 "85: Missing a Javadoc comment.", 271 "97: Missing a Javadoc comment.", 272 }; 273 verify(checkConfig, 274 getPath("javadoc" + File.separator +"InputNoJavadoc.java"), 275 expected); 276 } 277 278 public void testTypeParameters() throws Exception 279 { 280 final DefaultConfiguration checkConfig = 281 createCheckConfig(JavadocTypeCheck.class); 282 final String [] expected = { 283 "7:4: Unused @param tag for '<D123>'.", 284 "11: Type Javadoc comment is missing an @param <C456> tag.", 285 }; 286 verify(checkConfig, getPath("InputTypeParamsTags.java"), expected); 287 } 288 public void testAllowMissingTypeParameters() throws Exception 289 { 290 final DefaultConfiguration checkConfig = 291 createCheckConfig(JavadocTypeCheck.class); 292 checkConfig.addAttribute("allowMissingParamTags", "true"); 293 final String [] expected = { 294 "7:4: Unused @param tag for '<D123>'.", 295 }; 296 verify(checkConfig, getPath("InputTypeParamsTags.java"), expected); 297 } 298 } 299 | Popular Tags |