Skip to content

Commit 4755984

Browse files
author
Nicolai Parlog
committed
Implemented tests for the case that the nesting's inner observable is missing.
1 parent 22d88d9 commit 4755984

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public void testChangingOldObservablesValue() {
8484
assertFalse(getPropertyValue());
8585
}
8686

87+
@Override
88+
@Test
89+
public void testChangedValueNotPropagationAfterObservableWasMissing() {
90+
// set the nesting observable and change the nested property's value to 'true'
91+
setNestingObservable(getNesting(), null);
92+
getProperty().setValue(true);
93+
94+
// set the new observable and assert that the property reflects its value, i.e. holds 'false'
95+
BooleanProperty newObservable = createNewObservableWithValue(false);
96+
setNestingObservable(getNesting(), newObservable);
97+
assertFalse(getPropertyValue());
98+
}
99+
87100
//#end OVERRIDDEN TEST METHODS
88101

89102
}

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,42 @@ public void testChangingObservableToNull() {
129129
assertFalse(property.isInnerObservablePresent());
130130
}
131131

132+
/**
133+
* Tests whether changing the nested property's value while the nesting's observable is missing works.
134+
*/
135+
@Test
136+
public void testChangingValueWhileObservableIsMissing() {
137+
// set the nesting observable to null
138+
setNestingObservable(nesting, null);
139+
140+
// set a new value (which can not be written to the nesting's observable as none is present)
141+
T newValue = createNewValue();
142+
property.setValue(newValue);
143+
144+
// assert that the property indeed holds the new value
145+
assertEquals(newValue, property.getValue());
146+
}
147+
148+
/**
149+
* Tests whether the nested property's value, which was changed while the nesting's observable was missing, will not
150+
* propagate to an observable which will be set thereafter.
151+
*/
152+
@Test
153+
public void testChangedValueNotPropagationAfterObservableWasMissing() {
154+
// set the nesting observable to null and create the new observable
155+
setNestingObservable(nesting, null);
156+
P newObservable = createNewObservableWithValue(createNewValue());
157+
158+
// change the nested property's value (which can not be written to the nesting's observable as none is present);
159+
// due to the contract of 'createNewValue' the nested property has currently another value than the new observable
160+
property.setValue(createNewValue());
161+
assertNotEquals(newObservable.getValue(), property.getValue());
162+
163+
// set the new observable and assert that the property reflects its value
164+
setNestingObservable(nesting, newObservable);
165+
assertEquals(newObservable.getValue(), property.getValue());
166+
}
167+
132168
/**
133169
* Tests whether the property's value is correctly updated when the nesting's new observable gets a new value.
134170
*/
@@ -196,7 +232,8 @@ public void testChangingOldObservablesValue() {
196232
protected abstract NestedProperty<T> createNestedPropertyFromNesting(Nesting<P> nesting);
197233

198234
/**
199-
* Creates a new value. Each call must return a new instance.
235+
* Creates a new value. Each call must return an instance which is not equal to any of those returned before and to
236+
* that contained in the observable returned by {@link #createNewObservableWithSomeValue()}.
200237
*
201238
* @return a new instance of type {@code T}
202239
*/

0 commit comments

Comments
 (0)