Skip to content

Commit db4e766

Browse files
author
Nicolai Parlog
committed
Tests now assert that nested properties correctly update their 'observableNull' property.
1 parent 4a7eb4f commit db4e766

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

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

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import static org.codefx.nesting.testhelper.NestingAccess.getNestingValue;
55
import static org.codefx.nesting.testhelper.NestingAccess.setNestingObservable;
66
import static org.codefx.nesting.testhelper.NestingAccess.setNestingValue;
7+
import static org.junit.Assert.assertFalse;
78
import static org.junit.Assert.assertNotSame;
89
import static org.junit.Assert.assertNull;
910
import static org.junit.Assert.assertSame;
11+
import static org.junit.Assert.assertTrue;
1012
import javafx.beans.property.Property;
1113

1214
import org.codefx.nesting.Nesting;
@@ -56,6 +58,7 @@ public void setUp() {
5658
@Test
5759
public void testInnerValueAfterConstruction() {
5860
assertSame(getNestingValue(nesting), property.getValue());
61+
assertFalse(property.isInnerObservableNull());
5962
}
6063

6164
/**
@@ -74,17 +77,19 @@ public void testChangingValue() {
7477
}
7578

7679
/**
77-
* Tests whether the property's value is not updated when the nesting gets null as a new observable.
80+
* Tests whether the property's value is correctly updated when the nesting's observable changes its value to null.
7881
*/
7982
@Test
80-
public void testChangingObservableToNull() {
81-
T oldValue = property.getValue();
82-
setNestingObservable(nesting, null);
83-
// assert that setting the null observable worked
84-
assertNull(getNestingObservable(nesting));
83+
public void testChangingValueToNull() {
84+
if (!allowsNullValues())
85+
return;
8586

86-
// assert that the nesting still holds the old value
87-
assertSame(oldValue, property.getValue());
87+
setNestingValue(nesting, null);
88+
// assert that setting the value worked
89+
assertNull(getNestingValue(nesting));
90+
91+
// assert that the property holds null
92+
assertNull(property.getValue());
8893
}
8994

9095
/**
@@ -101,6 +106,24 @@ public void testChangingObservable() {
101106
// assert that nesting and property hold the new value
102107
assertSame(getNestingValue(nesting), property.getValue());
103108
assertSame(newValue, property.getValue());
109+
// assert that 'isInnerObservableNull' is still false
110+
assertFalse(property.isInnerObservableNull());
111+
}
112+
113+
/**
114+
* Tests whether the property's value is not updated when the nesting gets null as a new observable.
115+
*/
116+
@Test
117+
public void testChangingObservableToNull() {
118+
T oldValue = property.getValue();
119+
setNestingObservable(nesting, null);
120+
// assert that setting the null observable worked
121+
assertNull(getNestingObservable(nesting));
122+
123+
// assert that the nesting still holds the old value
124+
assertSame(oldValue, property.getValue());
125+
// assert that 'isInnerObservableNull' is now true
126+
assertTrue(property.isInnerObservableNull());
104127
}
105128

106129
/**
@@ -153,6 +176,13 @@ public void testChangingOldObservablesValue() {
153176

154177
// #region ABSTRACT METHODS
155178

179+
/**
180+
* Indicates whether the tested nested property allows null values.
181+
*
182+
* @return true if the nested properties allows null values
183+
*/
184+
protected abstract boolean allowsNullValues();
185+
156186
/**
157187
* Creates the property, which will be tested, from the specified nesting.
158188
*

test/org/codefx/nesting/property/NestedIntegerPropertyTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public class NestedIntegerPropertyTest extends AbstractNestedPropertyTest<Number
1515
*/
1616
private int nextValue = 1;
1717

18+
@Override
19+
protected boolean allowsNullValues() {
20+
return false;
21+
}
22+
1823
@Override
1924
protected NestedIntegerProperty createNestedPropertyFromNesting(Nesting<Property<Number>> nesting) {
2025
return new NestedIntegerProperty(nesting, null, null);

test/org/codefx/nesting/property/NestedObjectPropertyTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
public class NestedObjectPropertyTest extends AbstractNestedPropertyTest<SomeValue> {
1313

14+
@Override
15+
protected boolean allowsNullValues() {
16+
return true;
17+
}
18+
1419
@Override
1520
protected NestedProperty<SomeValue> createNestedPropertyFromNesting(Nesting<Property<SomeValue>> nesting) {
1621
return new NestedObjectProperty<>(nesting, null, null);

0 commit comments

Comments
 (0)