@@ -682,7 +682,7 @@ public void shouldNotForgetCurrentValueWhenMovingFromGenericToSingleChangeImplem
682
682
StringProperty p = new SimpleStringProperty ("a" ) {
683
683
@ Override
684
684
protected void invalidated () {
685
- removeListener (invalidationListener );
685
+ removeListener (invalidationListener ); // this removal occurs before notification
686
686
}
687
687
};
688
688
@@ -693,6 +693,56 @@ protected void invalidated() {
693
693
694
694
assertFalse (invalidated .get ()); // false because the invalidation listener was removed before called
695
695
assertEquals ("b" , currentValue .get ());
696
+
697
+ p .set ("a" ); // if current value wasn't copied correctly (it is still "a") then this wouldn't trigger a change
698
+
699
+ assertEquals ("a" , currentValue .get ());
700
+ }
701
+
702
+ @ Test
703
+ public void shouldNotForgetCurrentValueWhenMovingFromChangeListenerAndInvalidationListenerToSingleChangeListener () {
704
+ AtomicReference <String > currentValue = new AtomicReference <>();
705
+ StringProperty p = new SimpleStringProperty ("a" );
706
+ InvalidationListener invalidationListener = new InvalidationListener () {
707
+ @ Override
708
+ public void invalidated (Observable obs ) {
709
+ p .removeListener (this ); // this removal occurs during notification
710
+ }
711
+ };
712
+
713
+ p .addListener (invalidationListener );
714
+ p .addListener ((obs , old , current ) -> currentValue .set (current ));
715
+
716
+ p .set ("b" );
717
+
718
+ assertEquals ("b" , currentValue .get ());
719
+
720
+ p .set ("a" ); // if current value wasn't copied correctly (it is still "a") then this wouldn't trigger a change
721
+
722
+ assertEquals ("a" , currentValue .get ());
723
+ }
724
+
725
+ @ Test
726
+ public void shouldNotForgetCurrentValueWhenMovingFromTwoChangeListenersToSingleChangeListener () {
727
+ AtomicReference <String > currentValue = new AtomicReference <>();
728
+ StringProperty p = new SimpleStringProperty ("a" );
729
+ ChangeListener <String > changeListener = new ChangeListener <>() {
730
+ @ Override
731
+ public void changed (ObservableValue <? extends String > observable , String oldValue , String newValue ) {
732
+ p .removeListener (this );
733
+ }
734
+ };
735
+
736
+ p .addListener (changeListener );
737
+ p .addListener ((obs , old , current ) -> currentValue .set (current ));
738
+
739
+ p .set ("b" );
740
+
741
+ assertEquals ("b" , currentValue .get ());
742
+
743
+ p .set ("a" ); // if current value wasn't copied correctly (it is still "a") then this wouldn't trigger a change
744
+
745
+ assertEquals ("a" , currentValue .get ());
696
746
}
697
747
698
748
@ Test
0 commit comments