2828import com .sun .javafx .binding .BidirectionalBinding ;
2929import javafx .beans .binding .Bindings ;
3030import javafx .beans .property .*;
31- import org . junit . Before ;
32- import org .junit .Test ;
33- import org .junit .runner . RunWith ;
34- import org .junit .runners . Parameterized ;
31+
32+ import org .junit .jupiter . api . Test ;
33+ import org .junit .jupiter . params . ParameterizedTest ;
34+ import org .junit .jupiter . params . provider . MethodSource ;
3535
3636import java .util .Arrays ;
3737import java .util .Collection ;
3838import javafx .beans .value .ObservableValue ;
3939
40- import static org .junit .Assert .*;
40+ import static org .junit .jupiter . api . Assertions .*;
4141
42- @ RunWith (Parameterized .class )
4342public class BidirectionalBindingTest <T > {
4443
4544 @ FunctionalInterface
@@ -70,12 +69,8 @@ public T[] getValues() {
7069 private Property <T > op4 ;
7170 private T [] v ;
7271
73- public BidirectionalBindingTest (Factory <T > factory ) {
72+ private void setUp (Factory <T > factory ) {
7473 this .factory = factory ;
75- }
76-
77- @ Before
78- public void setUp () {
7974 op1 = factory .createProperty ();
8075 op2 = factory .createProperty ();
8176 op3 = factory .createProperty ();
@@ -85,8 +80,10 @@ public void setUp() {
8580 op2 .setValue (v [1 ]);
8681 }
8782
88- @ Test
89- public void testBind () {
83+ @ ParameterizedTest
84+ @ MethodSource ("parameters" )
85+ public void testBind (Factory <T > factory ) {
86+ setUp (factory );
9087 Bindings .bindBidirectional (op1 , op2 );
9188 Bindings .bindBidirectional (op1 , op2 );
9289 System .gc (); // making sure we did not not overdo weak references
@@ -102,8 +99,10 @@ public void testBind() {
10299 assertEquals (v [3 ], op2 .getValue ());
103100 }
104101
105- @ Test
106- public void testUnbind () {
102+ @ ParameterizedTest
103+ @ MethodSource ("parameters" )
104+ public void testUnbind (Factory <T > factory ) {
105+ setUp (factory );
107106 // unbind non-existing binding => no-op
108107 Bindings .unbindBidirectional (op1 , op2 );
109108
@@ -127,8 +126,10 @@ public void testUnbind() {
127126 assertEquals (v [3 ], op2 .getValue ());
128127 }
129128
130- @ Test
131- public void testChaining () {
129+ @ ParameterizedTest
130+ @ MethodSource ("parameters" )
131+ public void testChaining (Factory <T > factory ) {
132+ setUp (factory );
132133 op3 .setValue (v [2 ]);
133134 Bindings .bindBidirectional (op1 , op2 );
134135 Bindings .bindBidirectional (op2 , op3 );
@@ -179,8 +180,10 @@ private int getListenerCount(ObservableValue<T> v) {
179180 return ExpressionHelperUtility .getInvalidationListeners (v ).size ();
180181 }
181182
182- @ Test
183- public void testWeakReferencing () {
183+ @ ParameterizedTest
184+ @ MethodSource ("parameters" )
185+ public void testWeakReferencing (Factory <T > factory ) {
186+ setUp (factory );
184187 Bindings .bindBidirectional (op1 , op2 );
185188
186189 assertEquals (1 , getListenerCount (op1 ));
@@ -201,16 +204,20 @@ public void testWeakReferencing() {
201204 assertEquals (0 , getListenerCount (op2 ));
202205 }
203206
204- @ Test
205- public void testHashCode () {
207+ @ ParameterizedTest
208+ @ MethodSource ("parameters" )
209+ public void testHashCode (Factory <T > factory ) {
210+ setUp (factory );
206211 final int hc1 = BidirectionalBinding .bind (op1 , op2 ).hashCode ();
207212 final int hc2 = BidirectionalBinding .bind (op2 , op1 ).hashCode ();
208213 assertEquals (hc1 , hc2 );
209214 }
210215
211216 @ SuppressWarnings ("unlikely-arg-type" )
212- @ Test
213- public void testEquals () {
217+ @ ParameterizedTest
218+ @ MethodSource ("parameters" )
219+ public void testEquals (Factory <T > factory ) {
220+ setUp (factory );
214221 final BidirectionalBinding golden = BidirectionalBinding .bind (op1 , op2 );
215222
216223 assertTrue (golden .equals (golden ));
@@ -224,8 +231,10 @@ public void testEquals() {
224231 assertFalse (golden .equals (BidirectionalBinding .bind (op2 , op3 )));
225232 }
226233
227- @ Test
228- public void testEqualsWithGCedProperty () {
234+ @ ParameterizedTest
235+ @ MethodSource ("parameters" )
236+ public void testEqualsWithGCedProperty (Factory <T > factory ) {
237+ setUp (factory );
229238 final BidirectionalBinding binding1 = BidirectionalBinding .bind (op1 , op2 );
230239 final BidirectionalBinding binding2 = BidirectionalBinding .bind (op1 , op2 );
231240 final BidirectionalBinding binding3 = BidirectionalBinding .bind (op2 , op1 );
@@ -242,38 +251,52 @@ public void testEqualsWithGCedProperty() {
242251 assertFalse (binding3 .equals (binding4 ));
243252 }
244253
245- @ Test (expected =NullPointerException .class )
246- public void testBind_Null_X () {
247- Bindings .bindBidirectional (null , op2 );
254+ @ ParameterizedTest
255+ @ MethodSource ("parameters" )
256+ public void testBind_Null_X (Factory <T > factory ) {
257+ setUp (factory );
258+ assertThrows (NullPointerException .class , () -> Bindings .bindBidirectional (null , op2 ));
248259 }
249260
250- @ Test (expected =NullPointerException .class )
251- public void testBind_X_Null () {
252- Bindings .bindBidirectional (op1 , null );
261+ @ ParameterizedTest
262+ @ MethodSource ("parameters" )
263+ public void testBind_X_Null (Factory <T > factory ) {
264+ setUp (factory );
265+ assertThrows (NullPointerException .class , () -> Bindings .bindBidirectional (op1 , null ));
253266 }
254267
255- @ Test (expected =IllegalArgumentException .class )
256- public void testBind_X_Self () {
257- Bindings .bindBidirectional (op1 , op1 );
268+ @ ParameterizedTest
269+ @ MethodSource ("parameters" )
270+ public void testBind_X_Self (Factory <T > factory ) {
271+ setUp (factory );
272+ assertThrows (IllegalArgumentException .class , () -> Bindings .bindBidirectional (op1 , op1 ));
258273 }
259274
260- @ Test (expected =NullPointerException .class )
261- public void testUnbind_Null_X () {
262- Bindings .unbindBidirectional (null , op2 );
275+ @ ParameterizedTest
276+ @ MethodSource ("parameters" )
277+ public void testUnbind_Null_X (Factory <T > factory ) {
278+ setUp (factory );
279+ assertThrows (NullPointerException .class , () -> Bindings .unbindBidirectional (null , op2 ));
263280 }
264281
265- @ Test (expected =NullPointerException .class )
266- public void testUnbind_X_Null () {
267- Bindings .unbindBidirectional (op1 , null );
282+ @ ParameterizedTest
283+ @ MethodSource ("parameters" )
284+ public void testUnbind_X_Null (Factory <T > factory ) {
285+ setUp (factory );
286+ assertThrows (NullPointerException .class , () -> Bindings .unbindBidirectional (op1 , null ));
268287 }
269288
270- @ Test (expected =IllegalArgumentException .class )
271- public void testUnbind_X_Self () {
272- Bindings .unbindBidirectional (op1 , op1 );
289+ @ ParameterizedTest
290+ @ MethodSource ("parameters" )
291+ public void testUnbind_X_Self (Factory <T > factory ) {
292+ setUp (factory );
293+ assertThrows (IllegalArgumentException .class , () -> Bindings .unbindBidirectional (op1 , op1 ));
273294 }
274295
275- @ Test
276- public void testBrokenBind () {
296+ @ ParameterizedTest
297+ @ MethodSource ("parameters" )
298+ public void testBrokenBind (Factory <T > factory ) {
299+ setUp (factory );
277300 Bindings .bindBidirectional (op1 , op2 );
278301 op1 .bind (op3 );
279302 assertEquals (op3 .getValue (), op1 .getValue ());
@@ -284,8 +307,10 @@ public void testBrokenBind() {
284307 assertEquals (op2 .getValue (), op1 .getValue ());
285308 }
286309
287- @ Test
288- public void testDoubleBrokenBind () {
310+ @ ParameterizedTest
311+ @ MethodSource ("parameters" )
312+ public void testDoubleBrokenBind (Factory <T > factory ) {
313+ setUp (factory );
289314 Bindings .bindBidirectional (op1 , op2 );
290315 op1 .bind (op3 );
291316 op4 .setValue (v [0 ]);
@@ -302,16 +327,17 @@ public void testDoubleBrokenBind() {
302327 assertEquals (v [1 ], op2 .getValue ());
303328 }
304329
305- @ Test
306- public void testSetValueWithoutIntermediateValidation () {
330+ @ ParameterizedTest
331+ @ MethodSource ("parameters" )
332+ public void testSetValueWithoutIntermediateValidation (Factory <T > factory ) {
333+ setUp (factory );
307334 BidirectionalBinding .bind (op1 , op2 );
308335 op1 .setValue (v [0 ]);
309336 op2 .setValue (v [1 ]);
310337 assertEquals (v [1 ], op1 .getValue ());
311338 assertEquals (v [1 ], op2 .getValue ());
312339 }
313340
314- @ Parameterized .Parameters
315341 public static Collection <Object []> parameters () {
316342 final Boolean [] booleanData = new Boolean [] {true , false , true , false };
317343 final Double [] doubleData = new Double [] {2348.2345 , -92.214 , -214.0214 , -908.214 };
0 commit comments