Skip to content

Commit 61a248d

Browse files
author
Jay Bhaskar
committed
8340464: [TestBug] Convert parametrized base tests to JUnit 5
Reviewed-by: angorya, arapte
1 parent 1b26b66 commit 61a248d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3766
-2919
lines changed

modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@
2828
import com.sun.javafx.binding.BidirectionalBinding;
2929
import javafx.beans.binding.Bindings;
3030
import 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

3636
import java.util.Arrays;
3737
import java.util.Collection;
3838
import javafx.beans.value.ObservableValue;
3939

40-
import static org.junit.Assert.*;
40+
import static org.junit.jupiter.api.Assertions.*;
4141

42-
@RunWith(Parameterized.class)
4342
public 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};

modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingWithConversionTest.java

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
import javafx.beans.binding.Bindings;
3131
import javafx.beans.property.*;
3232
import javafx.util.StringConverter;
33-
import org.junit.Before;
34-
import org.junit.Test;
35-
import org.junit.runner.RunWith;
36-
import org.junit.runners.Parameterized;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.Arguments;
36+
import org.junit.jupiter.params.provider.MethodSource;
3737

3838
import java.text.DateFormat;
3939
import java.text.ParseException;
4040
import java.util.Arrays;
4141
import java.util.Collection;
4242
import java.util.Date;
4343
import java.util.Locale;
44+
import java.util.stream.Stream;
4445

45-
import static org.junit.Assert.*;
46+
import static org.junit.jupiter.api.Assertions.*;
4647

47-
@RunWith(Parameterized.class)
4848
public class BidirectionalBindingWithConversionTest<S, T> {
4949

5050
public static interface Functions<U, V> {
@@ -57,29 +57,28 @@ public static interface Functions<U, V> {
5757
void check1(V obj0, V obj1);
5858
}
5959

60-
private final Functions<S, T> func;
61-
private final S[] v0;
62-
private final T[] v1;
60+
private Functions<S, T> func;
61+
private S[] v0;
62+
private T[] v1;
6363

6464
private PropertyMock<S> op0;
6565
private PropertyMock<T> op1;
6666

67-
public BidirectionalBindingWithConversionTest(Functions<S, T> func, S[] v0, T[] v1) {
67+
private void setUP(Functions<S, T> func, S[] v0, T[] v1) {
6868
this.op0 = func.create0();
6969
this.op1 = func.create1();
7070
this.func = func;
7171
this.v0 = v0;
7272
this.v1 = v1;
7373
}
7474

75-
@Before
76-
public void setUp() {
75+
76+
@ParameterizedTest
77+
@MethodSource("parameters")
78+
public void testBind(Functions<S, T> func, S[] v0, T[] v1) {
79+
setUP(func, v0, v1);
7780
op0.setValue(v0[0]);
7881
op1.setValue(v1[1]);
79-
}
80-
81-
@Test
82-
public void testBind() {
8382
func.bind(op0, op1);
8483
System.gc(); // making sure we did not not overdo weak references
8584
func.check0(v0[1], op0.getValue());
@@ -94,8 +93,12 @@ public void testBind() {
9493
func.check1(v1[3], op1.getValue());
9594
}
9695

97-
@Test
98-
public void testUnbind() {
96+
@ParameterizedTest
97+
@MethodSource("parameters")
98+
public void testUnbind(Functions<S, T> func, S[] v0, T[] v1) {
99+
setUP(func, v0, v1);
100+
op0.setValue(v0[0]);
101+
op1.setValue(v1[1]);
99102
// unbind non-existing binding => no-op
100103
func.unbind(op0, op1);
101104

@@ -119,8 +122,12 @@ public void testUnbind() {
119122
func.check1(v1[3], op1.getValue());
120123
}
121124

122-
@Test
123-
public void testWeakReferencing() {
125+
@ParameterizedTest
126+
@MethodSource("parameters")
127+
public void testWeakReferencing(Functions<S, T> func, S[] v0, T[] v1) {
128+
setUP(func, v0, v1);
129+
op0.setValue(v0[0]);
130+
op1.setValue(v1[1]);
124131
func.bind(op0, op1);
125132
assertEquals(1, op0.getListenerCount());
126133
assertEquals(1, op1.getListenerCount());
@@ -141,32 +148,47 @@ public void testWeakReferencing() {
141148
assertEquals(0, op0.getListenerCount());
142149
}
143150

144-
@Test(expected=NullPointerException.class)
145-
public void testBind_Null_X() {
146-
func.bind(null, op1);
151+
@ParameterizedTest
152+
@MethodSource("parameters")
153+
public void testBind_Null_X(Functions<S, T> func, S[] v0, T[] v1) {
154+
setUP(func, v0, v1);
155+
op0.setValue(v0[0]);
156+
op1.setValue(v1[1]);
157+
assertThrows(NullPointerException.class, () -> func.bind(null, op1));
147158
}
148159

149-
@Test(expected=NullPointerException.class)
150-
public void testBind_X_Null() {
151-
func.bind(op0, null);
160+
public void testBind_X_Null(Functions<S, T> func, S[] v0, T[] v1) {
161+
setUP(func, v0, v1);
162+
op0.setValue(v0[0]);
163+
op1.setValue(v1[1]);
164+
assertThrows(NullPointerException.class, () -> func.bind(op0, null));
152165
}
153166

154-
@Test(expected=NullPointerException.class)
155-
public void testUnbind_Null_X() {
156-
func.unbind(null, op1);
167+
public void testUnbind_Null_X(Functions<S, T> func, S[] v0, T[] v1) {
168+
setUP(func, v0, v1);
169+
op0.setValue(v0[0]);
170+
op1.setValue(v1[1]);
171+
assertThrows(NullPointerException.class, () -> func.unbind(null, op1));
157172
}
158173

159-
@Test(expected=NullPointerException.class)
160-
public void testUnbind_X_Null() {
161-
func.unbind(op0, null);
174+
@ParameterizedTest
175+
@MethodSource("parameters")
176+
public void testUnbind_X_Null(Functions<S, T> func, S[] v0, T[] v1) {
177+
setUP(func, v0, v1);
178+
op0.setValue(v0[0]);
179+
op1.setValue(v1[1]);
180+
assertThrows(NullPointerException.class, () -> func.unbind(op0, null));
162181
}
163182

164-
@Test(expected=IllegalArgumentException.class)
165-
public void testUnbind_X_Self() {
166-
func.unbind(op0, op0);
183+
@ParameterizedTest
184+
@MethodSource("parameters")
185+
public void testUnbind_X_Self(Functions<S, T> func, S[] v0, T[] v1) {
186+
setUP(func, v0, v1);
187+
op0.setValue(v0[0]);
188+
op1.setValue(v1[1]);
189+
assertThrows(IllegalArgumentException.class, () -> func.unbind(op0, op0));
167190
}
168191

169-
@Parameterized.Parameters
170192
public static Collection<Object[]> parameters() {
171193
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
172194
final Date[] dates = new Date[] {new Date(), new Date(0), new Date(Integer.MAX_VALUE), new Date(Long.MAX_VALUE)};

0 commit comments

Comments
 (0)