1
1
package org .codefx .libfx .nesting .property ;
2
2
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 ;
3
6
import javafx .beans .property .BooleanProperty ;
4
7
import javafx .beans .property .SimpleBooleanProperty ;
5
8
6
9
import org .codefx .libfx .nesting .Nesting ;
10
+ import org .codefx .libfx .nesting .property .InnerObservableMissingBehavior .WhenInnerObservableMissingOnUpdate ;
7
11
import org .junit .Test ;
8
12
9
13
/**
@@ -16,8 +20,8 @@ public abstract class AbstractNestedBooleanPropertyTest extends
16
20
17
21
/*
18
22
* 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.
21
25
*/
22
26
23
27
@ Override
@@ -42,13 +46,32 @@ protected BooleanProperty createNewObservableWithSomeValue() {
42
46
43
47
// #begin OVERRIDDEN TEST METHODS
44
48
49
+ // #begin TESTS
50
+
45
51
@ Override
46
52
@ Test
47
53
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 );
50
63
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
+ }
52
75
53
76
//#end OVERRIDDEN TEST METHODS
54
77
0 commit comments