Skip to content

Commit 9412173

Browse files
committed
Convert o.e.swt.tests.gtk to JUnit 5
1 parent f59f98a commit 9412173

File tree

10 files changed

+51
-57
lines changed

10 files changed

+51
-57
lines changed
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Red Hat and others. All rights reserved.
2+
* Copyright (c) 2018, 2025 Red Hat and others. All rights reserved.
33
* The contents of this file are made available under the terms
44
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
55
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -14,21 +14,14 @@
1414
*/
1515
package org.eclipse.swt.tests.gtk;
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

21-
22-
@RunWith(Suite.class)
23-
@Suite.SuiteClasses({
24-
// Test.class be added here.
20+
@Suite
21+
@SelectClasses({
2522
Test_GtkConverter.class
2623
})
2724

2825
public class AllGTKTests {
2926

30-
public static void main(String[] args) {
31-
JUnitCore.main(AllGTKTests.class.getName()); // Enable once a test is added.
32-
}
33-
3427
}

tests/org.eclipse.swt.tests.gtk/JUnit Tests/org/eclipse/swt/tests/gtk/Test_GtkConverter.java

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

17-
import static org.junit.Assert.fail;
17+
import static org.junit.jupiter.api.Assertions.fail;
1818

1919
import java.nio.charset.StandardCharsets;
2020

2121
import org.eclipse.swt.internal.Converter;
22-
import org.junit.Ignore;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.Disabled;
23+
import org.junit.jupiter.api.Test;
2424

2525
/**
2626
* Good source for UTF-8 code points for testing:
@@ -144,7 +144,7 @@ public void test_HeuristicUTF16_LotsOfLetters() {
144144
* This test is documented, but is currently known to fail.
145145
*
146146
*/
147-
@Ignore
147+
@Disabled
148148
@Test
149149
public void test_Heuristic_specialSingleCases() {
150150
byte [] testBytes = "Ё".getBytes(StandardCharsets.UTF_16LE);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Bundle-Name: Eclipse SWT Tests Linux/gtk
44
Bundle-SymbolicName: org.eclipse.swt.tests.gtk
55
Bundle-Version: 3.109.100.qualifier
66
Bundle-Vendor: Eclipse.org
7-
Require-Bundle: org.junit;bundle-version="4.12.0",
8-
org.eclipse.swt
7+
Require-Bundle: junit-jupiter-api,
8+
org.eclipse.swt,
9+
junit-platform-suite-api
910
Eclipse-BundleShape: dir
1011
Bundle-RequiredExecutionEnvironment: JavaSE-17
1112
Automatic-Module-Name: org.eclipse.swt.tests.gtk

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug336238_ShellSetBoundFailTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Red Hat and others.
2+
* Copyright (c) 2018, 2025 Red Hat 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,10 +13,11 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.gtk.snippets;
1515

16-
import static org.junit.Assert.assertEquals;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1718

1819
import org.eclipse.swt.widgets.Shell;
19-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2021

2122
public class Bug336238_ShellSetBoundFailTest {
2223

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug497705_setBoundsAfterSetVisible.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*******************************************************************************/
1515
package org.eclipse.swt.tests.gtk.snippets;
1616

17-
import static org.junit.Assert.assertTrue;
17+
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1819

1920
import java.util.concurrent.atomic.AtomicInteger;
2021

@@ -26,9 +27,9 @@
2627
import org.eclipse.swt.widgets.Control;
2728
import org.eclipse.swt.widgets.Display;
2829
import org.eclipse.swt.widgets.Shell;
29-
import org.junit.After;
30-
import org.junit.Before;
31-
import org.junit.Test;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3233

3334

3435
/**
@@ -55,7 +56,7 @@ public class Bug497705_setBoundsAfterSetVisible {
5556
private Rectangle bounds;
5657
Control testControl;
5758

58-
@Before
59+
@BeforeEach
5960
public void setUp() {
6061
display = Display.getDefault();
6162
shell = new Shell(display);
@@ -183,7 +184,7 @@ public void works_drainingQueue() {
183184
verifyBounds();
184185
}
185186

186-
@After
187+
@AfterEach
187188
public void tearDown() {
188189
if (debugShowWidget) {
189190
if (!passed) System.err.println(log.toString());
@@ -195,7 +196,7 @@ public void tearDown() {
195196
}
196197
display.dispose();
197198
}
198-
assertTrue(log.toString(), passed);
199+
assertTrue(passed, log.toString());
199200
}
200201

201202
private void verifyBounds() {

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/manualJUnit/MJ_Table.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
import org.eclipse.swt.widgets.TableColumn;
5858
import org.eclipse.swt.widgets.TableItem;
5959
import org.eclipse.swt.widgets.Text;
60-
import org.junit.FixMethodOrder;
61-
import org.junit.Test;
62-
import org.junit.runners.MethodSorters;
60+
import org.junit.jupiter.api.MethodOrderer;
61+
import org.junit.jupiter.api.Test;
62+
import org.junit.jupiter.api.TestMethodOrder;
6363

64-
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // To make it easier for human to go through the tests. Same order makes tests easier to recognize.
64+
@TestMethodOrder(MethodOrderer.MethodName.class) // To make it easier for human to go through the tests. Same order makes tests easier to recognize.
6565
public class MJ_Table extends MJ_root {
6666

6767
// Shared elements:
@@ -112,7 +112,7 @@ public class MJ_Table extends MJ_root {
112112
*/
113113
@Test
114114
public void ownerDrawn_cheese_single_col () {
115-
knownToBeBrokenGtk3("Cheese on gtk3"); // z for warning
115+
// knownToBeBrokenGtk3("Cheese on gtk3"); // z for warning
116116
Shell shell = mkShell("Expected: There should be no cheese in the items. Move over shouldn't cheese out. See javadoc for screenshot");
117117
shell.setLayout(new FillLayout(SWT.VERTICAL));
118118

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/manualJUnit/MJ_Template.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import org.eclipse.swt.SWT;
1818
import org.eclipse.swt.widgets.Button;
1919
import org.eclipse.swt.widgets.Shell;
20-
import org.junit.FixMethodOrder;
21-
import org.junit.Test;
22-
import org.junit.runners.MethodSorters;
20+
import org.junit.jupiter.api.MethodOrderer;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.TestMethodOrder;
2323

2424
/** Convenience class for easy copy & paste */
25-
@FixMethodOrder(MethodSorters.JVM)
25+
@TestMethodOrder(MethodOrderer.MethodName.class)
2626
public class MJ_Template extends MJ_root {
2727

2828
@Test

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/manualJUnit/MJ_Tree.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import org.eclipse.swt.widgets.Tree;
3333
import org.eclipse.swt.widgets.TreeColumn;
3434
import org.eclipse.swt.widgets.TreeItem;
35-
import org.junit.FixMethodOrder;
36-
import org.junit.Test;
37-
import org.junit.runners.MethodSorters;
35+
import org.junit.jupiter.api.MethodOrderer;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.TestMethodOrder;
3838

3939
/** Convenience class for easy copy & paste */
40-
@FixMethodOrder(MethodSorters.JVM)
40+
@TestMethodOrder(MethodOrderer.MethodName.class)
4141
public class MJ_Tree extends MJ_root {
4242

4343

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/manualJUnit/MJ_curr_working_set.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
*/
1515
package org.eclipse.swt.tests.manualJUnit;
1616

17-
import org.junit.FixMethodOrder;
18-
import org.junit.runners.MethodSorters;
17+
import org.junit.jupiter.api.MethodOrderer;
18+
import org.junit.jupiter.api.TestMethodOrder;
1919

2020
/**
2121
* During development/testing, sometimes when you want to run specific set of jUnits, you can move them here temporarily.
2222
*/
23-
@FixMethodOrder(MethodSorters.JVM) // To make it easier for human to go through the tests. Same order makes tests easier to recognize.
23+
@TestMethodOrder(MethodOrderer.MethodName.class) // To make it easier for human to go through the tests. Same order makes tests easier to recognize.
2424
public class MJ_curr_working_set extends MJ_root {
2525

2626

tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/manualJUnit/MJ_root.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616

1717
package org.eclipse.swt.tests.manualJUnit;
1818

19-
import static org.junit.Assert.fail;
20-
import static org.junit.Assume.assumeTrue;
19+
import static org.junit.jupiter.api.Assertions.fail;
20+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2121

2222
import org.eclipse.swt.SWT;
2323
import org.eclipse.swt.widgets.Display;
2424
import org.eclipse.swt.widgets.Listener;
2525
import org.eclipse.swt.widgets.Shell;
26-
import org.junit.After;
27-
import org.junit.Before;
28-
import org.junit.Rule;
29-
import org.junit.rules.TestName;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.TestInfo;
3029

3130
/**
3231
* Some tests can't be automated and have to be tested manually by visual inspection.
@@ -52,15 +51,16 @@ public class MJ_root {
5251
/** Default Shell values */
5352
final int SWIDTH = 1200;
5453
final int SHEIGHT = 800;
55-
54+
private TestInfo testInfo;
5655
Display display;
57-
@Before //each test.
58-
public void setUp() {
56+
@BeforeEach //each test.
57+
public void setUp(TestInfo testInfo) {
5958
display = new Display();
6059
display.addFilter(SWT.KeyDown, globalTestValidatorViaKeyboard);
60+
this.testInfo = testInfo;
6161
}
6262

63-
@After
63+
@AfterEach
6464
public void tearDown() {
6565
if (!display.isDisposed()) { // pass = shell is disposed.
6666
display.dispose();
@@ -102,10 +102,8 @@ void mainLoop(Shell shell) {
102102
}
103103
};
104104

105-
@Rule
106-
public TestName testName = new TestName();
107105
private String getCurrentTestName() {
108-
return testName.getMethodName ();
106+
return testInfo.getDisplayName();
109107
}
110108

111109

0 commit comments

Comments
 (0)