1 22 package org.jboss.test.jmx.compliance.notification; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 27 import javax.management.ListenerNotFoundException ; 28 import javax.management.Notification ; 29 import javax.management.NotificationBroadcasterSupport ; 30 import javax.management.NotificationFilterSupport ; 31 32 import org.jboss.test.jmx.compliance.notification.support.Listener; 33 34 import junit.framework.TestCase; 35 36 41 public class NotificationBroadcasterSupportTestCase 42 extends TestCase 43 { 44 46 49 private ArrayList sent = new ArrayList (); 50 51 54 private long sequence = 0; 55 56 59 private static final String DEFAULT_TYPE = "DefaultType"; 60 61 64 private static final String ANOTHER_TYPE = "AnotherType"; 65 66 69 private static final ArrayList EMPTY = new ArrayList (); 70 71 73 76 public NotificationBroadcasterSupportTestCase(String s) 77 { 78 super(s); 79 } 80 81 83 public void testAddNotificationListener() 84 throws Exception 85 { 86 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 87 88 broadcaster.addNotificationListener(new Listener(), null, null); 89 90 broadcaster.addNotificationListener(new Listener(), new NotificationFilterSupport (), null); 91 92 broadcaster.addNotificationListener(new Listener(), null, new Object ()); 93 94 broadcaster.addNotificationListener(new Listener(), new NotificationFilterSupport (), new Object ()); 95 } 96 97 public void testAddNotificationListenerErrors() 98 throws Exception 99 { 100 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 101 102 boolean caught = false; 103 try 104 { 105 broadcaster.addNotificationListener(null, null, null); 106 } 107 catch (IllegalArgumentException e) 108 { 109 caught = true; 110 } 111 assertTrue("Expected IllegalArgumentException for null listener", caught); 112 113 caught = false; 114 try 115 { 116 broadcaster.addNotificationListener(null, new NotificationFilterSupport (), null); 117 } 118 catch (IllegalArgumentException e) 119 { 120 caught = true; 121 } 122 assertTrue("Expected IllegalArgumentException for null listener", caught); 123 124 caught = false; 125 try 126 { 127 broadcaster.addNotificationListener(null, null, new Object ()); 128 } 129 catch (IllegalArgumentException e) 130 { 131 caught = true; 132 } 133 assertTrue("Expected IllegalArgumentException for null listener", caught); 134 135 caught = false; 136 try 137 { 138 broadcaster.addNotificationListener(null, new NotificationFilterSupport (), new Object ()); 139 } 140 catch (IllegalArgumentException e) 141 { 142 caught = true; 143 } 144 assertTrue("Expected IllegalArgumentException for null listener", caught); 145 } 146 147 public void testNotificationWithNoListeners() 148 throws Exception 149 { 150 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 151 152 clear(); 153 createNotification(broadcaster); 154 } 155 156 public void testSimpleNotification() 157 throws Exception 158 { 159 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 160 161 Listener listener = new Listener(); 162 broadcaster.addNotificationListener(listener, null, null); 163 164 clear(); 165 createNotification(broadcaster); 166 167 compare(sent, received(listener, null)); 168 } 169 170 public void testSimpleFilteredNotification() 171 throws Exception 172 { 173 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 174 175 Listener listener = new Listener(); 176 NotificationFilterSupport filter = new NotificationFilterSupport (); 177 filter.enableType(DEFAULT_TYPE); 178 broadcaster.addNotificationListener(listener, filter, null); 179 180 clear(); 181 createNotification(broadcaster); 182 183 compare(apply(sent, filter), received(listener, null)); 184 } 185 186 public void testSimpleFilteredOutNotification() 187 throws Exception 188 { 189 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 190 191 Listener listener = new Listener(); 192 NotificationFilterSupport filter = new NotificationFilterSupport (); 193 filter.disableType(DEFAULT_TYPE); 194 broadcaster.addNotificationListener(listener, filter, null); 195 196 clear(); 197 createNotification(broadcaster); 198 199 compare(apply(sent, filter), received(listener, null)); 200 } 201 202 public void testSimpleNotificationWithHandback() 203 throws Exception 204 { 205 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 206 207 Listener listener = new Listener(); 208 Object handback = new Object (); 209 broadcaster.addNotificationListener(listener, null, handback); 210 211 clear(); 212 createNotification(broadcaster); 213 214 compare(sent, received(listener, handback)); 215 compare(EMPTY, received(listener, null)); 216 } 217 218 public void testTwoNotifications() 219 throws Exception 220 { 221 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 222 223 Listener listener = new Listener(); 224 broadcaster.addNotificationListener(listener, null, null); 225 226 clear(); 227 createNotification(broadcaster); 228 createNotification(broadcaster); 229 230 compare(sent, received(listener, null)); 231 } 232 233 public void testTwoNotificationsWithDifferentTypes() 234 throws Exception 235 { 236 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 237 238 Listener listener = new Listener(); 239 NotificationFilterSupport filter = new NotificationFilterSupport (); 240 filter.enableType(DEFAULT_TYPE); 241 filter.enableType(ANOTHER_TYPE); 242 broadcaster.addNotificationListener(listener, filter, null); 243 244 clear(); 245 createNotification(broadcaster); 246 createNotification(broadcaster, ANOTHER_TYPE); 247 248 compare(apply(sent, filter), received(listener, null)); 249 } 250 251 public void testTwoNotificationsWithDifferentTypesOneFilteredOut() 252 throws Exception 253 { 254 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 255 256 Listener listener = new Listener(); 257 NotificationFilterSupport filter = new NotificationFilterSupport (); 258 filter.enableType(DEFAULT_TYPE); 259 broadcaster.addNotificationListener(listener, filter, null); 260 261 clear(); 262 createNotification(broadcaster); 263 createNotification(broadcaster, ANOTHER_TYPE); 264 265 compare(apply(sent, filter), received(listener, null)); 266 } 267 268 public void testTwoListeners() 269 throws Exception 270 { 271 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 272 273 Listener listener1 = new Listener(); 274 broadcaster.addNotificationListener(listener1, null, null); 275 Listener listener2 = new Listener(); 276 broadcaster.addNotificationListener(listener2, null, null); 277 278 clear(); 279 createNotification(broadcaster); 280 281 compare(sent, received(listener1, null)); 282 compare(sent, received(listener2, null)); 283 } 284 285 public void testOneListenerRegisteredTwice() 286 throws Exception 287 { 288 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 289 290 Listener listener = new Listener(); 291 broadcaster.addNotificationListener(listener, null, null); 292 broadcaster.addNotificationListener(listener, null, null); 293 294 clear(); 295 createNotification(broadcaster); 296 297 ArrayList copySent = new ArrayList (sent); 298 copySent.addAll(sent); 299 compare(copySent, received(listener, null)); 300 } 301 302 public void testOneListenerRegisteredTwiceOneFilteredOut() 303 throws Exception 304 { 305 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 306 307 Listener listener = new Listener(); 308 broadcaster.addNotificationListener(listener, null, null); 309 NotificationFilterSupport filter = new NotificationFilterSupport (); 310 filter.disableType(DEFAULT_TYPE); 311 broadcaster.addNotificationListener(listener, filter, null); 312 313 clear(); 314 createNotification(broadcaster); 315 316 compare(sent, received(listener, null)); 317 } 318 319 public void testOneListenerRegisteredWithDifferentHandbacks() 320 throws Exception 321 { 322 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 323 324 Listener listener = new Listener(); 325 Object handback1 = new Object (); 326 broadcaster.addNotificationListener(listener, null, handback1); 327 Object handback2 = new Object (); 328 broadcaster.addNotificationListener(listener, null, handback2); 329 330 clear(); 331 createNotification(broadcaster); 332 333 compare(sent, received(listener, handback1)); 334 compare(sent, received(listener, handback2)); 335 compare(EMPTY, received(listener, null)); 336 } 337 338 public void testOneListenerRegisteredWithDifferentHandbacksOneFilteredOut() 339 throws Exception 340 { 341 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 342 343 Listener listener = new Listener(); 344 Object handback1 = new Object (); 345 broadcaster.addNotificationListener(listener, null, handback1); 346 Object handback2 = new Object (); 347 NotificationFilterSupport filter = new NotificationFilterSupport (); 348 filter.disableType(DEFAULT_TYPE); 349 broadcaster.addNotificationListener(listener, filter, handback2); 350 351 clear(); 352 createNotification(broadcaster); 353 354 compare(sent, received(listener, handback1)); 355 compare(apply(sent, filter), received(listener, handback2)); 356 compare(EMPTY, received(listener, null)); 357 } 358 359 public void testOneListenerRegisteredWithTwoBroadcasters() 360 throws Exception 361 { 362 NotificationBroadcasterSupport broadcaster1 = new NotificationBroadcasterSupport (); 363 NotificationBroadcasterSupport broadcaster2 = new NotificationBroadcasterSupport (); 364 365 Listener listener = new Listener(); 366 broadcaster1.addNotificationListener(listener, null, null); 367 broadcaster2.addNotificationListener(listener, null, null); 368 369 createNotification(broadcaster1); 370 createNotification(broadcaster2); 371 372 compare(sent, received(listener, null)); 373 } 374 375 public void testRemoveListener() 376 throws Exception 377 { 378 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 379 380 Listener listener = new Listener(); 381 broadcaster.addNotificationListener(listener, null, null); 382 broadcaster.removeNotificationListener(listener); 383 384 createNotification(broadcaster); 385 386 compare(EMPTY, received(listener, null)); 387 } 388 389 public void testRegisteredTwiceRemoveListener() 390 throws Exception 391 { 392 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 393 394 Listener listener = new Listener(); 395 broadcaster.addNotificationListener(listener, null, null); 396 broadcaster.addNotificationListener(listener, null, null); 397 broadcaster.removeNotificationListener(listener); 398 399 createNotification(broadcaster); 400 401 compare(EMPTY, received(listener, null)); 402 } 403 404 public void testRegisteredWithFilterRemoveListener() 405 throws Exception 406 { 407 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 408 409 Listener listener = new Listener(); 410 NotificationFilterSupport filter = new NotificationFilterSupport (); 411 filter.enableType(DEFAULT_TYPE); 412 broadcaster.addNotificationListener(listener, filter, null); 413 broadcaster.removeNotificationListener(listener); 414 415 createNotification(broadcaster); 416 417 compare(EMPTY, received(listener, null)); 418 } 419 420 public void testRegisteredWithHandbackRemoveListener() 421 throws Exception 422 { 423 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 424 425 Listener listener = new Listener(); 426 Object handback = new Object (); 427 broadcaster.addNotificationListener(listener, null, handback); 428 broadcaster.removeNotificationListener(listener); 429 430 createNotification(broadcaster); 431 432 compare(EMPTY, received(listener, null)); 433 compare(EMPTY, received(listener, handback)); 434 } 435 436 public void testRegisteredWithFilterHandbackRemoveListener() 437 throws Exception 438 { 439 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 440 441 Listener listener = new Listener(); 442 Object handback = new Object (); 443 NotificationFilterSupport filter = new NotificationFilterSupport (); 444 filter.enableType(DEFAULT_TYPE); 445 broadcaster.addNotificationListener(listener, filter, handback); 446 broadcaster.removeNotificationListener(listener); 447 448 createNotification(broadcaster); 449 450 compare(EMPTY, received(listener, null)); 451 compare(EMPTY, received(listener, handback)); 452 } 453 454 public void testRegisterRemoveListenerRegister() 455 throws Exception 456 { 457 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 458 459 Listener listener = new Listener(); 460 broadcaster.addNotificationListener(listener, null, null); 461 broadcaster.removeNotificationListener(listener); 462 broadcaster.addNotificationListener(listener, null, null); 463 464 createNotification(broadcaster); 465 466 compare(sent, received(listener, null)); 467 } 468 469 public void testRemoveListenerErrors() 470 throws Exception 471 { 472 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 473 474 Listener listener = new Listener(); 475 476 boolean caught = false; 477 try 478 { 479 broadcaster.removeNotificationListener(null); 480 } 481 catch (ListenerNotFoundException e) 482 { 483 caught = true; 484 } 485 assertTrue("Expected ListenerNotFoundException for null listener", caught); 486 487 caught = false; 488 try 489 { 490 broadcaster.removeNotificationListener(listener); 491 } 492 catch (ListenerNotFoundException e) 493 { 494 caught = true; 495 } 496 assertTrue("Expected ListenerNotFoundException for listener never added", caught); 497 498 caught = false; 499 try 500 { 501 broadcaster.addNotificationListener(listener, null, null); 502 broadcaster.removeNotificationListener(listener); 503 broadcaster.removeNotificationListener(listener); 504 } 505 catch (ListenerNotFoundException e) 506 { 507 caught = true; 508 } 509 assertTrue("Expected ListenerNotFoundException for listener remove twice", caught); 510 } 511 512 public void testRemoveTripletListenerOnly() 513 throws Exception 514 { 515 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 516 517 Listener listener = new Listener(); 518 broadcaster.addNotificationListener(listener, null, null); 519 broadcaster.removeNotificationListener(listener, null, null); 520 521 createNotification(broadcaster); 522 523 compare(EMPTY, received(listener, null)); 524 } 525 526 public void testRemoveTripletListenerFilter() 527 throws Exception 528 { 529 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 530 531 Listener listener = new Listener(); 532 NotificationFilterSupport filter = new NotificationFilterSupport (); 533 filter.enableType(DEFAULT_TYPE); 534 broadcaster.addNotificationListener(listener, filter, null); 535 broadcaster.removeNotificationListener(listener, filter, null); 536 537 createNotification(broadcaster); 538 539 compare(EMPTY, received(listener, null)); 540 } 541 542 public void testRemoveTripletListenerHandback() 543 throws Exception 544 { 545 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 546 547 Listener listener = new Listener(); 548 Object handback = new Object (); 549 broadcaster.addNotificationListener(listener, null, handback); 550 broadcaster.removeNotificationListener(listener, null, handback); 551 552 createNotification(broadcaster); 553 554 compare(EMPTY, received(listener, null)); 555 compare(EMPTY, received(listener, handback)); 556 } 557 558 public void testRemoveTripletListenerFilterHandback() 559 throws Exception 560 { 561 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 562 563 Listener listener = new Listener(); 564 Object handback = new Object (); 565 NotificationFilterSupport filter = new NotificationFilterSupport (); 566 filter.enableType(DEFAULT_TYPE); 567 broadcaster.addNotificationListener(listener, filter, handback); 568 broadcaster.removeNotificationListener(listener, filter, handback); 569 570 createNotification(broadcaster); 571 572 compare(EMPTY, received(listener, null)); 573 compare(EMPTY, received(listener, handback)); 574 } 575 576 public void testRegisterTwiceRemoveOnceTriplet() 577 throws Exception 578 { 579 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 580 581 Listener listener = new Listener(); 582 Object handback = new Object (); 583 NotificationFilterSupport filter = new NotificationFilterSupport (); 584 filter.enableType(DEFAULT_TYPE); 585 broadcaster.addNotificationListener(listener, filter, handback); 586 broadcaster.addNotificationListener(listener, filter, handback); 587 broadcaster.removeNotificationListener(listener, filter, handback); 588 589 createNotification(broadcaster); 590 591 compare(EMPTY, received(listener, null)); 592 compare(sent, received(listener, handback)); 593 } 594 595 public void testRegisterTwiceRemoveTwiceTriplet() 596 throws Exception 597 { 598 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 599 600 Listener listener = new Listener(); 601 Object handback = new Object (); 602 NotificationFilterSupport filter = new NotificationFilterSupport (); 603 filter.enableType(DEFAULT_TYPE); 604 broadcaster.addNotificationListener(listener, filter, handback); 605 broadcaster.addNotificationListener(listener, filter, handback); 606 broadcaster.removeNotificationListener(listener, filter, handback); 607 broadcaster.removeNotificationListener(listener, filter, handback); 608 609 createNotification(broadcaster); 610 611 compare(EMPTY, received(listener, null)); 612 compare(EMPTY, received(listener, handback)); 613 } 614 615 public void testRegisterTwoRemoveOneTripletListener() 616 throws Exception 617 { 618 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 619 620 Listener listener = new Listener(); 621 Object handback = new Object (); 622 NotificationFilterSupport filter = new NotificationFilterSupport (); 623 filter.enableType(DEFAULT_TYPE); 624 broadcaster.addNotificationListener(listener, filter, handback); 625 broadcaster.addNotificationListener(listener, null, null); 626 broadcaster.removeNotificationListener(listener, null, null); 627 628 createNotification(broadcaster); 629 630 compare(EMPTY, received(listener, null)); 631 compare(sent, received(listener, handback)); 632 } 633 634 public void testRegisterTwoRemoveOneTripletListenerFilter() 635 throws Exception 636 { 637 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 638 639 Listener listener = new Listener(); 640 Object handback = new Object (); 641 NotificationFilterSupport filter = new NotificationFilterSupport (); 642 filter.enableType(DEFAULT_TYPE); 643 broadcaster.addNotificationListener(listener, filter, handback); 644 broadcaster.addNotificationListener(listener, filter, null); 645 broadcaster.removeNotificationListener(listener, filter, null); 646 647 createNotification(broadcaster); 648 649 compare(EMPTY, received(listener, null)); 650 compare(sent, received(listener, handback)); 651 } 652 653 public void testRegisterTwoRemoveOneTripletListenerHandback() 654 throws Exception 655 { 656 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 657 658 Listener listener = new Listener(); 659 Object handback = new Object (); 660 NotificationFilterSupport filter = new NotificationFilterSupport (); 661 filter.enableType(DEFAULT_TYPE); 662 broadcaster.addNotificationListener(listener, filter, handback); 663 broadcaster.addNotificationListener(listener, null, handback); 664 broadcaster.removeNotificationListener(listener, null, handback); 665 666 createNotification(broadcaster); 667 668 compare(EMPTY, received(listener, null)); 669 compare(sent, received(listener, handback)); 670 } 671 672 public void testRegisterTwoRemoveOneTripletListenerFilterHandback() 673 throws Exception 674 { 675 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 676 677 Listener listener = new Listener(); 678 Object handback = new Object (); 679 NotificationFilterSupport filter = new NotificationFilterSupport (); 680 filter.enableType(DEFAULT_TYPE); 681 broadcaster.addNotificationListener(listener, null, null); 682 broadcaster.addNotificationListener(listener, filter, handback); 683 broadcaster.removeNotificationListener(listener, filter, handback); 684 685 createNotification(broadcaster); 686 687 compare(sent, received(listener, null)); 688 compare(EMPTY, received(listener, handback)); 689 } 690 691 public void testRemoveTripletErrors() 692 throws Exception 693 { 694 NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport (); 695 Object handback = new Object (); 696 NotificationFilterSupport filter = new NotificationFilterSupport (); 697 filter.enableType(DEFAULT_TYPE); 698 699 Listener listener = new Listener(); 700 701 boolean caught = false; 702 try 703 { 704 broadcaster.removeNotificationListener(null, null, null); 705 } 706 catch (ListenerNotFoundException e) 707 { 708 caught = true; 709 } 710 assertTrue("Expected ListenerNotFoundException for null listener", caught); 711 712 caught = false; 713 try 714 { 715 broadcaster.removeNotificationListener(listener, null, null); 716 } 717 catch (ListenerNotFoundException e) 718 { 719 caught = true; 720 } 721 assertTrue("Expected ListenerNotFoundException for listener never added", caught); 722 723 caught = false; 724 try 725 { 726 broadcaster.addNotificationListener(listener, null, null); 727 broadcaster.removeNotificationListener(listener, null, null); 728 broadcaster.removeNotificationListener(listener, null, null); 729 } 730 catch (ListenerNotFoundException e) 731 { 732 caught = true; 733 } 734 assertTrue("Expected ListenerNotFoundException for listener remove twice", caught); 735 736 caught = false; 737 try 738 { 739 broadcaster.addNotificationListener(listener, filter, null); 740 broadcaster.removeNotificationListener(listener, new NotificationFilterSupport (), null); 741 } 742 catch (ListenerNotFoundException e) 743 { 744 caught = true; 745 broadcaster.removeNotificationListener(listener, filter, null); 746 } 747 assertTrue("Expected ListenerNotFoundException for wrong filter", caught); 748 749 caught = false; 750 try 751 { 752 broadcaster.addNotificationListener(listener, null, handback); 753 broadcaster.removeNotificationListener(listener, null, new Object ()); 754 } 755 catch (ListenerNotFoundException e) 756 { 757 caught = true; 758 broadcaster.removeNotificationListener(listener, null, handback); 759 } 760 assertTrue("Expected ListenerNotFoundException for wrong handback", caught); 761 762 caught = false; 763 try 764 { 765 broadcaster.addNotificationListener(listener, filter, handback); 766 broadcaster.removeNotificationListener(listener, new NotificationFilterSupport (), new Object ()); 767 } 768 catch (ListenerNotFoundException e) 769 { 770 caught = true; 771 broadcaster.removeNotificationListener(listener, filter, handback); 772 } 773 assertTrue("Expected ListenerNotFoundException for wrong filter and handback", caught); 774 775 caught = false; 776 try 777 { 778 broadcaster.addNotificationListener(listener, filter, handback); 779 broadcaster.removeNotificationListener(listener, null, null); 780 } 781 catch (ListenerNotFoundException e) 782 { 783 caught = true; 784 broadcaster.removeNotificationListener(listener, filter, handback); 785 } 786 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 1", caught); 787 788 caught = false; 789 try 790 { 791 broadcaster.addNotificationListener(listener, filter, handback); 792 broadcaster.removeNotificationListener(listener, filter, null); 793 } 794 catch (ListenerNotFoundException e) 795 { 796 caught = true; 797 broadcaster.removeNotificationListener(listener, filter, handback); 798 } 799 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 2", caught); 800 801 caught = false; 802 try 803 { 804 broadcaster.addNotificationListener(listener, filter, handback); 805 broadcaster.removeNotificationListener(listener, null, handback); 806 } 807 catch (ListenerNotFoundException e) 808 { 809 caught = true; 810 broadcaster.removeNotificationListener(listener, filter, handback); 811 } 812 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 3", caught); 813 814 caught = false; 815 try 816 { 817 broadcaster.addNotificationListener(listener, filter, null); 818 broadcaster.removeNotificationListener(listener, null, null); 819 } 820 catch (ListenerNotFoundException e) 821 { 822 caught = true; 823 broadcaster.removeNotificationListener(listener, filter, null); 824 } 825 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 4", caught); 826 827 caught = false; 828 try 829 { 830 broadcaster.addNotificationListener(listener, filter, null); 831 broadcaster.removeNotificationListener(listener, null, handback); 832 } 833 catch (ListenerNotFoundException e) 834 { 835 caught = true; 836 broadcaster.removeNotificationListener(listener, filter, null); 837 } 838 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 5", caught); 839 840 caught = false; 841 try 842 { 843 broadcaster.addNotificationListener(listener, filter, null); 844 broadcaster.removeNotificationListener(listener, filter, handback); 845 } 846 catch (ListenerNotFoundException e) 847 { 848 caught = true; 849 broadcaster.removeNotificationListener(listener, filter, null); 850 } 851 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 6", caught); 852 853 caught = false; 854 try 855 { 856 broadcaster.addNotificationListener(listener, null, handback); 857 broadcaster.removeNotificationListener(listener, null, null); 858 } 859 catch (ListenerNotFoundException e) 860 { 861 caught = true; 862 broadcaster.removeNotificationListener(listener, null, handback); 863 } 864 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 7", caught); 865 866 caught = false; 867 try 868 { 869 broadcaster.addNotificationListener(listener, null, handback); 870 broadcaster.removeNotificationListener(listener, filter, null); 871 } 872 catch (ListenerNotFoundException e) 873 { 874 caught = true; 875 broadcaster.removeNotificationListener(listener, null, handback); 876 } 877 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 8", caught); 878 879 caught = false; 880 try 881 { 882 broadcaster.addNotificationListener(listener, null, handback); 883 broadcaster.removeNotificationListener(listener, filter, handback); 884 } 885 catch (ListenerNotFoundException e) 886 { 887 caught = true; 888 broadcaster.removeNotificationListener(listener, null, handback); 889 } 890 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 9", caught); 891 892 caught = false; 893 try 894 { 895 broadcaster.addNotificationListener(listener, null, null); 896 broadcaster.removeNotificationListener(listener, filter, null); 897 } 898 catch (ListenerNotFoundException e) 899 { 900 caught = true; 901 broadcaster.removeNotificationListener(listener, null, null); 902 } 903 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 10", caught); 904 905 caught = false; 906 try 907 { 908 broadcaster.addNotificationListener(listener, null, null); 909 broadcaster.removeNotificationListener(listener, null, handback); 910 } 911 catch (ListenerNotFoundException e) 912 { 913 caught = true; 914 broadcaster.removeNotificationListener(listener, null, null); 915 } 916 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 11", caught); 917 918 caught = false; 919 try 920 { 921 broadcaster.addNotificationListener(listener, null, null); 922 broadcaster.removeNotificationListener(listener, filter, handback); 923 } 924 catch (ListenerNotFoundException e) 925 { 926 caught = true; 927 broadcaster.removeNotificationListener(listener, null, null); 928 } 929 assertTrue("Expected ListenerNotFoundException for listener remove with wrong triplet 12", caught); 930 } 931 932 934 private void createNotification(NotificationBroadcasterSupport broadcaster) 935 { 936 createNotification(broadcaster, DEFAULT_TYPE); 937 } 938 939 private void createNotification(NotificationBroadcasterSupport broadcaster, String type) 940 { 941 synchronized(this) 942 { 943 sequence++; 944 } 945 Notification notification = new Notification (type, broadcaster, sequence); 946 sent.add(notification); 947 broadcaster.sendNotification(notification); 948 } 949 950 private void clear() 951 { 952 sent.clear(); 953 } 954 955 private ArrayList apply(ArrayList sent, NotificationFilterSupport filter) 956 { 957 ArrayList result = new ArrayList (); 958 for (Iterator iterator = sent.iterator(); iterator.hasNext();) 959 { 960 Notification notification = (Notification ) iterator.next(); 961 if (filter.isNotificationEnabled(notification)) 962 result.add(notification); 963 } 964 return result; 965 } 966 967 private ArrayList received(Listener listener, Object object) 968 { 969 ArrayList result = (ArrayList ) listener.notifications.get(object); 970 if (result == null) 971 result = EMPTY; 972 return result; 973 } 974 975 private void compare(ArrayList passedSent, ArrayList passedReceived) 976 throws Exception 977 { 978 ArrayList sent = new ArrayList (passedSent); 979 ArrayList received = new ArrayList (passedReceived); 980 981 for (Iterator iterator = sent.iterator(); iterator.hasNext();) 982 { 983 Notification notification = (Notification ) iterator.next(); 984 boolean found = received.remove(notification); 985 assertTrue("Expected notification " + notification, found); 986 } 987 988 assertTrue("Didn't expect notification(s) " + received, received.isEmpty()); 989 } 990 } | Popular Tags |