11package org .codefx .libfx .nesting .property ;
22
3+ import static org .codefx .libfx .nesting .testhelper .NestingAccess .setNestingObservable ;
4+ import static org .codefx .tarkastus .AssertFX .assertSameOrEqual ;
5+ import static org .junit .Assert .assertNotEquals ;
36import javafx .beans .property .BooleanProperty ;
47import javafx .beans .property .SimpleBooleanProperty ;
58
69import org .codefx .libfx .nesting .Nesting ;
10+ import org .codefx .libfx .nesting .property .InnerObservableMissingBehavior .WhenInnerObservableMissingOnUpdate ;
711import org .junit .Test ;
812
913/**
@@ -16,8 +20,8 @@ public abstract class AbstractNestedBooleanPropertyTest extends
1620
1721 /*
1822 * Since Boolean has only two values, 'createNewValue' can not fulfill its contract. Instead it always returns
19- * 'true' whereas 'createNewObservableWithSomeValue' uses false. All tests where this might come into play are
20- * overridden below (for better readability or just to make them work) .
23+ * 'true' whereas 'createNewObservableWithSomeValue' uses false. All tests where this leads to a failing test are
24+ * overridden below.
2125 */
2226
2327 @ Override
@@ -42,13 +46,32 @@ protected BooleanProperty createNewObservableWithSomeValue() {
4246
4347 // #begin OVERRIDDEN TEST METHODS
4448
49+ // #begin TESTS
50+
4551 @ Override
4652 @ Test
4753 public void newInnerObservableAfterSetValueOnMissingInnerObservable_acceptUntilNext_newInnerObservableKeepsValue () {
48- // TODO rewrite test so that it passes
49- }
54+ boolean valueWhileMissing = true ;
55+ boolean valueOfNewInnerObservable = false ;
56+
57+ MissingBehavior <Boolean > missingBehavior = MissingBehavior
58+ .<Boolean > defaults ()
59+ .onUpdate (WhenInnerObservableMissingOnUpdate .ACCEPT_VALUE_UNTIL_NEXT_INNER_OBSERVABLE );
60+ NestedProperty <Boolean > property = createNestedPropertyFromNesting (getNesting (), missingBehavior );
61+ setNestingObservable (getNesting (), null );
62+ BooleanProperty newObservable = createNewObservableWithValue (valueOfNewInnerObservable );
5063
51- // TODO adapt other tests as described in implementation comment or change the comment
64+ // change the nested property's value (which can not be written to the nesting's observable as none is present);
65+ property .setValue (valueWhileMissing );
66+ // the values of the nested property and the new observable are not equal
67+ assertNotEquals (newObservable .getValue (), property .getValue ());
68+
69+ // set the new observable and assert that it kept its value and the nested property was updated
70+ setNestingObservable (getNesting (), newObservable );
71+
72+ assertSameOrEqual (valueOfNewInnerObservable , newObservable .getValue (), wrapsPrimitive ());
73+ assertSameOrEqual (valueOfNewInnerObservable , property .getValue (), wrapsPrimitive ());
74+ }
5275
5376 //#end OVERRIDDEN TEST METHODS
5477
0 commit comments