Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,18 +15,18 @@
package org.eclipse.swt.tests.junit;

import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* Automated Test Suite for class org.eclipse.swt.program.Program
Expand All @@ -35,8 +35,8 @@
*/
public class Test_org_eclipse_swt_program_Program {

@Before
public void setUp() {
@BeforeAll
public static void setUp() {
Display.getDefault();
}

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

try {
Program[] programs = Program.getPrograms();
if (programs != null && programs.length > 0) {
Program[] programs = Program.getPrograms();
if (programs != null && programs.length > 0) {

// Cannot test empty string argument because it may launch something.
//boolean result = programs[0].execute("");
//assertFalse(result);
// Cannot test empty string argument because it may launch something.
//boolean result = programs[0].execute("");
//assertFalse(result);

// test null argument
// test null argument

programs[0].execute(null);
fail("Failed to throw ERROR_NULL_ARGUMENT");
}
} catch (IllegalArgumentException e) {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,()-> programs[0].execute(null), "Failed to throw ERROR_NULL_ARGUMENT");
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
}
}
Expand All @@ -89,16 +85,9 @@ public void test_findProgramLjava_lang_String() {
}
}

try {
Program.findProgram(null);
fail("Failed to throw ERROR_NULL_ARGUMENT");
} catch (IllegalArgumentException e) {
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
} catch (Exception e) {
fail("Invalid Exception thrown of type "+e.getClass());
} catch (Error e) {
fail("Invalid Error thrown of type "+e.getClass());
}
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> Program.findProgram(null),
"Failed to throw ERROR_NULL_ARGUMENT");
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
}

@Test
Expand Down Expand Up @@ -158,12 +147,7 @@ public void test_getPrograms() {
assertNotNull(program);

// test if the list contains same objects multiple times
if (lookup.contains(program)) {
fail("Duplicated list entry for " + program);
}
else {
lookup.add(program);
}
assertTrue (lookup.add(program), "Duplicated list entry for " + program);
}
}

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

// test null argument

try {
Program.launch(null);
fail("Failed to throw ERROR_NULL_ARGUMENT");
} catch (IllegalArgumentException e) {
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
}
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> Program.launch(null),
"Failed to throw ERROR_NULL_ARGUMENT");
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
}

@Test
Expand Down
Loading