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
1515package org .eclipse .swt .tests .junit ;
1616
1717import 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
2222import java .util .HashSet ;
2323import java .util .Set ;
2424
2525import org .eclipse .swt .SWT ;
2626import org .eclipse .swt .program .Program ;
2727import 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
3535 */
3636public 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