Skip to content

Commit 47904d7

Browse files
author
nicolaiparlog
committed
Fix tests for NestedBooleanProperty
1 parent 7d44a67 commit 47904d7

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/test/java/org/codefx/libfx/nesting/property/AbstractNestedBooleanPropertyTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package 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;
36
import javafx.beans.property.BooleanProperty;
47
import javafx.beans.property.SimpleBooleanProperty;
58

69
import org.codefx.libfx.nesting.Nesting;
10+
import org.codefx.libfx.nesting.property.InnerObservableMissingBehavior.WhenInnerObservableMissingOnUpdate;
711
import 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

src/test/java/org/codefx/libfx/nesting/property/AbstractNestedPropertyTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public void newInnerObservableAfterSetValueOnMissingInnerObservable_acceptUntilN
224224

225225
// set the new observable and assert that it kept its value and the nested property was updated
226226
setNestingObservable(nesting, newObservable);
227+
227228
assertSameOrEqual(newInnerObservablesValue, newObservable.getValue(), wrapsPrimitive());
228229
assertSameOrEqual(newInnerObservablesValue, property.getValue(), wrapsPrimitive());
229230
}

0 commit comments

Comments
 (0)