6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.collections;
27
28 import com.sun.javafx.binding.SetExpressionHelper;
29 import javafx.beans.InvalidationListener;
30 import javafx.beans.InvalidationListenerMock;
31 import javafx.beans.Observable;
32 import javafx.collections.FXCollections;
33 import javafx.collections.ListChangeListener;
34 import javafx.collections.MockSetObserver;
35 import javafx.collections.ObservableSet;
36 import javafx.collections.SetChangeListener;
37 import org.junit.Before;
38 import org.junit.Test;
39
40 import java.util.BitSet;
41 import java.util.concurrent.atomic.AtomicBoolean;
42 import java.util.concurrent.atomic.AtomicInteger;
43
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertFalse;
46 import static org.junit.Assert.assertTrue;
47
48 public class SetListenerHelperTest {
49
50 private InvalidationListenerMock[] invalidationListenerMock;
51
52 private MockSetObserver<Object>[] changeListenerMock;
53
54 private SetListenerHelper<Object> helper;
604 assertEquals(1, changeListenerMock[3].getCallsNumber());
605 assertEquals(0, changeListenerMock[1].getCallsNumber());
606 assertEquals(0, changeListenerMock[2].getCallsNumber());
607
608 helper = SetListenerHelper.addListener(helper, removeListener);
609 SetListenerHelper.fireValueChangedEvent(helper, change);
610 helper = SetListenerHelper.removeListener(helper, removeListener);
611 resetAllListeners();
612 SetListenerHelper.fireValueChangedEvent(helper, change);
613 assertEquals(0, changeListenerMock[0].getCallsNumber());
614 assertEquals(0, changeListenerMock[3].getCallsNumber());
615 assertEquals(0, changeListenerMock[1].getCallsNumber());
616 assertEquals(0, changeListenerMock[2].getCallsNumber());
617 }
618
619
620
621 @Test
622 public void testExceptionNotPropagatedFromSingleInvalidation() {
623 helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();});
624 helper.fireValueChangedEvent(change);
625 }
626
627 @Test
628 public void testExceptionNotPropagatedFromMultipleInvalidation() {
629 BitSet called = new BitSet();
630
631 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();});
632 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();});
633
634 helper.fireValueChangedEvent(change);
635
636 assertTrue(called.get(0));
637 assertTrue(called.get(1));
638 }
639
640 @Test
641 public void testExceptionNotPropagatedFromSingleChange() {
642 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {
643 throw new RuntimeException();
644 });
645 helper.fireValueChangedEvent(change);
646 }
647
648 @Test
649 public void testExceptionNotPropagatedFromMultipleChange() {
650 BitSet called = new BitSet();
651
652 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(0); throw new RuntimeException();});
653 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(1); throw new RuntimeException();});
654 helper.fireValueChangedEvent(change);
655
656 assertTrue(called.get(0));
657 assertTrue(called.get(1));
658 }
659
660 @Test
661 public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() {
662 BitSet called = new BitSet();
663
664 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(0); throw new RuntimeException();});
665 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(1); throw new RuntimeException();});
666 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();});
667 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();});
668 helper.fireValueChangedEvent(change);
669
670 assertTrue(called.get(0));
671 assertTrue(called.get(1));
672 assertTrue(called.get(2));
673 assertTrue(called.get(3));
674 }
675
676
677 @Test
678 public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() {
679 AtomicBoolean called = new AtomicBoolean(false);
680
681 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true));
682
683 helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();});
684 helper.fireValueChangedEvent(change);
685
686 assertTrue(called.get());
687 }
688
689
690 @Test
691 public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() {
692 AtomicInteger called = new AtomicInteger(0);
693
694 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
695
696 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
697 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
698 helper.fireValueChangedEvent(change);
699
700 assertEquals(2, called.get());
701 }
702
703 @Test
704 public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() {
705 AtomicBoolean called = new AtomicBoolean(false);
706
707 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true));
708 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
709 helper.fireValueChangedEvent(change);
710
711 assertTrue(called.get());
712 }
713
714 @Test
715 public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() {
716 AtomicInteger called = new AtomicInteger(0);
717
718 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
719
720 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
721 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
722 helper.fireValueChangedEvent(change);
723
724 assertEquals(2, called.get());
725 }
726
727 @Test
728 public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() {
729 AtomicInteger called = new AtomicInteger(0);
730
731 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
732
733 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> { throw new RuntimeException();});
734 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> { throw new RuntimeException();});
735 helper = SetListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();});
736 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
737 helper.fireValueChangedEvent(change);
738
739 assertEquals(4, called.get());
740 }
741
742 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.com.sun.javafx.collections;
27
28 import com.sun.javafx.binding.SetExpressionHelper;
29 import com.sun.javafx.collections.SetListenerHelper;
30 import javafx.beans.InvalidationListener;
31 import test.javafx.beans.InvalidationListenerMock;
32 import javafx.beans.Observable;
33 import javafx.collections.FXCollections;
34 import test.javafx.collections.MockSetObserver;
35 import javafx.collections.ObservableSet;
36 import javafx.collections.SetChangeListener;
37 import org.junit.Before;
38 import org.junit.Test;
39
40 import java.util.BitSet;
41 import java.util.concurrent.atomic.AtomicBoolean;
42 import java.util.concurrent.atomic.AtomicInteger;
43
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertFalse;
46 import static org.junit.Assert.assertTrue;
47
48 public class SetListenerHelperTest {
49
50 private InvalidationListenerMock[] invalidationListenerMock;
51
52 private MockSetObserver<Object>[] changeListenerMock;
53
54 private SetListenerHelper<Object> helper;
604 assertEquals(1, changeListenerMock[3].getCallsNumber());
605 assertEquals(0, changeListenerMock[1].getCallsNumber());
606 assertEquals(0, changeListenerMock[2].getCallsNumber());
607
608 helper = SetListenerHelper.addListener(helper, removeListener);
609 SetListenerHelper.fireValueChangedEvent(helper, change);
610 helper = SetListenerHelper.removeListener(helper, removeListener);
611 resetAllListeners();
612 SetListenerHelper.fireValueChangedEvent(helper, change);
613 assertEquals(0, changeListenerMock[0].getCallsNumber());
614 assertEquals(0, changeListenerMock[3].getCallsNumber());
615 assertEquals(0, changeListenerMock[1].getCallsNumber());
616 assertEquals(0, changeListenerMock[2].getCallsNumber());
617 }
618
619
620
621 @Test
622 public void testExceptionNotPropagatedFromSingleInvalidation() {
623 helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();});
624 SetListenerHelper.fireValueChangedEvent(helper,change);
625 }
626
627 @Test
628 public void testExceptionNotPropagatedFromMultipleInvalidation() {
629 BitSet called = new BitSet();
630
631 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(0); throw new RuntimeException();});
632 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(1); throw new RuntimeException();});
633
634 SetListenerHelper.fireValueChangedEvent(helper,change);
635
636 assertTrue(called.get(0));
637 assertTrue(called.get(1));
638 }
639
640 @Test
641 public void testExceptionNotPropagatedFromSingleChange() {
642 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {
643 throw new RuntimeException();
644 });
645 SetListenerHelper.fireValueChangedEvent(helper,change);
646 }
647
648 @Test
649 public void testExceptionNotPropagatedFromMultipleChange() {
650 BitSet called = new BitSet();
651
652 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(0); throw new RuntimeException();});
653 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(1); throw new RuntimeException();});
654 SetListenerHelper.fireValueChangedEvent(helper,change);
655
656 assertTrue(called.get(0));
657 assertTrue(called.get(1));
658 }
659
660 @Test
661 public void testExceptionNotPropagatedFromMultipleChangeAndInvalidation() {
662 BitSet called = new BitSet();
663
664 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(0); throw new RuntimeException();});
665 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {called.set(1); throw new RuntimeException();});
666 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(2); throw new RuntimeException();});
667 helper = SetListenerHelper.addListener(helper, (Observable o) -> {called.set(3); throw new RuntimeException();});
668 SetListenerHelper.fireValueChangedEvent(helper,change);
669
670 assertTrue(called.get(0));
671 assertTrue(called.get(1));
672 assertTrue(called.get(2));
673 assertTrue(called.get(3));
674 }
675
676
677 @Test
678 public void testExceptionHandledByThreadUncaughtHandlerInSingleInvalidation() {
679 AtomicBoolean called = new AtomicBoolean(false);
680
681 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true));
682
683 helper = SetListenerHelper.addListener(helper,(Observable o) -> {throw new RuntimeException();});
684 SetListenerHelper.fireValueChangedEvent(helper,change);
685
686 assertTrue(called.get());
687 }
688
689
690 @Test
691 public void testExceptionHandledByThreadUncaughtHandlerInMultipleInvalidation() {
692 AtomicInteger called = new AtomicInteger(0);
693
694 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
695
696 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
697 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
698 SetListenerHelper.fireValueChangedEvent(helper,change);
699
700 assertEquals(2, called.get());
701 }
702
703 @Test
704 public void testExceptionHandledByThreadUncaughtHandlerInSingleChange() {
705 AtomicBoolean called = new AtomicBoolean(false);
706
707 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.set(true));
708 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
709 SetListenerHelper.fireValueChangedEvent(helper,change);
710
711 assertTrue(called.get());
712 }
713
714 @Test
715 public void testExceptionHandledByThreadUncaughtHandlerInMultipleChange() {
716 AtomicInteger called = new AtomicInteger(0);
717
718 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
719
720 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
721 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> {throw new RuntimeException();});
722 SetListenerHelper.fireValueChangedEvent(helper,change);
723
724 assertEquals(2, called.get());
725 }
726
727 @Test
728 public void testExceptionHandledByThreadUncaughtHandlerInMultipleChangeAndInvalidation() {
729 AtomicInteger called = new AtomicInteger(0);
730
731 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> called.incrementAndGet());
732
733 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> { throw new RuntimeException();});
734 helper = SetListenerHelper.addListener(helper, (SetChangeListener.Change<? extends Object> c) -> { throw new RuntimeException();});
735 helper = SetListenerHelper.addListener(helper, (Observable o) -> { throw new RuntimeException();});
736 helper = SetListenerHelper.addListener(helper, (Observable o) -> {throw new RuntimeException();});
737 SetListenerHelper.fireValueChangedEvent(helper,change);
738
739 assertEquals(4, called.get());
740 }
741
742 }
|