Skip to content

Commit b1f947e

Browse files
committed
Convert Program tests to JUnit 5.
1 parent e3c0392 commit b1f947e

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

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

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 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
@@ -15,18 +15,18 @@
1515
package org.eclipse.swt.tests.junit;
1616

1717
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertTrue;
20-
import static org.junit.Assert.fail;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertThrows;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.HashSet;
2323
import java.util.Set;
2424

2525
import org.eclipse.swt.SWT;
2626
import org.eclipse.swt.program.Program;
2727
import org.eclipse.swt.widgets.Display;
28-
import org.junit.Before;
29-
import org.junit.Test;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.Test;
3030

3131
/**
3232
* Automated Test Suite for class org.eclipse.swt.program.Program
@@ -35,8 +35,8 @@
3535
*/
3636
public class Test_org_eclipse_swt_program_Program {
3737

38-
@Before
39-
public void setUp() {
38+
@BeforeAll
39+
public static void setUp() {
4040
Display.getDefault();
4141
}
4242

@@ -60,20 +60,16 @@ public void test_executeLjava_lang_String() {
6060
// This test is incomplete because a true test of execute would open
6161
// an application that cannot be programmatically closed.
6262

63-
try {
64-
Program[] programs = Program.getPrograms();
65-
if (programs != null && programs.length > 0) {
63+
Program[] programs = Program.getPrograms();
64+
if (programs != null && programs.length > 0) {
6665

67-
// Cannot test empty string argument because it may launch something.
68-
//boolean result = programs[0].execute("");
69-
//assertFalse(result);
66+
// Cannot test empty string argument because it may launch something.
67+
//boolean result = programs[0].execute("");
68+
//assertFalse(result);
7069

71-
// test null argument
70+
// test null argument
7271

73-
programs[0].execute(null);
74-
fail("Failed to throw ERROR_NULL_ARGUMENT");
75-
}
76-
} catch (IllegalArgumentException e) {
72+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,()-> programs[0].execute(null), "Failed to throw ERROR_NULL_ARGUMENT");
7773
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
7874
}
7975
}
@@ -89,16 +85,9 @@ public void test_findProgramLjava_lang_String() {
8985
}
9086
}
9187

92-
try {
93-
Program.findProgram(null);
94-
fail("Failed to throw ERROR_NULL_ARGUMENT");
95-
} catch (IllegalArgumentException e) {
96-
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
97-
} catch (Exception e) {
98-
fail("Invalid Exception thrown of type "+e.getClass());
99-
} catch (Error e) {
100-
fail("Invalid Error thrown of type "+e.getClass());
101-
}
88+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> Program.findProgram(null),
89+
"Failed to throw ERROR_NULL_ARGUMENT");
90+
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
10291
}
10392

10493
@Test
@@ -158,12 +147,7 @@ public void test_getPrograms() {
158147
assertNotNull(program);
159148

160149
// test if the list contains same objects multiple times
161-
if (lookup.contains(program)) {
162-
fail("Duplicated list entry for " + program);
163-
}
164-
else {
165-
lookup.add(program);
166-
}
150+
assertTrue (lookup.add(program), "Duplicated list entry for " + program);
167151
}
168152
}
169153

@@ -177,12 +161,9 @@ public void test_launchLjava_lang_String() {
177161

178162
// test null argument
179163

180-
try {
181-
Program.launch(null);
182-
fail("Failed to throw ERROR_NULL_ARGUMENT");
183-
} catch (IllegalArgumentException e) {
184-
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
185-
}
164+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> Program.launch(null),
165+
"Failed to throw ERROR_NULL_ARGUMENT");
166+
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
186167
}
187168

188169
@Test

0 commit comments

Comments
 (0)