1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2016 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2025 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
15
15
package org .eclipse .swt .tests .junit ;
16
16
17
17
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 ;
21
21
22
22
import java .util .HashSet ;
23
23
import java .util .Set ;
24
24
25
25
import org .eclipse .swt .SWT ;
26
26
import org .eclipse .swt .program .Program ;
27
27
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 ;
30
30
31
31
/**
32
32
* Automated Test Suite for class org.eclipse.swt.program.Program
35
35
*/
36
36
public class Test_org_eclipse_swt_program_Program {
37
37
38
- @ Before
39
- public void setUp () {
38
+ @ BeforeAll
39
+ public static void setUp () {
40
40
Display .getDefault ();
41
41
}
42
42
@@ -60,20 +60,16 @@ public void test_executeLjava_lang_String() {
60
60
// This test is incomplete because a true test of execute would open
61
61
// an application that cannot be programmatically closed.
62
62
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 ) {
66
65
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);
70
69
71
- // test null argument
70
+ // test null argument
72
71
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" );
77
73
assertSWTProblem ("Failed to throw ERROR_NULL_ARGUMENT" , SWT .ERROR_NULL_ARGUMENT , e );
78
74
}
79
75
}
@@ -89,16 +85,9 @@ public void test_findProgramLjava_lang_String() {
89
85
}
90
86
}
91
87
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 );
102
91
}
103
92
104
93
@ Test
@@ -158,12 +147,7 @@ public void test_getPrograms() {
158
147
assertNotNull (program );
159
148
160
149
// 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 );
167
151
}
168
152
}
169
153
@@ -177,12 +161,9 @@ public void test_launchLjava_lang_String() {
177
161
178
162
// test null argument
179
163
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 );
186
167
}
187
168
188
169
@ Test
0 commit comments