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 TestOptions extends Tester 10 { 11 public TestOptions(String name) 12 { 13 super(name); 14 } 15 16 public void runTest(int violationLevel, String [] contents, String [] messages, int[] beginLine, int[] beginColumn, int[] endLine, int[] endColumn) 17 { 18 for (int level = -1; level < 9; ++level) { 19 Options.warningLevel = level; 20 21 tr.Ace.yellow("level: " + level); 22 23 for (int ci = 0; ci < contents.length; ++ci) { 24 String cont = contents[ci]; 25 String msg = messages.length > 1 ? messages[ci] : messages[0]; 26 int bgLn = beginLine.length > 1 ? beginLine[ci] : beginLine[0]; 27 int bgCol = beginColumn.length > 1 ? beginColumn[ci] : beginColumn[0]; 28 int endLn = endLine.length > 1 ? endLine[ci] : endLine[0]; 29 int endCol = endColumn.length > 1 ? endColumn[ci] : endColumn[0]; 30 31 tr.Ace.yellow("msg", msg); 32 tr.Ace.yellow("violationLevel + 3 - ci: " + (violationLevel + 3 - ci)); 33 34 List expected = new ArrayList(); 35 36 Violation[] violations = new Violation[0]; 37 38 if (level >= 0 && violationLevel + 3 - ci <= level) { 39 violations = new Violation[] { 40 new Violation(msg, bgLn, bgCol, endLn, endCol) 41 }; 42 } 43 44 evaluate(contents[ci], violations); 45 } 46 } 47 } 48 49 public void testDocumented() 50 { 51 runTest(ItemDocAnalyzer.CHKLVL_DOC_EXISTS, 52 new String [] { 53 "/** This is a description.\n" + 54 " */\n" + 55 "class Test {\n" + 56 " private class Inner {\n" + 57 " }\n" + 58 "}\n", 59 60 "class Test {\n" + 61 "}\n", 62 63 "/** This is a description.\n" + 64 " */\n" + 65 "class Test {\n" + 66 " protected class Inner {\n" + 67 " }\n" + 68 "}\n", 69 70 "public class TestHasJavadoc {\n" + 71 "}\n" 72 }, 73 74 new String [] { 75 "Undocumented private class", 76 "Undocumented class", 77 "Undocumented protected class", 78 "Undocumented public class" 79 }, 80 81 new int[] { 4, 1, 4, 1 }, new int[] { 19, 7, 21, 14 }, new int[] { 4, 1, 4, 1 }, new int[] { 23, 10, 25, 27 }); } 86 87 public void testSummarySentence() 88 { 89 runTest(ItemDocAnalyzer.CHKLVL_SUMMARY_SENTENCE, 90 new String [] { 91 "/** This is a description.\n" + 92 " */\n" + 93 "class Test {\n" + 94 " /** Too short. */\n" + 95 " private class Inner {\n" + 96 " }\n" + 97 "}\n", 98 99 "/** Too short. */\n" + 100 "class Test {\n" + 101 "}\n", 102 103 "/** This is a description.\n" + 104 " */\n" + 105 "class Test {\n" + 106 " /** Too short. */\n" + 107 " protected class Inner {\n" + 108 " }\n" + 109 "}\n", 110 111 "/** Too short. */\n" + 112 "public class TestHasJavadoc {\n" + 113 "}\n" 114 }, 115 116 new String [] { 117 ItemDocAnalyzer.MSG_SUMMARY_SENTENCE_TOO_SHORT 118 }, 119 120 new int[] { 4, 1, 4, 1 }, new int[] { 9, 5, 9, 5 }, new int[] { 4, 1, 4, 1 }, 123 new int[] { 18, 14, 18, 14 }); 124 } 125 126 public void testClassTagOrder() 127 { 128 runTest(ItemDocAnalyzer.CHKLVL_MISORDERED_TAGS, 129 new String [] { 130 "/** This is a description.\n" + 131 " */\n" + 132 "class Test {\n" + 133 " /**\n" + 134 " * This is a description. \n" + 135 " * @version 0.1.2 \n" + 136 " * @author me \n" + 137 " */\n" + 138 " private class Inner {\n" + 139 " }\n" + 140 "}\n", 141 142 "/** This is a description.\n" + 143 " */\n" + 144 "class Test {\n" + 145 " /**\n" + 146 " * This is a description. \n" + 147 " * @version 0.1.2 \n" + 148 " * @author me \n" + 149 " */\n" + 150 " class Inner {\n" + 151 " }\n" + 152 "}\n", 153 154 "/** This is a description.\n" + 155 " */\n" + 156 "class Test {\n" + 157 " /**\n" + 158 " * This is a description. \n" + 159 " * @version 0.1.2 \n" + 160 " * @author me \n" + 161 " */\n" + 162 " protected class Inner {\n" + 163 " }\n" + 164 "}\n", 165 166 "/** This is a description.\n" + 167 " */\n" + 168 "class Test {\n" + 169 " /**\n" + 170 " * This is a description. \n" + 171 " * @version 0.1.2 \n" + 172 " * @author me \n" + 173 " */\n" + 174 " public class Inner {\n" + 175 " }\n" + 176 "}\n", 177 }, 178 179 new String [] { 180 ItemDocAnalyzer.MSG_TAG_IMPROPER_ORDER 181 }, 182 new int[] { 7 }, 183 new int[] { 9 }, 184 new int[] { 7 }, 185 new int[] { 15 }); 186 } 187 188 public void testMethodTagOrder() 189 { 190 runTest(ItemDocAnalyzer.CHKLVL_MISORDERED_TAGS, 191 new String [] { 192 "/** This is a description.\n" + 193 " */\n" + 194 "class Test {\n" + 195 " /**\n" + 196 " * This is a description. \n" + 197 " * @since 0.1.2 \n" + 198 " * @see Something#else() \n" + 199 " */\n" + 200 " private void f() {}\n" + 201 "}\n", 202 203 "/** This is a description.\n" + 204 " */\n" + 205 "class Test {\n" + 206 " /**\n" + 207 " * This is a description. \n" + 208 " * @since 0.1.2 \n" + 209 " * @see Something#else() \n" + 210 " */\n" + 211 " void f() {}\n" + 212 "}\n", 213 214 "/** This is a description.\n" + 215 " */\n" + 216 "class Test {\n" + 217 " /**\n" + 218 " * This is a description. \n" + 219 " * @since 0.1.2 \n" + 220 " * @see Something#else() \n" + 221 " */\n" + 222 " protected void f() {}\n" + 223 "}\n", 224 225 "/** This is a description.\n" + 226 " */\n" + 227 "class Test {\n" + 228 " /**\n" + 229 " * This is a description. \n" + 230 " * @since 0.1.2 \n" + 231 " * @see Something#else() \n" + 232 " */\n" + 233 " public void f() {}\n" + 234 "}\n", 235 }, 236 237 new String [] { 238 ItemDocAnalyzer.MSG_TAG_IMPROPER_ORDER 239 }, 240 new int[] { 7 }, 241 new int[] { 9 }, 242 new int[] { 7 }, 243 new int[] { 12 }); 244 } 245 246 public void testMethodValidTags() 247 { 248 runTest(ItemDocAnalyzer.CHKLVL_VALID_TAGS, 249 new String [] { 250 "/** This is a description.\n" + 251 " */\n" + 252 "class Test {\n" + 253 " /**\n" + 254 " * This is a description. \n" + 255 " * @version 0.1.2 \n" + 256 " */\n" + 257 " private void f() {}\n" + 258 "}\n", 259 260 "/** This is a description.\n" + 261 " */\n" + 262 "class Test {\n" + 263 " /**\n" + 264 " * This is a description. \n" + 265 " * @version 0.1.2 \n" + 266 " */\n" + 267 " void f() {}\n" + 268 "}\n", 269 270 "/** This is a description.\n" + 271 " */\n" + 272 "class Test {\n" + 273 " /**\n" + 274 " * This is a description. \n" + 275 " * @version 0.1.2 \n" + 276 " */\n" + 277 " protected void f() {}\n" + 278 "}\n", 279 280 "/** This is a description.\n" + 281 " */\n" + 282 "class Test {\n" + 283 " /**\n" + 284 " * This is a description. \n" + 285 " * @version 0.1.2 \n" + 286 " */\n" + 287 " public void f() {}\n" + 288 "}\n", 289 }, 290 291 new String [] { 292 "Tag not valid for method" 293 }, 294 new int[] { 6 }, 295 new int[] { 9 }, 296 new int[] { 6 }, 297 new int[] { 16 }); 298 } 299 300 public void testClassTagContent() 301 { 302 runTest(ItemDocAnalyzer.CHKLVL_TAG_CONTENT, 303 new String [] { 304 "/** This is a description.\n" + 305 " */\n" + 306 "class Test {\n" + 307 " /**\n" + 308 " * This is a description. \n" + 309 " * @version \n" + 310 " */\n" + 311 " private class Inner {\n" + 312 " }\n" + 313 "}\n", 314 315 "/** This is a description.\n" + 316 " */\n" + 317 "class Test {\n" + 318 " /**\n" + 319 " * This is a description. \n" + 320 " * @version \n" + 321 " */\n" + 322 " class Inner {\n" + 323 " }\n" + 324 "}\n", 325 326 "/** This is a description.\n" + 327 " */\n" + 328 "class Test {\n" + 329 " /**\n" + 330 " * This is a description. \n" + 331 " * @version \n" + 332 " */\n" + 333 " protected class Inner {\n" + 334 " }\n" + 335 "}\n", 336 337 "/** This is a description.\n" + 338 " */\n" + 339 "class Test {\n" + 340 " /**\n" + 341 " * This is a description. \n" + 342 " * @version \n" + 343 " */\n" + 344 " public class Inner {\n" + 345 " }\n" + 346 "}\n", 347 }, 348 349 new String [] { 350 TypeDocAnalyzer.MSG_VERSION_WITHOUT_TEXT 351 }, 352 new int[] { 6 }, 353 new int[] { 9 }, 354 new int[] { 6 }, 355 new int[] { 16 }); 356 } 357 358 public void testMethodTags() 359 { 360 runTest(ItemDocAnalyzer.CHKLVL_TAG_CONTENT, 361 new String [] { 362 "/** This is a description.\n" + 363 " */\n" + 364 "class Test {\n" + 365 " /**\n" + 366 " * This is a description. \n" + 367 " * @return \n" + 368 " */\n" + 369 " private int f() { return 1; }\n" + 370 "}\n", 371 372 "/** This is a description.\n" + 373 " */\n" + 374 "class Test {\n" + 375 " /**\n" + 376 " * This is a description. \n" + 377 " * @return \n" + 378 " */\n" + 379 " int f() { return 1; }\n" + 380 "}\n", 381 382 "/** This is a description.\n" + 383 " */\n" + 384 "class Test {\n" + 385 " /**\n" + 386 " * This is a description. \n" + 387 " * @return \n" + 388 " */\n" + 389 " protected int f() { return 1; }\n" + 390 "}\n", 391 392 "/** This is a description.\n" + 393 " */\n" + 394 "class Test {\n" + 395 " /**\n" + 396 " * This is a description. \n" + 397 " * @return \n" + 398 " */\n" + 399 " public int f() { return 1; }\n" + 400 "}\n", 401 }, 402 403 new String [] { 404 MethodDocAnalyzer.MSG_RETURN_WITHOUT_DESCRIPTION 405 }, 406 new int[] { 6 }, 407 new int[] { 9 }, 408 new int[] { 6 }, 409 new int[] { 15 }); 410 } 411 412 public void testMethodParameters() 413 { 414 runTest(ItemDocAnalyzer.CHKLVL_TAG_CONTENT, 415 new String [] { 416 "/** This is a description.\n" + 417 " */\n" + 418 "class Test {\n" + 419 " /**\n" + 420 " * This is a description. \n" + 421 " * @param i \n" + 422 " */\n" + 423 " private int f(int i) { return 1; }\n" + 424 "}\n", 425 426 "/** This is a description.\n" + 427 " */\n" + 428 "class Test {\n" + 429 " /**\n" + 430 " * This is a description. \n" + 431 " * @param i \n" + 432 " */\n" + 433 " int f(int i) { return 1; }\n" + 434 "}\n", 435 436 "/** This is a description.\n" + 437 " */\n" + 438 "class Test {\n" + 439 " /**\n" + 440 " * This is a description. \n" + 441 " * @param i \n" + 442 " */\n" + 443 " protected int f(int i) { return 1; }\n" + 444 "}\n", 445 446 "/** This is a description.\n" + 447 " */\n" + 448 "class Test {\n" + 449 " /**\n" + 450 " * This is a description. \n" + 451 " * @param i \n" + 452 " */\n" + 453 " public int f(int i) { return 1; }\n" + 454 "}\n", 455 }, 456 457 new String [] { 458 ParameterDocAnalyzer.MSG_PARAMETER_WITHOUT_DESCRIPTION 459 }, 460 new int[] { 6 }, 461 new int[] { 16 }, 462 new int[] { 6 }, 463 new int[] { 16 }); 464 } 465 466 public void testMethodExceptions() 467 { 468 runTest(ItemDocAnalyzer.CHKLVL_TAG_CONTENT, 469 new String [] { 470 "/** This is a description.\n" + 471 " */\n" + 472 "class Test {\n" + 473 " /**\n" + 474 " * This is a description. \n" + 475 " * @throws IOException \n" + 476 " */\n" + 477 " private int f() throws IOException { return 1; }\n" + 478 "}\n", 479 480 "/** This is a description.\n" + 481 " */\n" + 482 "class Test {\n" + 483 " /**\n" + 484 " * This is a description. \n" + 485 " * @throws IOException \n" + 486 " */\n" + 487 " int f() throws IOException { return 1; }\n" + 488 "}\n", 489 490 "/** This is a description.\n" + 491 " */\n" + 492 "class Test {\n" + 493 " /**\n" + 494 " * This is a description. \n" + 495 " * @throws IOException \n" + 496 " */\n" + 497 " protected int f() throws IOException { return 1; }\n" + 498 "}\n", 499 500 "/** This is a description.\n" + 501 " */\n" + 502 "class Test {\n" + 503 " /**\n" + 504 " * This is a description. \n" + 505 " * @throws IOException \n" + 506 " */\n" + 507 " public int f() throws IOException { return 1; }\n" + 508 "}\n", 509 }, 510 511 new String [] { 512 ExceptionDocAnalyzer.MSG_EXCEPTION_WITHOUT_DESCRIPTION 513 }, 514 new int[] { 6 }, 515 new int[] { 17 }, 516 new int[] { 6 }, 517 new int[] { 27 }); 518 } 519 520 public void testFieldDoc() 521 { 522 runTest(ItemDocAnalyzer.CHKLVL_TAG_CONTENT, 523 new String [] { 524 "/** This is a description. */\n" + 525 "class Test {\n" + 526 " /** This is a description.\n" + 527 " * @serialField one int " + 528 " */\n" + 529 " private ObjectStreamField[] serialPersistentFields = { \n" + 530 " new ObjectStreamField(\"one\", Integer.TYPE) \n" + 531 " };\n" + 532 "}\n", 533 534 "/** This is a description. */\n" + 535 "class Test {\n" + 536 " /** This is a description.\n" + 537 " * @serialField one int " + 538 " */\n" + 539 " ObjectStreamField[] serialPersistentFields = { \n" + 540 " new ObjectStreamField(\"one\", Integer.TYPE) \n" + 541 " };\n" + 542 "}\n", 543 544 "/** This is a description. */\n" + 545 "class Test {\n" + 546 " /** This is a description.\n" + 547 " * @serialField one int " + 548 " */\n" + 549 " protected ObjectStreamField[] serialPersistentFields = { \n" + 550 " new ObjectStreamField(\"one\", Integer.TYPE) \n" + 551 " };\n" + 552 "}\n", 553 554 "/** This is a description. */\n" + 555 "class Test {\n" + 556 " /** This is a description.\n" + 557 " * @serialField one int " + 558 " */\n" + 559 " public ObjectStreamField[] serialPersistentFields = { \n" + 560 " new ObjectStreamField(\"one\", Integer.TYPE) \n" + 561 " };\n" + 562 "}\n", 563 }, 564 565 new String [] { 566 FieldDocAnalyzer.MSG_SERIALFIELD_WITHOUT_DESCRIPTION, 567 }, 568 new int[] { 4 }, 569 new int[] { 22 }, 570 new int[] { 4 }, 571 new int[] { 29 }); 572 } 573 574 } 575 | Popular Tags |