1 package org.incava.doctorj; 2 3 import java.io.*; 4 import java.util.*; 5 import junit.framework.TestCase; 6 import org.incava.analysis.Violation; 7 8 9 public class TestParameterDocAnalyzer extends Tester 10 { 11 public TestParameterDocAnalyzer(String name) 12 { 13 super(name); 14 } 15 16 public void testMethodParametersOK() 17 { 18 evaluate("/** This is a description. */\n" + 19 "class Test {\n" + 20 " /** This is a description.\n" + 21 " */\n" + 22 " void method() {}\n" + 23 "}\n", 24 new Violation[] { 25 }); 26 27 evaluate("/** This is a description. */\n" + 28 "class Test {\n" + 29 " /** This is a description.\n" + 30 " * @param i This describes the i parameter.\n" + 31 " */\n" + 32 " void method(int i) {}\n" + 33 "}\n", 34 new Violation[] { 35 }); 36 } 37 38 public void testMethodParametersNoParamsInCode() 39 { 40 evaluate("/** This is a description. */\n" + 41 "class Test {\n" + 42 " /** This is a description.\n" + 43 " * @param\n" + 44 " */\n" + 45 " void method() {}\n" + 46 "}\n", 47 new Violation[] { 48 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 49 }); 50 51 evaluate("/** This is a description. */\n" + 52 "class Test {\n" + 53 " /** This is a description.\n" + 54 " * @param i\n" + 55 " */\n" + 56 " void method() {}\n" + 57 "}\n", 58 new Violation[] { 59 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 60 }); 61 62 evaluate("/** This is a description. */\n" + 63 "class Test {\n" + 64 " /** This is a description.\n" + 65 " * @param i This describes the i parameter.\n" + 66 " */\n" + 67 " void method() {}\n" + 68 "}\n", 69 new Violation[] { 70 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 71 }); 72 73 evaluate("/** This is a description. */\n" + 74 "class Test {\n" + 75 " /** This is a description.\n" + 76 " * @param i This describes the i parameter.\n" + 77 " * @param j This describes the j parameter.\n" + 78 " */\n" + 79 " void method() {}\n" + 80 "}\n", 81 new Violation[] { 82 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 84 }); 85 86 evaluate("/** This is a description. */\n" + 87 "class Test {\n" + 88 " /** This is a description.\n" + 89 " * @param i This describes the i parameter.\n" + 90 " * @param j This describes the j parameter.\n" + 91 " * @param k This describes the k parameter.\n" + 92 " * @param l This describes the l parameter.\n" + 93 " * @param m This describes the m parameter.\n" + 94 " */\n" + 95 " void method() {}\n" + 96 "}\n", 97 new Violation[] { 98 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 100 }); 101 } 102 103 public void testMethodParametersParamWithoutTarget() 104 { 105 evaluate("/** This is a description. */\n" + 106 "class Test {\n" + 107 " /** This is a description.\n" + 108 " * @param\n" + 109 " */\n" + 110 " void method(int i) {}\n" + 111 "}\n", 112 new Violation[] { 113 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_WITHOUT_NAME, 4, 9, 4, 14), 114 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 21, 6, 21) 115 }); 116 } 117 118 public void testMethodParametersParamMisspelled() 119 { 120 evaluate("/** This is a description. */\n" + 121 "class Test {\n" + 122 " /** This is a description.\n" + 123 " * @param st The string in question.\n" + 124 " */\n" + 125 " void method(String str) {}\n" + 126 "}\n", 127 new Violation[] { 128 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_MISSPELLED, 4, 16, 4, 17) 129 }); 130 131 evaluate("/** This is a description. */\n" + 132 "class Test {\n" + 133 " /** This is a description.\n" + 134 " * @param s The string in question.\n" + 135 " */\n" + 136 " void method(String str) {}\n" + 137 "}\n", 138 new Violation[] { 139 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_MISSPELLED, 4, 16, 4, 16) 140 }); 141 } 142 143 public void testMethodParametersParamNotDocumented() 144 { 145 evaluate("/** This is a description. */\n" + 146 "class Test {\n" + 147 " /** This is a description.\n" + 148 " * @param comp A Comparator of some sort.\n" + 149 " */\n" + 150 " void method(String str, Comparator comp) {}\n" + 151 "}\n", 152 new Violation[] { 153 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 24, 6, 26) 154 }); 155 156 evaluate("/** This is a description. */\n" + 157 "class Test {\n" + 158 " /** This is a description.\n" + 159 " * @param price The price of tea in China.\n" + 160 " */\n" + 161 " void method(String str, int price, Comparator comp) {}\n" + 162 "}\n", 163 new Violation[] { 164 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 24, 6, 26), 165 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 51, 6, 54) 166 }); 167 } 168 169 public void testMethodParametersMisordered() 170 { 171 evaluate("/** This is a description. */\n" + 172 "class Test {\n" + 173 " /** This is a description.\n" + 174 " * @param comp A Comparator of some sort.\n" + 175 " * @param str The string in question.\n" + 176 " */\n" + 177 " void method(String str, Comparator comp) {}\n" + 178 "}\n", 179 new Violation[] { 180 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_IN_CODE_ORDER, 5, 16, 5, 18) 181 }); 182 183 evaluate("/** This is a description. */\n" + 184 "class Test {\n" + 185 " /** This is a description.\n" + 186 " * @param size The height and width of something.\n" + 187 " * @param comp A Comparator of some sort.\n" + 188 " * @param str The string in question.\n" + 189 " */\n" + 190 " void method(java.awt.Dimension size, String str, Comparator comp) {}\n" + 191 "}\n", 192 new Violation[] { 193 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_IN_CODE_ORDER, 6, 16, 6, 18) 194 }); 195 } 196 197 public void testMethodParametersTypeUsed() 198 { 199 evaluate("/** This is a description. */\n" + 200 "class Test {\n" + 201 " /** This is a description.\n" + 202 " * @param String The string in question.\n" + 203 " */\n" + 204 " void method(String str) {}\n" + 205 "}\n", 206 new Violation[] { 207 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 4, 16, 4, 21) 208 }); 209 210 evaluate("/** This is a description. */\n" + 211 "class Test {\n" + 212 " /** This is a description.\n" + 213 " * @param String The string in question.\n" + 214 " * @param Comparator A Comparator of some sort.\n" + 215 " */\n" + 216 " void method(String str, Comparator comp) {}\n" + 217 "}\n", 218 new Violation[] { 219 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 4, 16, 4, 21), 220 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 5, 16, 5, 25) 221 }); 222 } 223 224 226 public void testCtorParametersOK() 227 { 228 evaluate("/** This is a description. */\n" + 229 "class Test {\n" + 230 " /** This is a description.\n" + 231 " */\n" + 232 " Test() {}\n" + 233 "}\n", 234 new Violation[] { 235 }); 236 237 evaluate("/** This is a description. */\n" + 238 "class Test {\n" + 239 " /** This is a description.\n" + 240 " * @param i This describes the i parameter.\n" + 241 " */\n" + 242 " Test(int i) {}\n" + 243 "}\n", 244 new Violation[] { 245 }); 246 } 247 248 public void testCtorParametersNoParamsInCode() 249 { 250 evaluate("/** This is a description. */\n" + 251 "class Test {\n" + 252 " /** This is a description.\n" + 253 " * @param\n" + 254 " */\n" + 255 " Test() {}\n" + 256 "}\n", 257 new Violation[] { 258 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 259 }); 260 261 evaluate("/** This is a description. */\n" + 262 "class Test {\n" + 263 " /** This is a description.\n" + 264 " * @param i\n" + 265 " */\n" + 266 " Test() {}\n" + 267 "}\n", 268 new Violation[] { 269 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 270 }); 271 272 evaluate("/** This is a description. */\n" + 273 "class Test {\n" + 274 " /** This is a description.\n" + 275 " * @param i This describes the i parameter.\n" + 276 " */\n" + 277 " Test() {}\n" + 278 "}\n", 279 new Violation[] { 280 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 281 }); 282 283 evaluate("/** This is a description. */\n" + 284 "class Test {\n" + 285 " /** This is a description.\n" + 286 " * @param i This describes the i parameter.\n" + 287 " * @param j This describes the j parameter.\n" + 288 " */\n" + 289 " Test() {}\n" + 290 "}\n", 291 new Violation[] { 292 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 294 }); 295 296 evaluate("/** This is a description. */\n" + 297 "class Test {\n" + 298 " /** This is a description.\n" + 299 " * @param i This describes the i parameter.\n" + 300 " * @param j This describes the j parameter.\n" + 301 " * @param k This describes the k parameter.\n" + 302 " * @param l This describes the l parameter.\n" + 303 " * @param m This describes the m parameter.\n" + 304 " */\n" + 305 " Test() {}\n" + 306 "}\n", 307 new Violation[] { 308 new Violation(ParameterDocAnalyzer.MSG_PARAMETERS_DOCUMENTED_BUT_NO_CODE_PARAMETERS, 4, 9, 4, 14) 310 }); 311 } 312 313 public void testCtorParametersParamWithoutTarget() 314 { 315 evaluate("/** This is a description. */\n" + 316 "class Test {\n" + 317 " /** This is a description.\n" + 318 " * @param\n" + 319 " */\n" + 320 " Test(int i) {}\n" + 321 "}\n", 322 new Violation[] { 323 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_WITHOUT_NAME, 4, 9, 4, 14), 324 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 14, 6, 14) 325 }); 326 } 327 328 public void testCtorParametersParamMisspelled() 329 { 330 evaluate("/** This is a description. */\n" + 331 "class Test {\n" + 332 " /** This is a description.\n" + 333 " * @param st The string in question.\n" + 334 " */\n" + 335 " Test(String str) {}\n" + 336 "}\n", 337 new Violation[] { 338 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_MISSPELLED, 4, 16, 4, 17) 339 }); 340 341 evaluate("/** This is a description. */\n" + 342 "class Test {\n" + 343 " /** This is a description.\n" + 344 " * @param s The string in question.\n" + 345 " */\n" + 346 " Test(String str) {}\n" + 347 "}\n", 348 new Violation[] { 349 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_MISSPELLED, 4, 16, 4, 16) 350 }); 351 } 352 353 public void testCtorParametersParamNotDocumented() 354 { 355 evaluate("/** This is a description. */\n" + 356 "class Test {\n" + 357 " /** This is a description.\n" + 358 " * @param comp A Comparator of some sort.\n" + 359 " */\n" + 360 " Test(String str, Comparator comp) {}\n" + 361 "}\n", 362 new Violation[] { 363 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 17, 6, 19) 364 }); 365 366 evaluate("/** This is a description. */\n" + 367 "class Test {\n" + 368 " /** This is a description.\n" + 369 " * @param price The price of tea in China.\n" + 370 " */\n" + 371 " Test(String str, int price, Comparator comp) {}\n" + 372 "}\n", 373 new Violation[] { 374 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 17, 6, 19), 375 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_DOCUMENTED, 6, 44, 6, 47) 376 }); 377 } 378 379 public void testCtorParametersMisordered() 380 { 381 evaluate("/** This is a description. */\n" + 382 "class Test {\n" + 383 " /** This is a description.\n" + 384 " * @param comp A Comparator of some sort.\n" + 385 " * @param str The string in question.\n" + 386 " */\n" + 387 " Test(String str, Comparator comp) {}\n" + 388 "}\n", 389 new Violation[] { 390 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_IN_CODE_ORDER, 5, 16, 5, 18) 391 }); 392 393 evaluate("/** This is a description. */\n" + 394 "class Test {\n" + 395 " /** This is a description.\n" + 396 " * @param size The height and width of something.\n" + 397 " * @param comp A Comparator of some sort.\n" + 398 " * @param str The string in question.\n" + 399 " */\n" + 400 " Test(java.awt.Dimension size, String str, Comparator comp) {}\n" + 401 "}\n", 402 new Violation[] { 403 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_IN_CODE_ORDER, 6, 16, 6, 18) 404 }); 405 } 406 407 public void testCtorParametersTypeUsed() 408 { 409 evaluate("/** This is a description. */\n" + 410 "class Test {\n" + 411 " /** This is a description.\n" + 412 " * @param String The string in question.\n" + 413 " */\n" + 414 " Test(String str) {}\n" + 415 "}\n", 416 new Violation[] { 417 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 4, 16, 4, 21) 418 }); 419 420 evaluate("/** This is a description. */\n" + 421 "class Test {\n" + 422 " /** This is a description.\n" + 423 " * @param String The string in question.\n" + 424 " * @param Comparator A Comparator of some sort.\n" + 425 " */\n" + 426 " Test(String str, Comparator comp) {}\n" + 427 "}\n", 428 new Violation[] { 429 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 4, 16, 4, 21), 430 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_TYPE_USED, 5, 16, 5, 25) 431 }); 432 } 433 434 public void testParamterNotInCode() 435 { 436 evaluate("/** This is a description. */\n" + 437 "class Test {\n" + 438 " /**\n" + 439 " * Calculate the bundles along the search path from the base bundle to the\n" + 440 " * bundle specified by baseName and locale.\n" + 441 " * @param baseName the base bundle name\n" + 442 " * @param locale the locale\n" + 443 " * @param names the vector used to return the names of the bundles along\n" + 444 " * the search path.\n" + 445 " *\n" + 446 " */\n" + 447 " private static Vector calculateBundleNames(String baseName, Locale locale) {\n" + 448 " }\n" + 449 "\n" + 450 "}\n", 451 new Violation[] { 452 new Violation(ParameterDocAnalyzer.MSG_PARAMETER_NOT_IN_CODE, 8, 15, 8, 19) 453 }, 454 "1.5"); 455 } 456 } 457 458 | Popular Tags |