1 33 34 package edu.rice.cs.drjava.ui.predictive; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 38 import java.util.List ; 39 40 43 public class PredictiveInputModelTest extends DrJavaTestCase { 44 public void testInitial() { 45 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 46 new PredictiveInputModel.PrefixStrategy<String >(), 47 "AboutDialog.java", 48 "FileOps.java", 49 "FileOpsTest.java", 50 "Utilities.java"); 51 assertEquals("AboutDialog.java", pim.getCurrentItem()); 52 assertEquals("", pim.getMask()); 53 assertEquals(4, pim.getMatchingItems().size()); 54 assertEquals("", pim.getSharedMaskExtension()); 55 } 56 57 public void testEmpty() { 58 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 59 new PredictiveInputModel.PrefixStrategy<String >()); 60 assertEquals(null, pim.getCurrentItem()); 61 assertEquals("", pim.getMask()); 62 assertEquals(0, pim.getMatchingItems().size()); 63 assertEquals("", pim.getSharedMaskExtension()); 64 65 pim.setMask("F"); 66 assertEquals(null, pim.getCurrentItem()); 67 assertEquals("F", pim.getMask()); 68 assertEquals(0, pim.getMatchingItems().size()); 69 assertEquals("", pim.getSharedMaskExtension()); 70 71 pim.extendMask(pim.getSharedMaskExtension()); 72 assertEquals(null, pim.getCurrentItem()); 73 assertEquals("F", pim.getMask()); 74 assertEquals(0, pim.getMatchingItems().size()); 75 assertEquals("", pim.getSharedMaskExtension()); 76 77 pim.extendMask("."); 78 assertEquals(null, pim.getCurrentItem()); 79 assertEquals("F.", pim.getMask()); 80 assertEquals(0, pim.getMatchingItems().size()); 81 assertEquals("", pim.getSharedMaskExtension()); 82 83 pim.extendMask("x"); 84 assertEquals(null, pim.getCurrentItem()); 85 assertEquals("F.x", pim.getMask()); 86 assertEquals(0, pim.getMatchingItems().size()); 87 assertEquals("", pim.getSharedMaskExtension()); 88 89 pim.extendMask("y"); 90 assertEquals(null, pim.getCurrentItem()); 91 assertEquals("F.xy", pim.getMask()); 92 assertEquals(0, pim.getMatchingItems().size()); 93 assertEquals("", pim.getSharedMaskExtension()); 94 95 pim.setList("AboutDialog.java", 96 "FileOps.java", 97 "FileOpsTest.java", 98 "Utilities.java"); 99 pim.setMask("F"); 100 assertEquals("FileOps.java", pim.getCurrentItem()); 101 assertEquals("F", pim.getMask()); 102 assertEquals(2, pim.getMatchingItems().size()); 103 assertEquals("ileOps", pim.getSharedMaskExtension()); 104 105 pim.extendMask(pim.getSharedMaskExtension()); 106 assertEquals("FileOps.java", pim.getCurrentItem()); 107 assertEquals("FileOps", pim.getMask()); 108 assertEquals(2, pim.getMatchingItems().size()); 109 assertEquals("", pim.getSharedMaskExtension()); 110 111 pim.extendMask("."); 112 assertEquals("FileOps.java", pim.getCurrentItem()); 113 assertEquals("FileOps.", pim.getMask()); 114 assertEquals(1, pim.getMatchingItems().size()); 115 assertEquals("java", pim.getSharedMaskExtension()); 116 117 pim.extendMask("x"); 118 assertEquals("FileOps.java", pim.getCurrentItem()); 119 assertEquals("FileOps.x", pim.getMask()); 120 assertEquals(0, pim.getMatchingItems().size()); 121 assertEquals("", pim.getSharedMaskExtension()); 122 123 pim.extendMask("y"); 124 assertEquals("FileOps.java", pim.getCurrentItem()); 125 assertEquals("FileOps.xy", pim.getMask()); 126 assertEquals(0, pim.getMatchingItems().size()); 127 assertEquals("", pim.getSharedMaskExtension()); 128 } 129 130 public void testNarrowingWithExtend() { 131 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 132 new PredictiveInputModel.PrefixStrategy<String >(), 133 "AboutDialog.java", 134 "FileOps.java", 135 "FileOpsTest.java", 136 "Utilities.java"); 137 pim.setMask("F"); 138 assertEquals("FileOps.java", pim.getCurrentItem()); 139 assertEquals("F", pim.getMask()); 140 assertEquals(2, pim.getMatchingItems().size()); 141 assertEquals("ileOps", pim.getSharedMaskExtension()); 142 143 pim.extendMask(pim.getSharedMaskExtension()); 144 assertEquals("FileOps.java", pim.getCurrentItem()); 145 assertEquals("FileOps", pim.getMask()); 146 assertEquals(2, pim.getMatchingItems().size()); 147 assertEquals("", pim.getSharedMaskExtension()); 148 149 pim.extendMask("."); 150 assertEquals("FileOps.java", pim.getCurrentItem()); 151 assertEquals("FileOps.", pim.getMask()); 152 assertEquals(1, pim.getMatchingItems().size()); 153 assertEquals("java", pim.getSharedMaskExtension()); 154 155 pim.extendMask("x"); 156 assertEquals("FileOps.java", pim.getCurrentItem()); 157 assertEquals("FileOps.x", pim.getMask()); 158 assertEquals(0, pim.getMatchingItems().size()); 159 assertEquals("", pim.getSharedMaskExtension()); 160 161 pim.extendMask("y"); 162 assertEquals("FileOps.java", pim.getCurrentItem()); 163 assertEquals("FileOps.xy", pim.getMask()); 164 assertEquals(0, pim.getMatchingItems().size()); 165 assertEquals("", pim.getSharedMaskExtension()); 166 } 167 168 public void testNarrowingWithSet() { 169 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 170 new PredictiveInputModel.PrefixStrategy<String >(), 171 "AboutDialog.java", 172 "FileOps.java", 173 "FileOpsTest.java", 174 "Utilities.java"); 175 pim.setMask("F"); 176 assertEquals("FileOps.java", pim.getCurrentItem()); 177 assertEquals("F", pim.getMask()); 178 assertEquals(2, pim.getMatchingItems().size()); 179 assertEquals("ileOps", pim.getSharedMaskExtension()); 180 181 pim.setMask(pim.getMask()+pim.getSharedMaskExtension()); 182 assertEquals("FileOps.java", pim.getCurrentItem()); 183 assertEquals("FileOps", pim.getMask()); 184 assertEquals(2, pim.getMatchingItems().size()); 185 assertEquals("", pim.getSharedMaskExtension()); 186 187 pim.setMask(pim.getMask()+"."); 188 assertEquals("FileOps.java", pim.getCurrentItem()); 189 assertEquals("FileOps.", pim.getMask()); 190 assertEquals(1, pim.getMatchingItems().size()); 191 assertEquals("java", pim.getSharedMaskExtension()); 192 193 pim.setMask(pim.getMask()+"x"); 194 assertEquals("FileOps.java", pim.getCurrentItem()); 195 assertEquals("FileOps.x", pim.getMask()); 196 assertEquals(0, pim.getMatchingItems().size()); 197 assertEquals("", pim.getSharedMaskExtension()); 198 199 pim.setMask(pim.getMask()+"y"); 200 assertEquals("FileOps.java", pim.getCurrentItem()); 201 assertEquals("FileOps.xy", pim.getMask()); 202 assertEquals(0, pim.getMatchingItems().size()); 203 assertEquals("", pim.getSharedMaskExtension()); 204 } 205 206 public void testWidening() { 207 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 208 new PredictiveInputModel.PrefixStrategy<String >(), 209 "AboutDialog.java", 210 "FileOps.java", 211 "FileOpsTest.java", 212 "Utilities.java"); 213 pim.setMask("FileOps."); 214 assertEquals("FileOps.java", pim.getCurrentItem()); 215 assertEquals("FileOps.", pim.getMask()); 216 assertEquals(1, pim.getMatchingItems().size()); 217 assertEquals("java", pim.getSharedMaskExtension()); 218 219 pim.setMask("FileOps"); 220 assertEquals("FileOps.java", pim.getCurrentItem()); 221 assertEquals("FileOps", pim.getMask()); 222 assertEquals(2, pim.getMatchingItems().size()); 223 assertEquals("", pim.getSharedMaskExtension()); 224 225 pim.setMask("F"); 226 assertEquals("FileOps.java", pim.getCurrentItem()); 227 assertEquals("F", pim.getMask()); 228 assertEquals(2, pim.getMatchingItems().size()); 229 assertEquals("ileOps", pim.getSharedMaskExtension()); 230 231 pim.setMask(""); 232 assertEquals("FileOps.java", pim.getCurrentItem()); 233 assertEquals("", pim.getMask()); 234 assertEquals(4, pim.getMatchingItems().size()); 235 assertEquals("", pim.getSharedMaskExtension()); 236 } 237 238 public void testSetMatching() { 239 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 240 new PredictiveInputModel.PrefixStrategy<String >(), 241 "AboutDialog.java", 242 "FileOps.java", 243 "FileOpsTest.java", 244 "Utilities.java"); 245 pim.setMask("F"); 246 assertEquals("FileOps.java", pim.getCurrentItem()); 247 assertEquals("F", pim.getMask()); 248 assertEquals(2, pim.getMatchingItems().size()); 249 assertEquals("ileOps", pim.getSharedMaskExtension()); 250 251 pim.setCurrentItem(pim.getCurrentItem()); 252 assertEquals("FileOps.java", pim.getCurrentItem()); 253 assertEquals("F", pim.getMask()); 254 assertEquals(2, pim.getMatchingItems().size()); 255 assertEquals("ileOps", pim.getSharedMaskExtension()); 256 257 List <String > m = pim.getMatchingItems(); 258 int i = m.indexOf(pim.getCurrentItem()); 259 pim.setCurrentItem(m.get(i+1)); 260 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 261 assertEquals("F", pim.getMask()); 262 assertEquals(2, pim.getMatchingItems().size()); 263 assertEquals("ileOps", pim.getSharedMaskExtension()); 264 } 265 266 public void testSetNotMatching() { 267 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 268 new PredictiveInputModel.PrefixStrategy<String >(), 269 "AboutDialog.java", 270 "FileOps.java", 271 "FileOpsTest.java", 272 "Utilities.java"); 273 pim.setMask("F"); 274 assertEquals("FileOps.java", pim.getCurrentItem()); 275 assertEquals("F", pim.getMask()); 276 assertEquals(2, pim.getMatchingItems().size()); 277 assertEquals("ileOps", pim.getSharedMaskExtension()); 278 279 pim.setCurrentItem("AboutDialog.java"); 280 assertEquals("FileOps.java", pim.getCurrentItem()); 281 assertEquals("F", pim.getMask()); 282 assertEquals(2, pim.getMatchingItems().size()); 283 assertEquals("ileOps", pim.getSharedMaskExtension()); 284 285 pim.setCurrentItem("Utilities.java"); 286 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 287 assertEquals("F", pim.getMask()); 288 assertEquals(2, pim.getMatchingItems().size()); 289 assertEquals("ileOps", pim.getSharedMaskExtension()); 290 } 291 292 public void testSetNotInList() { 293 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 294 new PredictiveInputModel.PrefixStrategy<String >(), 295 "AboutDialog.java", 296 "FileOps.java", 297 "FileOpsTest.java", 298 "Utilities.java"); 299 pim.setMask("F"); 300 assertEquals("FileOps.java", pim.getCurrentItem()); 301 assertEquals("F", pim.getMask()); 302 assertEquals(2, pim.getMatchingItems().size()); 303 assertEquals("ileOps", pim.getSharedMaskExtension()); 304 305 pim.setCurrentItem("BBBB"); 306 assertEquals("FileOps.java", pim.getCurrentItem()); 307 assertEquals("F", pim.getMask()); 308 assertEquals(2, pim.getMatchingItems().size()); 309 assertEquals("ileOps", pim.getSharedMaskExtension()); 310 311 pim.setCurrentItem("FileOps.XXX"); 312 assertEquals("FileOps.java", pim.getCurrentItem()); 313 assertEquals("F", pim.getMask()); 314 assertEquals(2, pim.getMatchingItems().size()); 315 assertEquals("ileOps", pim.getSharedMaskExtension()); 316 317 pim.setCurrentItem("XXX"); 318 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 319 assertEquals("F", pim.getMask()); 320 assertEquals(2, pim.getMatchingItems().size()); 321 assertEquals("ileOps", pim.getSharedMaskExtension()); 322 } 323 324 public void testIgnoreCaseNarrowingWithExtend() { 325 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 326 new PredictiveInputModel.PrefixStrategy<String >(), 327 "AboutDialog.java", 328 "FileOps.java", 329 "FileOpsTest.java", 330 "Utilities.java"); 331 pim.setMask("f"); 332 assertEquals("FileOps.java", pim.getCurrentItem()); 333 assertEquals("f", pim.getMask()); 334 assertEquals(2, pim.getMatchingItems().size()); 335 assertEquals("ileOps", pim.getSharedMaskExtension()); 336 337 pim.extendMask(pim.getSharedMaskExtension().toUpperCase()); 338 assertEquals("FileOps.java", pim.getCurrentItem()); 339 assertEquals("fILEOPS", pim.getMask()); 340 assertEquals(2, pim.getMatchingItems().size()); 341 assertEquals("", pim.getSharedMaskExtension()); 342 343 pim.extendMask("."); 344 assertEquals("FileOps.java", pim.getCurrentItem()); 345 assertEquals("fILEOPS.", pim.getMask()); 346 assertEquals(1, pim.getMatchingItems().size()); 347 assertEquals("java", pim.getSharedMaskExtension()); 348 349 pim.extendMask("x"); 350 assertEquals("FileOps.java", pim.getCurrentItem()); 351 assertEquals("fILEOPS.x", pim.getMask()); 352 assertEquals(0, pim.getMatchingItems().size()); 353 assertEquals("", pim.getSharedMaskExtension()); 354 355 pim.extendMask("y"); 356 assertEquals("FileOps.java", pim.getCurrentItem()); 357 assertEquals("fILEOPS.xy", pim.getMask()); 358 assertEquals(0, pim.getMatchingItems().size()); 359 assertEquals("", pim.getSharedMaskExtension()); 360 } 361 362 public void testIgnoreCaseNarrowingWithSet() { 363 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 364 new PredictiveInputModel.PrefixStrategy<String >(), 365 "AboutDialog.java", 366 "FileOps.java", 367 "FileOpsTest.java", 368 "Utilities.java"); 369 pim.setMask("f"); 370 assertEquals("FileOps.java", pim.getCurrentItem()); 371 assertEquals("f", pim.getMask()); 372 assertEquals(2, pim.getMatchingItems().size()); 373 assertEquals("ileOps", pim.getSharedMaskExtension()); 374 375 pim.setMask(pim.getMask()+pim.getSharedMaskExtension().toUpperCase()); 376 assertEquals("FileOps.java", pim.getCurrentItem()); 377 assertEquals("fILEOPS", pim.getMask()); 378 assertEquals(2, pim.getMatchingItems().size()); 379 assertEquals("", pim.getSharedMaskExtension()); 380 381 pim.setMask(pim.getMask()+"."); 382 assertEquals("FileOps.java", pim.getCurrentItem()); 383 assertEquals("fILEOPS.", pim.getMask()); 384 assertEquals(1, pim.getMatchingItems().size()); 385 assertEquals("java", pim.getSharedMaskExtension()); 386 387 pim.setMask(pim.getMask()+"x"); 388 assertEquals("FileOps.java", pim.getCurrentItem()); 389 assertEquals("fILEOPS.x", pim.getMask()); 390 assertEquals(0, pim.getMatchingItems().size()); 391 assertEquals("", pim.getSharedMaskExtension()); 392 393 pim.setMask(pim.getMask()+"y"); 394 assertEquals("FileOps.java", pim.getCurrentItem()); 395 assertEquals("fILEOPS.xy", pim.getMask()); 396 assertEquals(0, pim.getMatchingItems().size()); 397 assertEquals("", pim.getSharedMaskExtension()); 398 } 399 400 public void testIgnoreCaseWidening() { 401 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 402 new PredictiveInputModel.PrefixStrategy<String >(), 403 "AboutDialog.java", 404 "FileOps.java", 405 "FileOpsTest.java", 406 "Utilities.java"); 407 pim.setMask("fILEOPS."); 408 assertEquals("FileOps.java", pim.getCurrentItem()); 409 assertEquals("fILEOPS.", pim.getMask()); 410 assertEquals(1, pim.getMatchingItems().size()); 411 assertEquals("java", pim.getSharedMaskExtension()); 412 413 pim.setMask("fILEOPS"); 414 assertEquals("FileOps.java", pim.getCurrentItem()); 415 assertEquals("fILEOPS", pim.getMask()); 416 assertEquals(2, pim.getMatchingItems().size()); 417 assertEquals("", pim.getSharedMaskExtension()); 418 419 pim.setMask("f"); 420 assertEquals("FileOps.java", pim.getCurrentItem()); 421 assertEquals("f", pim.getMask()); 422 assertEquals(2, pim.getMatchingItems().size()); 423 assertEquals("ileOps", pim.getSharedMaskExtension()); 424 425 pim.setMask(""); 426 assertEquals("FileOps.java", pim.getCurrentItem()); 427 assertEquals("", pim.getMask()); 428 assertEquals(4, pim.getMatchingItems().size()); 429 assertEquals("", pim.getSharedMaskExtension()); 430 } 431 432 public void testIgnoreCaseSetMatching() { 433 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 434 new PredictiveInputModel.PrefixStrategy<String >(), 435 "AboutDialog.java", 436 "FileOps.java", 437 "FileOpsTest.java", 438 "Utilities.java"); 439 pim.setMask("f"); 440 assertEquals("FileOps.java", pim.getCurrentItem()); 441 assertEquals("f", pim.getMask()); 442 assertEquals(2, pim.getMatchingItems().size()); 443 assertEquals("ileOps", pim.getSharedMaskExtension()); 444 445 pim.setCurrentItem(pim.getCurrentItem()); 446 assertEquals("FileOps.java", pim.getCurrentItem()); 447 assertEquals("f", pim.getMask()); 448 assertEquals(2, pim.getMatchingItems().size()); 449 assertEquals("ileOps", pim.getSharedMaskExtension()); 450 451 pim.setCurrentItem(pim.getCurrentItem().toUpperCase()); 452 assertEquals("FileOps.java", pim.getCurrentItem()); 453 assertEquals("f", pim.getMask()); 454 assertEquals(2, pim.getMatchingItems().size()); 455 assertEquals("ileOps", pim.getSharedMaskExtension()); 456 457 List <String > m = pim.getMatchingItems(); 458 int i = m.indexOf(pim.getCurrentItem()); 459 pim.setCurrentItem(m.get(i+1).toUpperCase()); 460 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 461 assertEquals("f", pim.getMask()); 462 assertEquals(2, pim.getMatchingItems().size()); 463 assertEquals("ileOps", pim.getSharedMaskExtension()); 464 } 465 466 public void testIgnoreCaseSetNotMatching() { 467 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 468 new PredictiveInputModel.PrefixStrategy<String >(), 469 "AboutDialog.java", 470 "FileOps.java", 471 "FileOpsTest.java", 472 "Utilities.java"); 473 pim.setMask("f"); 474 assertEquals("FileOps.java", pim.getCurrentItem()); 475 assertEquals("f", pim.getMask()); 476 assertEquals(2, pim.getMatchingItems().size()); 477 assertEquals("ileOps", pim.getSharedMaskExtension()); 478 479 pim.setCurrentItem("AboutDialog.java"); 480 assertEquals("FileOps.java", pim.getCurrentItem()); 481 assertEquals("f", pim.getMask()); 482 assertEquals(2, pim.getMatchingItems().size()); 483 assertEquals("ileOps", pim.getSharedMaskExtension()); 484 485 pim.setCurrentItem("aboutDIALOG.JAVa"); 486 assertEquals("FileOps.java", pim.getCurrentItem()); 487 assertEquals("f", pim.getMask()); 488 assertEquals(2, pim.getMatchingItems().size()); 489 assertEquals("ileOps", pim.getSharedMaskExtension()); 490 491 pim.setCurrentItem("Utilities.java"); 492 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 493 assertEquals("f", pim.getMask()); 494 assertEquals(2, pim.getMatchingItems().size()); 495 assertEquals("ileOps", pim.getSharedMaskExtension()); 496 497 pim.setCurrentItem("uTILIties.JaVa"); 498 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 499 assertEquals("f", pim.getMask()); 500 assertEquals(2, pim.getMatchingItems().size()); 501 assertEquals("ileOps", pim.getSharedMaskExtension()); 502 } 503 504 public void testIgnoreCaseSetNotInList() { 505 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 506 new PredictiveInputModel.PrefixStrategy<String >(), 507 "AboutDialog.java", 508 "FileOps.java", 509 "FileOpsTest.java", 510 "Utilities.java"); 511 pim.setMask("f"); 512 assertEquals("FileOps.java", pim.getCurrentItem()); 513 assertEquals("f", pim.getMask()); 514 assertEquals(2, pim.getMatchingItems().size()); 515 assertEquals("ileOps", pim.getSharedMaskExtension()); 516 517 pim.setCurrentItem("BBBB"); 518 assertEquals("FileOps.java", pim.getCurrentItem()); 519 assertEquals("f", pim.getMask()); 520 assertEquals(2, pim.getMatchingItems().size()); 521 assertEquals("ileOps", pim.getSharedMaskExtension()); 522 523 pim.setCurrentItem("bbbb"); 524 assertEquals("FileOps.java", pim.getCurrentItem()); 525 assertEquals("f", pim.getMask()); 526 assertEquals(2, pim.getMatchingItems().size()); 527 assertEquals("ileOps", pim.getSharedMaskExtension()); 528 529 pim.setCurrentItem("FileOps.XXX"); 530 assertEquals("FileOps.java", pim.getCurrentItem()); 531 assertEquals("f", pim.getMask()); 532 assertEquals(2, pim.getMatchingItems().size()); 533 assertEquals("ileOps", pim.getSharedMaskExtension()); 534 535 pim.setCurrentItem("fILEoPS.xXx"); 536 assertEquals("FileOps.java", pim.getCurrentItem()); 537 assertEquals("f", pim.getMask()); 538 assertEquals(2, pim.getMatchingItems().size()); 539 assertEquals("ileOps", pim.getSharedMaskExtension()); 540 541 pim.setCurrentItem("xxx"); 542 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 543 assertEquals("f", pim.getMask()); 544 assertEquals(2, pim.getMatchingItems().size()); 545 assertEquals("ileOps", pim.getSharedMaskExtension()); 546 } 547 548 public void testFragmentInitial() { 549 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 550 new PredictiveInputModel.FragmentStrategy<String >(), 551 "AboutDialog.java", 552 "FileOps.java", 553 "FileOpsTest.java", 554 "Utilities.java"); 555 assertEquals("AboutDialog.java", pim.getCurrentItem()); 556 assertEquals("", pim.getMask()); 557 assertEquals(4, pim.getMatchingItems().size()); 558 assertEquals("", pim.getSharedMaskExtension()); 559 } 560 561 public void testFragmentEmpty() { 562 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 563 new PredictiveInputModel.FragmentStrategy<String >()); 564 assertEquals(null, pim.getCurrentItem()); 565 assertEquals("", pim.getMask()); 566 assertEquals(0, pim.getMatchingItems().size()); 567 568 pim.setMask("F"); 569 assertEquals(null, pim.getCurrentItem()); 570 assertEquals("F", pim.getMask()); 571 assertEquals(0, pim.getMatchingItems().size()); 572 573 pim.extendMask(pim.getSharedMaskExtension()); 574 assertEquals(null, pim.getCurrentItem()); 575 assertEquals("F", pim.getMask()); 576 assertEquals(0, pim.getMatchingItems().size()); 577 578 pim.extendMask("."); 579 assertEquals(null, pim.getCurrentItem()); 580 assertEquals("F.", pim.getMask()); 581 assertEquals(0, pim.getMatchingItems().size()); 582 583 pim.extendMask("x"); 584 assertEquals(null, pim.getCurrentItem()); 585 assertEquals("F.x", pim.getMask()); 586 assertEquals(0, pim.getMatchingItems().size()); 587 588 pim.extendMask("y"); 589 assertEquals(null, pim.getCurrentItem()); 590 assertEquals("F.xy", pim.getMask()); 591 assertEquals(0, pim.getMatchingItems().size()); 592 593 pim.setMask("i .java"); 594 assertEquals(null, pim.getCurrentItem()); 595 assertEquals("i .java", pim.getMask()); 596 assertEquals(0, pim.getMatchingItems().size()); 597 598 pim.setList("AboutDialog.java", 599 "FileOps.java", 600 "FileOpsTest.java", 601 "Utilities.java"); 602 pim.setMask("F"); 603 assertEquals("FileOps.java", pim.getCurrentItem()); 604 assertEquals("F", pim.getMask()); 605 assertEquals(2, pim.getMatchingItems().size()); 606 607 pim.extendMask("ileOps"); 608 assertEquals("FileOps.java", pim.getCurrentItem()); 609 assertEquals("FileOps", pim.getMask()); 610 assertEquals(2, pim.getMatchingItems().size()); 611 612 pim.extendMask("."); 613 assertEquals("FileOps.java", pim.getCurrentItem()); 614 assertEquals("FileOps.", pim.getMask()); 615 assertEquals(1, pim.getMatchingItems().size()); 616 617 pim.extendMask("x"); 618 assertEquals("AboutDialog.java", pim.getCurrentItem()); 619 assertEquals("FileOps.x", pim.getMask()); 620 assertEquals(0, pim.getMatchingItems().size()); 621 622 pim.extendMask("y"); 623 assertEquals("AboutDialog.java", pim.getCurrentItem()); 624 assertEquals("FileOps.xy", pim.getMask()); 625 assertEquals(0, pim.getMatchingItems().size()); 626 627 pim.setMask("File java"); 628 assertEquals("FileOps.java", pim.getCurrentItem()); 629 assertEquals("File java", pim.getMask()); 630 assertEquals(2, pim.getMatchingItems().size()); 631 } 632 633 public void testFragmentNarrowingWithExtend() { 634 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 635 new PredictiveInputModel.FragmentStrategy<String >(), 636 "AboutDialog.java", 637 "FileOps.java", 638 "FileOpsTest.java", 639 "Utilities.java"); 640 pim.setMask("F"); 641 assertEquals("FileOps.java", pim.getCurrentItem()); 642 assertEquals("F", pim.getMask()); 643 assertEquals(2, pim.getMatchingItems().size()); 644 645 pim.extendMask(" ileOps"); 646 assertEquals("FileOps.java", pim.getCurrentItem()); 647 assertEquals("F ileOps", pim.getMask()); 648 assertEquals(2, pim.getMatchingItems().size()); 649 650 pim.extendMask("."); 651 assertEquals("FileOps.java", pim.getCurrentItem()); 652 assertEquals("F ileOps.", pim.getMask()); 653 assertEquals(1, pim.getMatchingItems().size()); 654 655 pim.extendMask("x"); 656 assertEquals("AboutDialog.java", pim.getCurrentItem()); 657 assertEquals("F ileOps.x", pim.getMask()); 658 assertEquals(0, pim.getMatchingItems().size()); 659 660 pim.extendMask("y"); 661 assertEquals("AboutDialog.java", pim.getCurrentItem()); 662 assertEquals("F ileOps.xy", pim.getMask()); 663 assertEquals(0, pim.getMatchingItems().size()); 664 } 665 666 public void testFragmentNarrowingWithSet() { 667 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 668 new PredictiveInputModel.FragmentStrategy<String >(), 669 "AboutDialog.java", 670 "FileOps.java", 671 "FileOpsTest.java", 672 "Utilities.java"); 673 pim.setMask("F"); 674 assertEquals("FileOps.java", pim.getCurrentItem()); 675 assertEquals("F", pim.getMask()); 676 assertEquals(2, pim.getMatchingItems().size()); 677 678 pim.setMask("F ileOps"); 679 assertEquals("FileOps.java", pim.getCurrentItem()); 680 assertEquals("F ileOps", pim.getMask()); 681 assertEquals(2, pim.getMatchingItems().size()); 682 683 pim.setMask(pim.getMask()+"."); 684 assertEquals("FileOps.java", pim.getCurrentItem()); 685 assertEquals("F ileOps.", pim.getMask()); 686 assertEquals(1, pim.getMatchingItems().size()); 687 688 pim.setMask(pim.getMask()+"x"); 689 assertEquals("AboutDialog.java", pim.getCurrentItem()); 690 assertEquals("F ileOps.x", pim.getMask()); 691 assertEquals(0, pim.getMatchingItems().size()); 692 693 pim.setMask(pim.getMask()+"y"); 694 assertEquals("AboutDialog.java", pim.getCurrentItem()); 695 assertEquals("F ileOps.xy", pim.getMask()); 696 assertEquals(0, pim.getMatchingItems().size()); 697 } 698 699 public void testFragmentWidening() { 700 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 701 new PredictiveInputModel.FragmentStrategy<String >(), 702 "AboutDialog.java", 703 "FileOps.java", 704 "FileOpsTest.java", 705 "Utilities.java"); 706 pim.setMask("File Ops."); 707 assertEquals("FileOps.java", pim.getCurrentItem()); 708 assertEquals("File Ops.", pim.getMask()); 709 assertEquals(1, pim.getMatchingItems().size()); 710 711 pim.setMask("File Ops"); 712 assertEquals("FileOps.java", pim.getCurrentItem()); 713 assertEquals("File Ops", pim.getMask()); 714 assertEquals(2, pim.getMatchingItems().size()); 715 716 pim.setMask("F i"); 717 assertEquals("FileOps.java", pim.getCurrentItem()); 718 assertEquals("F i", pim.getMask()); 719 assertEquals(2, pim.getMatchingItems().size()); 720 721 pim.setMask(""); 722 assertEquals("FileOps.java", pim.getCurrentItem()); 723 assertEquals("", pim.getMask()); 724 assertEquals(4, pim.getMatchingItems().size()); 725 } 726 727 public void testFragmentSetMatching() { 728 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 729 new PredictiveInputModel.FragmentStrategy<String >(), 730 "AboutDialog.java", 731 "FileOps.java", 732 "FileOpsTest.java", 733 "Utilities.java"); 734 pim.setMask("F"); 735 assertEquals("FileOps.java", pim.getCurrentItem()); 736 assertEquals("F", pim.getMask()); 737 assertEquals(2, pim.getMatchingItems().size()); 738 739 pim.setCurrentItem(pim.getCurrentItem()); 740 assertEquals("FileOps.java", pim.getCurrentItem()); 741 assertEquals("F", pim.getMask()); 742 assertEquals(2, pim.getMatchingItems().size()); 743 744 List <String > m = pim.getMatchingItems(); 745 int i = m.indexOf(pim.getCurrentItem()); 746 pim.setCurrentItem(m.get(i+1)); 747 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 748 assertEquals("F", pim.getMask()); 749 assertEquals(2, pim.getMatchingItems().size()); 750 } 751 752 public void testFragmentSetNotMatching() { 753 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 754 new PredictiveInputModel.FragmentStrategy<String >(), 755 "AboutDialog.java", 756 "FileOps.java", 757 "FileOpsTest.java", 758 "Utilities.java"); 759 pim.setMask("F"); 760 assertEquals("FileOps.java", pim.getCurrentItem()); 761 assertEquals("F", pim.getMask()); 762 assertEquals(2, pim.getMatchingItems().size()); 763 764 pim.setCurrentItem("AboutDialog.java"); 765 assertEquals("FileOps.java", pim.getCurrentItem()); 766 assertEquals("F", pim.getMask()); 767 assertEquals(2, pim.getMatchingItems().size()); 768 769 pim.setCurrentItem("Utilities.java"); 770 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 771 assertEquals("F", pim.getMask()); 772 assertEquals(2, pim.getMatchingItems().size()); 773 } 774 775 public void testFragmentSetNotInList() { 776 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(false, 777 new PredictiveInputModel.FragmentStrategy<String >(), 778 "AboutDialog.java", 779 "FileOps.java", 780 "FileOpsTest.java", 781 "Utilities.java"); 782 pim.setMask("F"); 783 assertEquals("FileOps.java", pim.getCurrentItem()); 784 assertEquals("F", pim.getMask()); 785 assertEquals(2, pim.getMatchingItems().size()); 786 787 pim.setCurrentItem("BBBB"); 788 assertEquals("FileOps.java", pim.getCurrentItem()); 789 assertEquals("F", pim.getMask()); 790 assertEquals(2, pim.getMatchingItems().size()); 791 792 pim.setCurrentItem("FileOps.XXX"); 793 assertEquals("FileOps.java", pim.getCurrentItem()); 794 assertEquals("F", pim.getMask()); 795 assertEquals(2, pim.getMatchingItems().size()); 796 797 pim.setCurrentItem("XXX"); 798 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 799 assertEquals("F", pim.getMask()); 800 assertEquals(2, pim.getMatchingItems().size()); 801 } 802 803 public void testFragmentIgnoreCaseEmpty() { 804 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 805 new PredictiveInputModel.FragmentStrategy<String >()); 806 assertEquals(null, pim.getCurrentItem()); 807 assertEquals("", pim.getMask()); 808 assertEquals(0, pim.getMatchingItems().size()); 809 810 pim.setMask("F"); 811 assertEquals(null, pim.getCurrentItem()); 812 assertEquals("F", pim.getMask()); 813 assertEquals(0, pim.getMatchingItems().size()); 814 815 pim.extendMask("."); 816 assertEquals(null, pim.getCurrentItem()); 817 assertEquals("F.", pim.getMask()); 818 assertEquals(0, pim.getMatchingItems().size()); 819 820 pim.extendMask("x"); 821 assertEquals(null, pim.getCurrentItem()); 822 assertEquals("F.x", pim.getMask()); 823 assertEquals(0, pim.getMatchingItems().size()); 824 825 pim.extendMask("y"); 826 assertEquals(null, pim.getCurrentItem()); 827 assertEquals("F.xy", pim.getMask()); 828 assertEquals(0, pim.getMatchingItems().size()); 829 830 pim.setMask("I .JAVa"); 831 assertEquals(null, pim.getCurrentItem()); 832 assertEquals("I .JAVa", pim.getMask()); 833 assertEquals(0, pim.getMatchingItems().size()); 834 835 pim.setList("AboutDialog.java", 836 "FileOps.java", 837 "FileOpsTest.java", 838 "Utilities.java"); 839 pim.setMask("F"); 840 assertEquals("FileOps.java", pim.getCurrentItem()); 841 assertEquals("F", pim.getMask()); 842 assertEquals(2, pim.getMatchingItems().size()); 843 844 pim.extendMask("ILEoPS"); 845 assertEquals("FileOps.java", pim.getCurrentItem()); 846 assertEquals("FILEoPS", pim.getMask()); 847 assertEquals(2, pim.getMatchingItems().size()); 848 849 pim.extendMask("."); 850 assertEquals("FileOps.java", pim.getCurrentItem()); 851 assertEquals("FILEoPS.", pim.getMask()); 852 assertEquals(1, pim.getMatchingItems().size()); 853 854 pim.extendMask("x"); 855 assertEquals("AboutDialog.java", pim.getCurrentItem()); 856 assertEquals("FILEoPS.x", pim.getMask()); 857 assertEquals(0, pim.getMatchingItems().size()); 858 859 pim.extendMask("y"); 860 assertEquals("AboutDialog.java", pim.getCurrentItem()); 861 assertEquals("FILEoPS.xy", pim.getMask()); 862 assertEquals(0, pim.getMatchingItems().size()); 863 864 pim.setMask("FiLe JAVa"); 865 assertEquals("FileOps.java", pim.getCurrentItem()); 866 assertEquals("FiLe JAVa", pim.getMask()); 867 assertEquals(2, pim.getMatchingItems().size()); 868 } 869 870 public void testFragmentIgnoreCaseNarrowingWithExtend() { 871 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 872 new PredictiveInputModel.FragmentStrategy<String >(), 873 "AboutDialog.java", 874 "FileOps.java", 875 "FileOpsTest.java", 876 "Utilities.java"); 877 pim.setMask("F"); 878 assertEquals("FileOps.java", pim.getCurrentItem()); 879 assertEquals("F", pim.getMask()); 880 assertEquals(2, pim.getMatchingItems().size()); 881 882 pim.extendMask(" IlEOpS"); 883 assertEquals("FileOps.java", pim.getCurrentItem()); 884 assertEquals("F IlEOpS", pim.getMask()); 885 assertEquals(2, pim.getMatchingItems().size()); 886 887 pim.extendMask("."); 888 assertEquals("FileOps.java", pim.getCurrentItem()); 889 assertEquals("F IlEOpS.", pim.getMask()); 890 assertEquals(1, pim.getMatchingItems().size()); 891 892 pim.extendMask("x"); 893 assertEquals("AboutDialog.java", pim.getCurrentItem()); 894 assertEquals("F IlEOpS.x", pim.getMask()); 895 assertEquals(0, pim.getMatchingItems().size()); 896 897 pim.extendMask("y"); 898 assertEquals("AboutDialog.java", pim.getCurrentItem()); 899 assertEquals("F IlEOpS.xy", pim.getMask()); 900 assertEquals(0, pim.getMatchingItems().size()); 901 } 902 903 public void testFragmentIgnoreCaseNarrowingWithSet() { 904 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 905 new PredictiveInputModel.FragmentStrategy<String >(), 906 "AboutDialog.java", 907 "FileOps.java", 908 "FileOpsTest.java", 909 "Utilities.java"); 910 pim.setMask("F"); 911 assertEquals("FileOps.java", pim.getCurrentItem()); 912 assertEquals("F", pim.getMask()); 913 assertEquals(2, pim.getMatchingItems().size()); 914 915 pim.setMask("F IlEOpS"); 916 assertEquals("FileOps.java", pim.getCurrentItem()); 917 assertEquals("F IlEOpS", pim.getMask()); 918 assertEquals(2, pim.getMatchingItems().size()); 919 920 pim.setMask(pim.getMask()+"."); 921 assertEquals("FileOps.java", pim.getCurrentItem()); 922 assertEquals("F IlEOpS.", pim.getMask()); 923 assertEquals(1, pim.getMatchingItems().size()); 924 925 pim.setMask(pim.getMask()+"x"); 926 assertEquals("AboutDialog.java", pim.getCurrentItem()); 927 assertEquals("F IlEOpS.x", pim.getMask()); 928 assertEquals(0, pim.getMatchingItems().size()); 929 930 pim.setMask(pim.getMask()+"y"); 931 assertEquals("AboutDialog.java", pim.getCurrentItem()); 932 assertEquals("F IlEOpS.xy", pim.getMask()); 933 assertEquals(0, pim.getMatchingItems().size()); 934 } 935 936 public void testFragmentIgnoreCaseWidening() { 937 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 938 new PredictiveInputModel.FragmentStrategy<String >(), 939 "AboutDialog.java", 940 "FileOps.java", 941 "FileOpsTest.java", 942 "Utilities.java"); 943 pim.setMask("FiLE oPS."); 944 assertEquals("FileOps.java", pim.getCurrentItem()); 945 assertEquals("FiLE oPS.", pim.getMask()); 946 assertEquals(1, pim.getMatchingItems().size()); 947 948 pim.setMask("FiLE oPS"); 949 assertEquals("FileOps.java", pim.getCurrentItem()); 950 assertEquals("FiLE oPS", pim.getMask()); 951 assertEquals(2, pim.getMatchingItems().size()); 952 953 pim.setMask("f I"); 954 assertEquals("FileOps.java", pim.getCurrentItem()); 955 assertEquals("f I", pim.getMask()); 956 assertEquals(2, pim.getMatchingItems().size()); 957 958 pim.setMask(""); 959 assertEquals("FileOps.java", pim.getCurrentItem()); 960 assertEquals("", pim.getMask()); 961 assertEquals(4, pim.getMatchingItems().size()); 962 } 963 964 public void testFragmentIgnoreCaseSetMatching() { 965 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 966 new PredictiveInputModel.FragmentStrategy<String >(), 967 "AboutDialog.java", 968 "FileOps.java", 969 "FileOpsTest.java", 970 "Utilities.java"); 971 pim.setMask("F"); 972 assertEquals("FileOps.java", pim.getCurrentItem()); 973 assertEquals("F", pim.getMask()); 974 assertEquals(2, pim.getMatchingItems().size()); 975 976 pim.setCurrentItem(pim.getCurrentItem().toUpperCase()); 977 assertEquals("FileOps.java", pim.getCurrentItem()); 978 assertEquals("F", pim.getMask()); 979 assertEquals(2, pim.getMatchingItems().size()); 980 981 List <String > m = pim.getMatchingItems(); 982 int i = m.indexOf(pim.getCurrentItem()); 983 pim.setCurrentItem(m.get(i+1).toUpperCase()); 984 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 985 assertEquals("F", pim.getMask()); 986 assertEquals(2, pim.getMatchingItems().size()); 987 } 988 989 public void testFragmentIgnoreCaseSetNotMatching() { 990 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 991 new PredictiveInputModel.FragmentStrategy<String >(), 992 "AboutDialog.java", 993 "FileOps.java", 994 "FileOpsTest.java", 995 "Utilities.java"); 996 pim.setMask("F"); 997 assertEquals("FileOps.java", pim.getCurrentItem()); 998 assertEquals("F", pim.getMask()); 999 assertEquals(2, pim.getMatchingItems().size()); 1000 1001 pim.setCurrentItem("AboutDialog.java"); 1002 assertEquals("FileOps.java", pim.getCurrentItem()); 1003 assertEquals("F", pim.getMask()); 1004 assertEquals(2, pim.getMatchingItems().size()); 1005 1006 pim.setCurrentItem("Utilities.java"); 1007 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 1008 assertEquals("F", pim.getMask()); 1009 assertEquals(2, pim.getMatchingItems().size()); 1010 } 1011 1012 public void testFragmentIgnoreCaseSetNotInList() { 1013 PredictiveInputModel<String > pim = new PredictiveInputModel<String >(true, 1014 new PredictiveInputModel.FragmentStrategy<String >(), 1015 "AboutDialog.java", 1016 "FileOps.java", 1017 "FileOpsTest.java", 1018 "Utilities.java"); 1019 pim.setMask("F"); 1020 assertEquals("FileOps.java", pim.getCurrentItem()); 1021 assertEquals("F", pim.getMask()); 1022 assertEquals(2, pim.getMatchingItems().size()); 1023 1024 pim.setCurrentItem("BBBB"); 1025 assertEquals("FileOps.java", pim.getCurrentItem()); 1026 assertEquals("F", pim.getMask()); 1027 assertEquals(2, pim.getMatchingItems().size()); 1028 1029 pim.setCurrentItem("FileOps.XXX"); 1030 assertEquals("FileOps.java", pim.getCurrentItem()); 1031 assertEquals("F", pim.getMask()); 1032 assertEquals(2, pim.getMatchingItems().size()); 1033 1034 pim.setCurrentItem("XXX"); 1035 assertEquals("FileOpsTest.java", pim.getCurrentItem()); 1036 assertEquals("F", pim.getMask()); 1037 assertEquals(2, pim.getMatchingItems().size()); 1038 } 1039} 1040 | Popular Tags |