Skip to content

Commit 236a370

Browse files
committed
Migrate SWT suites to JUnit 5
First towards being able to move unit tests to JUnit 5.
1 parent 9440140 commit 236a370

File tree

9 files changed

+94
-96
lines changed

9 files changed

+94
-96
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllBrowserTests.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@
1414
package org.eclipse.swt.tests.junit;
1515

1616

17-
import org.eclipse.test.TracingSuite;
18-
import org.eclipse.test.TracingSuite.TracingOptions;
19-
import org.junit.runner.JUnitCore;
20-
import org.junit.runner.RunWith;
21-
import org.junit.runners.Suite;
17+
import org.junit.platform.suite.api.SelectClasses;
18+
import org.junit.platform.suite.api.Suite;
2219

23-
@RunWith(TracingSuite.class)
24-
@TracingOptions(stackDumpTimeoutSeconds = 60)
25-
@Suite.SuiteClasses({
20+
@Suite
21+
@SelectClasses({
2622
Test_org_eclipse_swt_browser_Browser.class,
2723
})
2824
public class AllBrowserTests {
29-
30-
public static void main(String[] args) {
31-
JUnitCore.main(AllBrowserTests.class.getName());
32-
}
3325
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllGraphicsTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,15 +13,14 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import org.junit.runner.JUnitCore;
17-
import org.junit.runner.RunWith;
18-
import org.junit.runners.Suite;
16+
import org.junit.platform.suite.api.SelectClasses;
17+
import org.junit.platform.suite.api.Suite;
1918

2019
/**
2120
* Suite for testing all of the graphics test cases.
2221
*/
23-
@RunWith(Suite.class)
24-
@Suite.SuiteClasses({ Test_org_eclipse_swt_graphics_Color.class,
22+
@Suite
23+
@SelectClasses({ Test_org_eclipse_swt_graphics_Color.class,
2524
Test_org_eclipse_swt_graphics_Cursor.class,
2625
Test_org_eclipse_swt_graphics_DeviceData.class,
2726
Test_org_eclipse_swt_graphics_Font.class,
@@ -42,7 +41,4 @@
4241
Test_org_eclipse_swt_graphics_ImageLoaderEvent.class,
4342
Test_org_eclipse_swt_graphics_Transform.class })
4443
public class AllGraphicsTests {
45-
public static void main(String[] args) {
46-
JUnitCore.main(AllGraphicsTests.class.getName());
47-
}
4844
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllNonBrowserTests.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,17 +18,16 @@
1818
import java.util.List;
1919

2020
import org.eclipse.swt.graphics.Resource;
21-
import org.junit.AfterClass;
22-
import org.junit.BeforeClass;
23-
import org.junit.runner.JUnitCore;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.Suite;
21+
import org.junit.jupiter.api.AfterAll;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.platform.suite.api.SelectClasses;
24+
import org.junit.platform.suite.api.Suite;
2625

2726
/**
2827
* Suite for running most SWT test cases (all except for browser tests).
2928
*/
30-
@RunWith(Suite.class)
31-
@Suite.SuiteClasses({ Test_org_eclipse_swt_SWT.class, Test_org_eclipse_swt_SWTException.class,
29+
@Suite
30+
@SelectClasses({ Test_org_eclipse_swt_SWT.class, Test_org_eclipse_swt_SWTException.class,
3231
Test_org_eclipse_swt_SWTError.class, Test_org_eclipse_swt_widgets_Display.class, AllGraphicsTests.class,
3332
AllWidgetTests.class, Test_org_eclipse_swt_layout_GridData.class,
3433
Test_org_eclipse_swt_events_ControlEvent.class, Test_org_eclipse_swt_events_ModifyEvent.class,
@@ -50,7 +49,7 @@
5049
public class AllNonBrowserTests {
5150
private static List<Error> leakedResources;
5251

53-
@BeforeClass
52+
@BeforeAll
5453
public static void beforeClass() {
5554
// Set up ResourceTracked to detect any leaks
5655
leakedResources = new ArrayList<> ();
@@ -67,7 +66,7 @@ public static void beforeClass() {
6766
* through a test and not through @AfterClass, but this is a
6867
* suite class and not a test class, so it can't have tests.
6968
*/
70-
@AfterClass
69+
@AfterAll
7170
public static void afterClass() {
7271
// Run GC in order do detect any outstanding leaks
7372
System.gc ();
@@ -93,10 +92,6 @@ public static void afterClass() {
9392
}
9493
}
9594

96-
public static void main(String[] args) {
97-
JUnitCore.main(AllNonBrowserTests.class.getName());
98-
}
99-
10095
/*
10196
* The logical order to run the tests in is: - SWT, SWTError, SWTException -
10297
* Display - graphics classes - items and Caret, etc - widgets - dialogs -
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,21 +14,17 @@
1414
package org.eclipse.swt.tests.junit;
1515

1616

17-
import org.junit.runner.JUnitCore;
18-
import org.junit.runner.RunWith;
19-
import org.junit.runners.Suite;
17+
import org.junit.platform.suite.api.SelectClasses;
18+
import org.junit.platform.suite.api.Suite;
2019

2120
/**
2221
* Suite for running all SWT test cases.
2322
*/
24-
@RunWith(Suite.class)
25-
@Suite.SuiteClasses({
23+
@Suite
24+
@SelectClasses({
2625
AllNonBrowserTests.class,
2726
AllBrowserTests.class
2827
})
2928
public class AllTests {
3029

31-
public static void main(String[] args) {
32-
JUnitCore.main(AllTests.class.getName());
33-
}
3430
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,15 +14,14 @@
1414
*******************************************************************************/
1515
package org.eclipse.swt.tests.junit;
1616

17-
import org.junit.runner.JUnitCore;
18-
import org.junit.runner.RunWith;
19-
import org.junit.runners.Suite;
17+
import org.junit.platform.suite.api.SelectClasses;
18+
import org.junit.platform.suite.api.Suite;
2019

2120
/**
2221
* Suite for testing all of the widget test cases.
2322
*/
24-
@RunWith(Suite.class)
25-
@Suite.SuiteClasses({ Test_org_eclipse_swt_widgets_Shell.class,
23+
@Suite
24+
@SelectClasses({ Test_org_eclipse_swt_widgets_Shell.class,
2625
Test_org_eclipse_swt_widgets_ExpandItem.class, Test_org_eclipse_swt_widgets_MenuItem.class,
2726
Test_org_eclipse_swt_widgets_ToolItem.class, Test_org_eclipse_swt_widgets_TabItem.class,
2827
Test_org_eclipse_swt_widgets_TableItem.class, Test_org_eclipse_swt_widgets_TableColumn.class,
@@ -53,7 +52,4 @@
5352
Test_org_eclipse_swt_widgets_ScrolledComposite.class,
5453
Test_org_eclipse_swt_custom_BusyIndicator.class})
5554
public class AllWidgetTests {
56-
public static void main(String[] args) {
57-
JUnitCore.main(AllWidgetTests.class.getName());
58-
}
5955
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
package org.eclipse.swt.tests.junit;
1616

1717
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertSame;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
22+
import static org.junit.jupiter.api.Assertions.assertSame;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import java.io.IOException;
2727
import java.util.concurrent.CompletableFuture;
@@ -144,16 +144,16 @@ else if (e.type == SWT.Dispose)
144144
} finally {
145145
display.close();
146146
}
147-
assertFalse(":a:", callbackReceived[CLOSE_CALLBACK]);
148-
assertTrue(":b:", callbackReceived[DISPOSE_CALLBACK]);
147+
assertFalse(callbackReceived[CLOSE_CALLBACK]);
148+
assertTrue(callbackReceived[DISPOSE_CALLBACK]);
149149

150150
display = new Display();
151151
try {
152152
display.addListener(SWT.Close, listener);
153153
} finally {
154154
display.close();
155155
}
156-
assertTrue(":c:", callbackReceived[CLOSE_CALLBACK]);
156+
assertTrue(callbackReceived[CLOSE_CALLBACK]);
157157
}
158158

159159
@Test
@@ -250,10 +250,10 @@ public void test_disposeExecLjava_lang_Runnable() {
250250
Display testDisplay = new Display();
251251
disposeExecRan = false;
252252
testDisplay.disposeExec(() -> disposeExecRan = true);
253-
assertEquals("Display should not be disposed", false, testDisplay.isDisposed());
253+
assertFalse(testDisplay.isDisposed(), "Display should not be disposed");
254254
testDisplay.dispose();
255-
assertTrue("Display should be disposed", testDisplay.isDisposed());
256-
assertTrue("DisposeExec Runnable did not run", disposeExecRan);
255+
assertTrue(testDisplay.isDisposed(), "Display should be disposed");
256+
assertTrue(disposeExecRan, "DisposeExec Runnable did not run");
257257
}
258258

259259
@Test
@@ -372,8 +372,7 @@ public void test_getDismissalAlignment() {
372372
Display display = new Display();
373373
try {
374374
int alignment = display.getDismissalAlignment();
375-
assertTrue("getDismissalAlignment should return SWT.LEFT or SWT.RIGHT",
376-
alignment == SWT.LEFT || alignment == SWT.RIGHT);
375+
assertTrue(alignment == SWT.LEFT || alignment == SWT.RIGHT, "getDismissalAlignment should return SWT.LEFT or SWT.RIGHT");
377376
} finally {
378377
display.dispose();
379378
}
@@ -416,9 +415,9 @@ public void test_getMonitors() {
416415
Display display = new Display();
417416
Monitor[] monitors = display.getMonitors();
418417
assertNotNull(monitors);
419-
assertTrue("at least one monitor should be returned", monitors.length >= 1);
418+
assertTrue(monitors.length >= 1, "at least one monitor should be returned");
420419
for (int i = 0; i < monitors.length; i++)
421-
assertNotNull("monitor at index "+i+" should not be null", monitors[i]);
420+
assertNotNull(monitors[i], "monitor at index "+i+" should not be null");
422421
display.dispose();
423422
}
424423

@@ -1103,7 +1102,7 @@ public void test_postLorg_eclipse_swt_widgets_Event() {
11031102
event = new Event();
11041103
event.type = SWT.KeyDown;
11051104
event.keyCode = -1; // bogus key code; default 0 character
1106-
assertTrue("Display#post failed, probably because screen is not rendered (bug 407862)", display.post(event)); //$NON-NLS-1$
1105+
assertTrue(display.post(event), "Display#post failed, probably because screen is not rendered (bug 407862)"); //$NON-NLS-1$
11071106
// don't test KeyDown/KeyUp with a character to avoid sending to
11081107
// random window if test shell looses focus
11091108

@@ -1469,7 +1468,7 @@ public void test_syncCall_RuntimeException() {
14691468
final Display display = new Display();
14701469
try {
14711470
int depth=display.syncCall(() -> {throw new IllegalArgumentException("42");});
1472-
assertFalse("should not be reached "+depth, true);
1471+
fail("should not be reached "+depth);
14731472
} catch (RuntimeException e) {
14741473
assertEquals("42", e.getMessage());
14751474
} finally {
@@ -1481,7 +1480,7 @@ public void test_syncCall_Exception() {
14811480
final Display display = new Display();
14821481
try {
14831482
int depth=display.syncCall(() -> {throw new IOException("42");});
1484-
assertFalse("should not be reached "+depth, true);
1483+
fail("should not be reached "+depth);
14851484
} catch (IOException e) {
14861485
assertEquals("42", e.getMessage());
14871486
} finally {
@@ -1494,20 +1493,18 @@ public void test_syncCall_SWTException() {
14941493
display.dispose();
14951494
try {
14961495
int magic=display.syncCall(() -> {display.dispose(); return 42;});
1497-
assertFalse("should not be reached "+magic, true);
1496+
fail("should not be reached "+magic);
14981497
} catch (SWTException e) {
14991498
assertEquals("Device is disposed", e.getMessage());
15001499
}
15011500
}
15021501
@Test
1503-
public void test_syncCall_concurrentCallable() {
1502+
public void test_syncCall_concurrentCallable() throws Exception {
15041503
final Display display = new Display();
15051504
try {
15061505
java.util.concurrent.Callable<Integer> c=() -> {return 42;};
15071506
int magic=display.syncCall(c::call);
15081507
assertEquals(42, magic);
1509-
} catch (Exception e) {
1510-
assertFalse("should not be reached ", true);
15111508
} finally {
15121509
display.dispose();
15131510
}
@@ -1518,7 +1515,7 @@ public void test_syncCall_concurrentCallable_Exception() {
15181515
try {
15191516
java.util.concurrent.Callable<Integer> c=() -> {throw new IOException("42");};
15201517
int depth=display.syncCall(c::call);
1521-
assertFalse("should not be reached "+depth, true);
1518+
fail("should not be reached "+depth);
15221519
} catch (Exception e) {
15231520
assertEquals("42", e.getMessage());
15241521
} finally {
@@ -1560,7 +1557,7 @@ public void test_timerExecILjava_lang_Runnable() {
15601557
}
15611558

15621559
// Verify the timerExec with less than zero milliseconds didn't execute.
1563-
assertFalse("< 0 ms timer did execute", timerExecRan[0]);
1560+
assertFalse(timerExecRan[0], "< 0 ms timer did execute");
15641561
} finally {
15651562
display.dispose();
15661563
}
@@ -1589,8 +1586,8 @@ public void test_getDPI() {
15891586
Display display = new Display();
15901587
try {
15911588
Point p = display.getDPI();
1592-
assertTrue("horizontal DPI not greater than zero", p.x > 0);
1593-
assertTrue("vertical DPI not greater than zero", p.y > 0);
1589+
assertTrue(p.x > 0, "horizontal DPI not greater than zero" );
1590+
assertTrue(p.y > 0, "vertical DPI not greater than zero");
15941591
} finally {
15951592
display.dispose();
15961593
}
@@ -1601,7 +1598,7 @@ public void test_getDepth() {
16011598
Display display = new Display();
16021599
try {
16031600
int d = display.getDepth();
1604-
assertTrue("depth not greater than zero", d > 0);
1601+
assertTrue(d > 0, "depth not greater than zero" );
16051602
} finally {
16061603
display.dispose();
16071604
}
@@ -1612,7 +1609,7 @@ public void test_getFontListLjava_lang_StringZ() {
16121609
try {
16131610
FontData[] scalable = display.getFontList(null, true);
16141611
FontData[] non_scalable = display.getFontList(null, false);
1615-
assertTrue("no fonts detected", (scalable.length + non_scalable.length) > 0);
1612+
assertTrue((scalable.length + non_scalable.length) > 0, "no fonts detected");
16161613
} finally {
16171614
display.dispose();
16181615
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/performance/PerformanceTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit.performance;
1515

16-
17-
import org.junit.runner.RunWith;
18-
import org.junit.runners.Suite;
16+
import org.junit.platform.suite.api.SelectClasses;
17+
import org.junit.platform.suite.api.Suite;
1918

2019
/**
2120
* Suite for running SWT performance test cases.
2221
*/
23-
@RunWith(Suite.class)
24-
@Suite.SuiteClasses({
22+
@Suite
23+
@SelectClasses({
2524
Test_situational.class
2625
})
2726
public class PerformanceTests {

tests/org.eclipse.swt.tests/META-INF/MANIFEST.MF

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ Bundle-Version: 3.107.800.qualifier
66
Bundle-Vendor: Eclipse.org
77
Export-Package: org.eclipse.swt.tests.junit,
88
org.eclipse.swt.tests.junit.performance
9-
Require-Bundle: org.junit;bundle-version="4.12.0",
9+
Require-Bundle: org.junit;bundle-version="4.13.2",
10+
junit-vintage-engine;bundle-version="5.12.0",
11+
junit-jupiter-engine;bundle-version="5.12.0",
12+
junit-jupiter-params;bundle-version="5.12.0",
13+
junit-jupiter-api;bundle-version="5.12.0",
14+
junit-platform-suite-api;bundle-version="1.12.0",
15+
junit-platform-suite-commons;bundle-version="1.12.0",
16+
junit-platform-suite-engine;bundle-version="1.12.0",
1017
org.eclipse.swt;bundle-version="3.120.0",
1118
org.eclipse.test;bundle-version="3.6.200",
1219
org.eclipse.test.performance;bundle-version="3.13.0"

0 commit comments

Comments
 (0)