4
4
import static org .codefx .nesting .testhelper .NestingAccess .getNestingValue ;
5
5
import static org .codefx .nesting .testhelper .NestingAccess .setNestingObservable ;
6
6
import static org .codefx .nesting .testhelper .NestingAccess .setNestingValue ;
7
+ import static org .junit .Assert .assertFalse ;
7
8
import static org .junit .Assert .assertNotSame ;
8
9
import static org .junit .Assert .assertNull ;
9
10
import static org .junit .Assert .assertSame ;
11
+ import static org .junit .Assert .assertTrue ;
10
12
import javafx .beans .property .Property ;
11
13
12
14
import org .codefx .nesting .Nesting ;
@@ -56,6 +58,7 @@ public void setUp() {
56
58
@ Test
57
59
public void testInnerValueAfterConstruction () {
58
60
assertSame (getNestingValue (nesting ), property .getValue ());
61
+ assertFalse (property .isInnerObservableNull ());
59
62
}
60
63
61
64
/**
@@ -74,17 +77,19 @@ public void testChangingValue() {
74
77
}
75
78
76
79
/**
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 .
78
81
*/
79
82
@ 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 ;
85
86
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 ());
88
93
}
89
94
90
95
/**
@@ -101,6 +106,24 @@ public void testChangingObservable() {
101
106
// assert that nesting and property hold the new value
102
107
assertSame (getNestingValue (nesting ), property .getValue ());
103
108
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 ());
104
127
}
105
128
106
129
/**
@@ -153,6 +176,13 @@ public void testChangingOldObservablesValue() {
153
176
154
177
// #region ABSTRACT METHODS
155
178
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
+
156
186
/**
157
187
* Creates the property, which will be tested, from the specified nesting.
158
188
*
0 commit comments