Skip to content

Commit 34c11eb

Browse files
committed
Migrate ConformanceTestSuite and dependencies to JUnit 5
- Migrate org.eclipse.jface.tests.databinding.conformance tests to JUnit 5. - Update ConformanceTestSuite to use @testfactory. - Update MANIFEST.MF to import junit.jupiter.api.function.
1 parent d8eb08e commit 34c11eb

File tree

13 files changed

+321
-277
lines changed

13 files changed

+321
-277
lines changed

tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableCollectionContractTest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.eclipse.jface.databinding.conformance;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.util.Arrays;
2424
import java.util.Collections;
@@ -30,8 +30,8 @@
3030
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
3131
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
3232
import org.eclipse.jface.databinding.conformance.util.RealmTester;
33-
import org.junit.Before;
34-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3535

3636
/**
3737
* Mutability tests for IObservableCollection.
@@ -58,7 +58,7 @@ public MutableObservableCollectionContractTest(
5858
}
5959

6060
@Override
61-
@Before
61+
@BeforeEach
6262
public void setUp() throws Exception {
6363
super.setUp();
6464
collection = (IObservableCollection) super.getObservable();
@@ -160,9 +160,8 @@ public void testRemoveAll_ChangeEventFiredAfterElementsAreRemoved()
160160
public void testRemoveAll_NoChange() throws Exception {
161161
ChangeEventTracker tracker = ChangeEventTracker.observe(collection);
162162
collection.removeAll(Collections.EMPTY_LIST);
163-
assertEquals(
164-
"List.removeAll on an empty list should not fire a list change event",
165-
0, tracker.count);
163+
assertEquals(0, tracker.count,
164+
"List.removeAll on an empty list should not fire a list change event");
166165
}
167166

168167
@Test
@@ -205,20 +204,18 @@ public void testRetainAll_ChangeEventFiredAfterElementsAreRetained()
205204
listener2.contains = true;
206205

207206
collection.retainAll(Arrays.asList(new Object[] { element1 }));
208-
assertTrue(
209-
formatFail("When Collection.retainAll(...) fires the change event the element should have been retained in the Collection."),
210-
listener1.contains);
211-
assertFalse(
212-
formatFail("When Collection.retainAll(...) fires the change event the element should have been removed from the Collection."),
213-
listener2.contains);
207+
assertTrue(listener1.contains,
208+
formatFail("When Collection.retainAll(...) fires the change event the element should have been retained in the Collection."));
209+
assertFalse(listener2.contains,
210+
formatFail("When Collection.retainAll(...) fires the change event the element should have been removed from the Collection."));
214211
}
215212

216213
@Test
217214
public void testRetainAll_NoChangeFiresNoChangeEvent() throws Exception {
218215
ChangeEventTracker tracker = ChangeEventTracker.observe(collection);
219216
collection.retainAll(Collections.EMPTY_LIST);
220-
assertEquals("List.retainAll should not have fired a change event:", 0,
221-
tracker.count);
217+
assertEquals(0, tracker.count,
218+
"List.retainAll should not have fired a change event:");
222219
}
223220

224221
@Test
@@ -253,12 +250,11 @@ public void testClear_ChangeEventFiredAfterElementIsRemoved()
253250
ChangeEventTracker listener = ChangeEventTracker.observe(collection);
254251
runnable.run();
255252

256-
assertEquals(formatFail(methodName + " should fire one ChangeEvent."),
257-
1, listener.count);
258-
assertEquals(
253+
assertEquals(1, listener.count,
254+
formatFail(methodName + " should fire one ChangeEvent."));
255+
assertEquals(collection, listener.event.getObservable(),
259256
formatFail(methodName
260-
+ "'s change event observable should be the created Collection."),
261-
collection, listener.event.getObservable());
257+
+ "'s change event observable should be the created Collection."));
262258
}
263259

264260
/**
@@ -277,11 +273,11 @@ public void testClear_ChangeEventFiredAfterElementIsRemoved()
277273
elementNotContained).init();
278274
listener.contains = true;
279275
collection.remove(elementNotContained);
280-
assertFalse(
276+
assertFalse(listener.contains,
281277
formatFail(new StringBuilder("When ")
282278
.append(methodName)
283279
.append(" fires a change event the element should have been removed from the Collection.")
284-
.toString()), listener.contains);
280+
.toString()));
285281
}
286282

287283
/**
@@ -299,11 +295,11 @@ public void testClear_ChangeEventFiredAfterElementIsRemoved()
299295
assertFalse(collection.contains(elementContained));
300296
runnable.run();
301297

302-
assertTrue(
298+
assertTrue(listener.contains,
303299
formatFail(new StringBuilder("When ")
304300
.append(methodName)
305301
.append(" fires a change event the element should have been added to the Collection.")
306-
.toString()), listener.contains);
302+
.toString()));
307303
}
308304

309305
/* package */static class ContainsListener implements IChangeListener {

tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.eclipse.jface.databinding.conformance;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertSame;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertSame;
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;
@@ -30,9 +30,8 @@
3030
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
3131
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
3232
import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker;
33-
import org.junit.Assert;
34-
import org.junit.Before;
35-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3635

3736
/**
3837
* Mutability tests for IObservableList.
@@ -60,7 +59,7 @@ public MutableObservableListContractTest(
6059
}
6160

6261
@Override
63-
@Before
62+
@BeforeEach
6463
public void setUp() throws Exception {
6564
super.setUp();
6665
list = (IObservableList) getObservable();
@@ -186,7 +185,7 @@ public void testSet_ListChangeEvent() throws Exception {
186185
list.add(element0);
187186
final Object element1 = delegate.createElement(list);
188187

189-
assertListChangeEventFired(() -> assertSame(element0, list.set(0, element1)), "List.set(int, Object)", list,
188+
assertListChangeEventFired(() -> assertSame(element0, list.set(0, element1), "List.set(int, Object)"), "List.set(int, Object)", list,
190189
Arrays.asList(new Object[] { element1 }));
191190
}
192191

@@ -196,7 +195,7 @@ public void testSet_ChangeEventFiredAfterElementIsSet() throws Exception {
196195
list.add(element1);
197196
final Object element2 = delegate.createElement(list);
198197

199-
assertContainsDuringChangeEvent(() -> assertSame(element1, list.set(0, element2)), "List.set(int, Object)",
198+
assertContainsDuringChangeEvent(() -> assertSame(element1, list.set(0, element2), "List.set(int, Object)"), "List.set(int, Object)",
200199
list, element2);
201200
}
202201

@@ -229,13 +228,11 @@ public void testMove_NoChangeEventAtSameIndex() throws Exception {
229228

230229
final Object movedElement = list.move(0, 0);
231230

232-
assertEquals(
233-
formatFail("IObservableList.move(int,int) should return the moved element"),
234-
element, movedElement);
235-
assertEquals(
231+
assertEquals(element, movedElement,
232+
formatFail("IObservableList.move(int,int) should return the moved element"));
233+
assertEquals(0, tracker.count,
236234
formatFail("IObservableLIst.move(int,int) should not fire a change event"
237-
+ "when the old and new indices are the same"), 0,
238-
tracker.count);
235+
+ "when the old and new indices are the same"));
239236
}
240237

241238
@Test
@@ -245,7 +242,7 @@ public void testMove_ListChangeEvent() throws Exception {
245242
final Object element1 = delegate.createElement(list);
246243
list.add(element1);
247244

248-
assertListChangeEventFired(() -> assertSame(element0, list.move(0, 1)), "IObservableList.move(int, int)", list,
245+
assertListChangeEventFired(() -> assertSame(element0, list.move(0, 1), "IObservableList.move(int, int)"), "IObservableList.move(int, int)", list,
249246
Arrays.asList(new Object[] { element1, element0 }));
250247
}
251248

@@ -398,9 +395,9 @@ public void testClear_ListDiffEntry() throws Exception {
398395
public void testClear_ClearsList() {
399396
Object element = delegate.createElement(list);
400397
list.add(element);
401-
Assert.assertEquals(Collections.singletonList(element), list);
398+
assertEquals(Collections.singletonList(element), list);
402399
list.clear();
403-
Assert.assertEquals(Collections.EMPTY_LIST, list);
400+
assertEquals(Collections.EMPTY_LIST, list);
404401
}
405402

406403
private void assertListChangeEventFired(Runnable runnable,
@@ -416,32 +413,30 @@ private void assertListChangeEventFired(Runnable runnable,
416413

417414
runnable.run();
418415

419-
assertEquals(formatFail(methodName
420-
+ " should fire one ListChangeEvent."), 1, listListener.count);
421-
assertEquals(formatFail(methodName
422-
+ "'s change event observable should be the created List."),
423-
list, listListener.event.getObservable());
424-
425-
assertEquals(
426-
formatFail("Two notifications should have been received."), 2,
427-
queue.size());
428-
assertEquals("ChangeEvent of " + methodName
429-
+ " should have fired before the ListChangeEvent.",
430-
changeListener, queue.get(0));
431-
assertEquals("ListChangeEvent of " + methodName
432-
+ " should have fired after the ChangeEvent.", listListener,
433-
queue.get(1));
434-
435-
assertEquals(formatFail(methodName
436-
+ " did not leave observable list with the expected contents"),
437-
newList, list);
416+
assertEquals(1, listListener.count, formatFail(methodName
417+
+ " should fire one ListChangeEvent."));
418+
assertEquals(list, listListener.event.getObservable(),
419+
formatFail(methodName
420+
+ "'s change event observable should be the created List."));
421+
422+
assertEquals(2, queue.size(),
423+
formatFail("Two notifications should have been received."));
424+
assertEquals(changeListener, queue.get(0),
425+
"ChangeEvent of " + methodName
426+
+ " should have fired before the ListChangeEvent.");
427+
assertEquals(listListener, queue.get(1),
428+
"ListChangeEvent of " + methodName
429+
+ " should have fired after the ChangeEvent.");
430+
431+
assertEquals(newList, list,
432+
formatFail(methodName
433+
+ " did not leave observable list with the expected contents"));
438434

439435
ListDiff diff = listListener.event.diff;
440436
diff.applyTo(oldList);
441-
assertEquals(
437+
assertEquals(newList, oldList,
442438
formatFail(methodName
443-
+ " fired a diff which does not represent the expected list change"),
444-
newList, oldList);
439+
+ " fired a diff which does not represent the expected list change"));
445440

446441
}
447442
}

tests/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableSetContractTest.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.eclipse.jface.databinding.conformance;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;
@@ -30,8 +30,8 @@
3030
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
3131
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
3232
import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker;
33-
import org.junit.Before;
34-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3535

3636
public class MutableObservableSetContractTest extends
3737
MutableObservableCollectionContractTest {
@@ -46,7 +46,7 @@ public MutableObservableSetContractTest(
4646
}
4747

4848
@Override
49-
@Before
49+
@BeforeEach
5050
public void setUp() throws Exception {
5151
super.setUp();
5252
set = (IObservableSet) getObservable();
@@ -206,22 +206,20 @@ private void assertSetChangeEventFired(Runnable runnable,
206206

207207
runnable.run();
208208

209-
assertEquals(
210-
formatFail(methodName + " should fire one SetChangeEvent."), 1,
211-
setListener.count);
212-
assertEquals(formatFail(methodName
213-
+ "'s change event observable should be the created Set."),
214-
set, setListener.event.getObservable());
215-
216-
assertEquals(
217-
formatFail("Two notifications should have been received."), 2,
218-
queue.size());
219-
assertEquals(formatFail("ChangeEvent of " + methodName
220-
+ " should have fired before the SetChangeEvent."),
221-
changeListener, queue.get(0));
222-
assertEquals(formatFail("SetChangeEvent of " + methodName
223-
+ " should have fired after the ChangeEvent."), setListener,
224-
queue.get(1));
209+
assertEquals(1, setListener.count,
210+
formatFail(methodName + " should fire one SetChangeEvent."));
211+
assertEquals(set, setListener.event.getObservable(),
212+
formatFail(methodName
213+
+ "'s change event observable should be the created Set."));
214+
215+
assertEquals(2, queue.size(),
216+
formatFail("Two notifications should have been received."));
217+
assertEquals(changeListener, queue.get(0),
218+
formatFail("ChangeEvent of " + methodName
219+
+ " should have fired before the SetChangeEvent."));
220+
assertEquals(setListener, queue.get(1),
221+
formatFail("SetChangeEvent of " + methodName
222+
+ " should have fired after the ChangeEvent."));
225223
}
226224

227225
/**
@@ -235,12 +233,12 @@ private void assertAddDiffEntry(Runnable runnable, String methodName,
235233
runnable.run();
236234

237235
Set entries = listener.event.diff.getAdditions();
238-
assertEquals(formatFail(methodName
239-
+ " should result in one diff entry."), 1, entries.size());
236+
assertEquals(1, entries.size(), formatFail(methodName
237+
+ " should result in one diff entry."));
240238

241-
assertTrue(formatFail(methodName
242-
+ " should result in a diff entry that is an addition."),
243-
entries.contains(element));
239+
assertTrue(entries.contains(element),
240+
formatFail(methodName
241+
+ " should result in a diff entry that is an addition."));
244242
}
245243

246244
/**
@@ -254,11 +252,11 @@ private void assertRemoveDiffEntry(Runnable runnable, String methodName,
254252
runnable.run();
255253

256254
Set entries = listener.event.diff.getRemovals();
257-
assertEquals(formatFail(methodName
258-
+ " should result in one diff entry."), 1, entries.size());
255+
assertEquals(1, entries.size(), formatFail(methodName
256+
+ " should result in one diff entry."));
259257

260-
assertTrue(formatFail(methodName
261-
+ " should result in a diff entry that is a removal."),
262-
entries.contains(element));
258+
assertTrue(entries.contains(element),
259+
formatFail(methodName
260+
+ " should result in a diff entry that is a removal."));
263261
}
264262
}

0 commit comments

Comments
 (0)