diff --git a/build.gradle b/build.gradle
index ea10ff7e4de..c035a7ef712 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2128,8 +2128,6 @@ allprojects {
// By default all of our projects require junit for testing so we can just
// setup this dependency here.
dependencies {
- testImplementation group: "junit", name: "junit", version: "${junitVersion}"
- testImplementation group: "org.hamcrest", name: "hamcrest-core", version: "${hamcrestVersion}"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter", version: "${junitJupiterVersion}"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter-api", version: "${junitJupiterVersion}"
testImplementation group: "org.junit.jupiter", name: "junit-jupiter-params", version: "${junitJupiterVersion}"
@@ -2139,7 +2137,6 @@ allprojects {
testRuntimeOnly group: "org.junit.platform", name: "junit-platform-commons", version: "${junitPlatformVersion}"
testRuntimeOnly group: "org.junit.platform", name: "junit-platform-engine", version: "${junitPlatformVersion}"
testRuntimeOnly group: "org.junit.platform", name: "junit-platform-launcher", version: "${junitPlatformVersion}"
- testRuntimeOnly group: "org.junit.vintage", name: "junit-vintage-engine", version: "${junitJupiterVersion}"
if (BUILD_CLOSED && DO_JCOV) {
testImplementation name: "jcov"
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index f6843576b1d..023d8ded5f9 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -73,11 +73,6 @@ repositories {
}
}
-dependencies {
- testImplementation group: "junit", name: "junit", version: "4.13.2"
- testImplementation group: "org.hamcrest", name: "hamcrest-core", version: "1.3"
-}
-
// At the moment the ASM library shipped with Gradle that is used to
// discover the different test classes fails on Java 8, so in order
// to have sourceCompatibility set to 1.8 I have to also turn scanForClasses off
diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index 6b15e5bda22..fb3d03aab7e 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -155,14 +155,6 @@
-
-
-
-
-
-
-
-
@@ -294,19 +286,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -371,14 +350,6 @@
-
-
-
-
-
-
-
-
diff --git a/modules/javafx.graphics/src/test/java/test/javafx/css/StyleablePropertyFactoryTest.java b/modules/javafx.graphics/src/test/java/test/javafx/css/StyleablePropertyFactoryTest.java
index 1a9c1e4b209..76509871a3f 100644
--- a/modules/javafx.graphics/src/test/java/test/javafx/css/StyleablePropertyFactoryTest.java
+++ b/modules/javafx.graphics/src/test/java/test/javafx/css/StyleablePropertyFactoryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,8 @@
import javafx.scene.text.Font;
import javafx.util.Duration;
+import java.util.Objects;
+import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.List;
import javafx.css.CssMetaData;
@@ -55,27 +57,23 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class StyleablePropertyFactoryTest {
private static class Data {
- final PropertyReference propertyReference;
+ final PropertyReference propertyReference;
final String style;
final T value;
- final Matcher matcher;
+ final Predicate matcher;
Data(String name, String style, T value) {
- this(name,style,value,CoreMatchers.equalTo(value));
+ this(name, style, value, arg -> Objects.equals(arg, value));
}
- Data(String name, String style, T value, Matcher matcher) {
- this.propertyReference = new PropertyReference(MyStyleable.class, name);
+ Data(String name, String style, T value, Predicate matcher) {
+ this.propertyReference = new PropertyReference<>(MyStyleable.class, name);
this.style = style;
this.value = value;
this.matcher = matcher;
@@ -83,57 +81,46 @@ private static class Data {
}
public static Stream data() {
-
return Stream.of(
- Arguments.of(new Data("myBoolean", "-my-boolean: true;", Boolean.TRUE)),
- Arguments.of(new Data("myColor", "-my-color: red;", Color.RED)),
- Arguments.of(new Data("myDuration", "-my-duration: 30ms;", Duration.millis(30))),
- Arguments.of(new Data("myEffect", "-my-effect: innershadow(gaussian, red, 10, .5, 1, 1);",
- new InnerShadow(BlurType.GAUSSIAN, Color.RED, 10, .5, 1, 1),
- new BaseMatcher() {
- @Override
- public boolean matches(Object o) {
- InnerShadow actual = (InnerShadow)o;
- return (actual.getBlurType() == BlurType.GAUSSIAN &&
- actual.getColor().equals(Color.RED) &&
- Double.compare(actual.getRadius(),10d) == 0 &&
- Double.compare(actual.getChoke(),.5d) == 0 &&
- Double.compare(actual.getOffsetX(),1d) == 0 &&
- Double.compare(actual.getOffsetY(),1d) == 0);
- }
- @Override
- public void describeTo(Description description) {
- description.appendText("InnerShadow(BlurType.GAUSSIAN, Color.RED, 10, .5, 1, 1)");
- }
- })
- ),
- Arguments.of(new Data("myPos", "-my-pos: bottom-right;", Pos.BOTTOM_RIGHT)),
- Arguments.of(new Data("myFont", "-my-font: 18 system;", Font.font("system", 18))),
- Arguments.of(new Data("myInsets", "-my-insets: 1 2 3 4;", new Insets(1,2,3,4))),
- Arguments.of(new Data("myInsets", "-my-insets: 5;", new Insets(5,5,5,5))),
- Arguments.of(new Data("myInsets", "-my-insets: 7 8;", new Insets(7,8,7,8))),
- Arguments.of(new Data("myInsets", "-my-insets: 9 10 11;", new Insets(9,10,11,10))),
- Arguments.of(new Data("myPaint", "-my-paint: linear-gradient(from 0% 0% to 100% 100%, red 0%, black 100%);",
- new LinearGradient(0,0,1,1,true, CycleMethod.NO_CYCLE,new Stop[] { new Stop(0,Color.RED), new Stop(1,Color.BLACK) }))
- ),
- Arguments.of(new Data("myNumber", "-my-number: 2em;", Font.getDefault().getSize()*2)),
- Arguments.of(new Data("myString", "-my-string: \"yaba daba do\";", "yaba daba do")),
- Arguments.of(new Data("myUrl", "-my-url: url('http://www.oracle.com');", "http://www.oracle.com")),
- Arguments.of(new Data("mySelected", "-my-selected: false;", Boolean.FALSE))
+ Arguments.of(new Data<>("myBoolean", "-my-boolean: true;", Boolean.TRUE)),
+ Arguments.of(new Data<>("myColor", "-my-color: red;", Color.RED)),
+ Arguments.of(new Data<>("myDuration", "-my-duration: 30ms;", Duration.millis(30))),
+ Arguments.of(new Data<>("myEffect", "-my-effect: innershadow(gaussian, red, 10, .5, 1, 1);",
+ new InnerShadow(BlurType.GAUSSIAN, Color.RED, 10, .5, 1, 1),
+ actual -> (actual.getBlurType() == BlurType.GAUSSIAN
+ && actual.getColor().equals(Color.RED)
+ && Double.compare(actual.getRadius(), 10d) == 0
+ && Double.compare(actual.getChoke(), .5d) == 0
+ && Double.compare(actual.getOffsetX(), 1d) == 0
+ && Double.compare(actual.getOffsetY(), 1d) == 0))),
+ Arguments.of(new Data<>("myPos", "-my-pos: bottom-right;", Pos.BOTTOM_RIGHT)),
+ Arguments.of(new Data<>("myFont", "-my-font: 18 system;", Font.font("system", 18))),
+ Arguments.of(new Data<>("myInsets", "-my-insets: 1 2 3 4;", new Insets(1,2,3,4))),
+ Arguments.of(new Data<>("myInsets", "-my-insets: 5;", new Insets(5,5,5,5))),
+ Arguments.of(new Data<>("myInsets", "-my-insets: 7 8;", new Insets(7,8,7,8))),
+ Arguments.of(new Data<>("myInsets", "-my-insets: 9 10 11;", new Insets(9,10,11,10))),
+ Arguments.of(new Data<>("myPaint", "-my-paint: linear-gradient(from 0% 0% to 100% 100%, red 0%, black 100%);",
+ new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE,
+ new Stop(0, Color.RED),
+ new Stop(1, Color.BLACK)))),
+ Arguments.of(new Data<>("myNumber", "-my-number: 2em;", Font.getDefault().getSize()*2)),
+ Arguments.of(new Data<>("myString", "-my-string: \"yaba daba do\";", "yaba daba do")),
+ Arguments.of(new Data<>("myUrl", "-my-url: url('http://www.oracle.com');", "http://www.oracle.com")),
+ Arguments.of(new Data<>("mySelected", "-my-selected: false;", Boolean.FALSE))
);
}
@ParameterizedTest
@MethodSource("data")
- public void theTest(Data data) {
+ public void testCssStyling(Data data) {
MyStyleable styleable = new MyStyleable();
styleable.setStyle(data.style);
Scene scene = new Scene(styleable);
styleable.applyCss();
- ReadOnlyProperty prop = data.propertyReference.getProperty(styleable);
- assertThat(prop.getValue(), data.matcher);
+ ReadOnlyProperty prop = data.propertyReference.getProperty(styleable);
+ assertTrue(data.matcher.test(prop.getValue()), prop.getValue() + " does not match expected value");
}
public static class MyStyleable extends Group {
@@ -141,7 +128,7 @@ public static class MyStyleable extends Group {
public MyStyleable() {
}
- private static final StyleablePropertyFactory fac = new StyleablePropertyFactory<>(null);
+ private static final StyleablePropertyFactory fac = new StyleablePropertyFactory<>(null);
public ObservableValue myBooleanProperty () { return (ObservableValue) myBoolean; }
public Boolean getMyBoolean() { return myBoolean.getValue(); }
diff --git a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasScaledTest.java b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasScaledTest.java
index 846a34ccef0..d6c68288246 100644
--- a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasScaledTest.java
+++ b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasScaledTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,11 +25,9 @@
package test.javafx.embed.swt;
-import static org.junit.Assert.fail;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
+import javafx.embed.swt.FXCanvas;
+import javafx.scene.Scene;
+import javafx.scene.layout.Region;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
@@ -38,86 +36,90 @@
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.junit.Test;
-
-import javafx.embed.swt.FXCanvas;
-import javafx.scene.Scene;
-import javafx.scene.layout.Region;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
-public class FXCanvasScaledTest {
-
- private int cnt;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
- static Shell shell;
+import static org.junit.jupiter.api.Assertions.fail;
- static Display display;
+public class FXCanvasScaledTest extends SWTTest {
/* Base size, so that with a scaling of 125% there are different results for Math.round and Math.ceil */
- final static int TARGET_BASE_SIZE = 101;
+ static final int TARGET_BASE_SIZE = 101;
+
+ private int cnt;
+ private FXCanvas canvas;
- @Test(timeout = 10000)
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testScale() throws Throwable {
- System.setProperty("sun.java2d.uiScale.enabled", "true");
- System.setProperty("sun.java2d.uiScale", "125%");
- System.setProperty("glass.win.uiScale", "125%");
- System.setProperty("glass.win.renderScale", "125%");
- System.setProperty("glass.gtk.uiScale", "1.25");
- System.setProperty("swt.autoScale", "125");
+ runOnSwtThread(() -> {
+ System.setProperty("sun.java2d.uiScale.enabled", "true");
+ System.setProperty("sun.java2d.uiScale", "125%");
+ System.setProperty("glass.win.uiScale", "125%");
+ System.setProperty("glass.win.renderScale", "125%");
+ System.setProperty("glass.gtk.uiScale", "1.25");
+ System.setProperty("swt.autoScale", "125");
+
+ // Start the Application
+ Display display = Display.getCurrent();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.open();
- // Start the Application
- display = new Display();
- shell = new Shell(display);
- shell.setLayout(new FillLayout());
- final FXCanvas canvas = new FXCanvas(shell, SWT.NONE);
- initFX(canvas);
+ canvas = new FXCanvas(shell, SWT.NONE);
+ initFX(canvas);
- Timer t = new Timer();
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- switch (cnt) {
- case 0:
- display.asyncExec(() -> canvas.setBounds(0, 0, 201, 201));
- break;
- case 1:
- display.asyncExec(() -> canvas.setBounds(0, 0, TARGET_BASE_SIZE, TARGET_BASE_SIZE));
- break;
- case 2:
- t.cancel();
- display.asyncExec(() -> {
- // Capture painted component. Bounds are in pt, so size is 101 and not 127
- GC gc = new GC(canvas);
- final Image image = new Image(display, canvas.getBounds());
- gc.copyArea(image, canvas.getBounds().x, canvas.getBounds().y);
- gc.dispose();
- PaletteData palette = image.getImageData().palette;
- int referenceWhitePixel = image.getImageData().getPixel(0, 0);
- RGB referenceRGB = palette.getRGB(referenceWhitePixel);
- // check if there is a diagonal, which should be the right border
- for (int x = 10; x < 30; x++) {
- for (int y = 80; y < 100; y++) {
- int pixel = image.getImageData().getPixel(x, y);
- RGB rgb = palette.getRGB(pixel);
- if (!referenceRGB.equals(rgb)) {
- fail("image is skewed");
+ Timer t = new Timer();
+ TimerTask task = new TimerTask() {
+ @Override
+ public void run() {
+ switch (cnt) {
+ case 0:
+ display.asyncExec(() -> canvas.setBounds(0, 0, 201, 201));
+ break;
+ case 1:
+ display.asyncExec(() -> canvas.setBounds(0, 0, TARGET_BASE_SIZE, TARGET_BASE_SIZE));
+ break;
+ case 2:
+ t.cancel();
+ display.asyncExec(() -> {
+ // Capture painted component. Bounds are in pt, so size is 101 and not 127
+ GC gc = new GC(canvas);
+ final Image image = new Image(display, canvas.getBounds());
+ gc.copyArea(image, canvas.getBounds().x, canvas.getBounds().y);
+ gc.dispose();
+ PaletteData palette = image.getImageData().palette;
+ int referenceWhitePixel = image.getImageData().getPixel(0, 0);
+ RGB referenceRGB = palette.getRGB(referenceWhitePixel);
+ // check if there is a diagonal, which should be the right border
+ for (int x = 10; x < 30; x++) {
+ for (int y = 80; y < 100; y++) {
+ int pixel = image.getImageData().getPixel(x, y);
+ RGB rgb = palette.getRGB(pixel);
+ if (!referenceRGB.equals(rgb)) {
+ fail("image is skewed");
+ }
}
}
- }
- shell.close();
- });
- break;
+ shell.close();
+ });
+ break;
+ }
+ cnt++;
}
- cnt++;
- }
- };
- t.schedule(task, 500, 500);
+ };
+ t.schedule(task, 500, 500);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ });
}
private static void initFX(FXCanvas canvas) {
diff --git a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasTest.java b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasTest.java
index c9a0c1521bb..1a143c30956 100644
--- a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasTest.java
+++ b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/FXCanvasTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,30 +31,42 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
-import static org.junit.Assert.assertSame;
+import java.util.concurrent.TimeUnit;
-public class FXCanvasTest {
+import static org.junit.jupiter.api.Assertions.assertSame;
- @Rule
- public SwtRule ctx = new SwtRule();
+public class FXCanvasTest extends SWTTest {
- @Test(timeout = 10000)
- public void getFXCanvas() throws Throwable {
- final Shell shell = new Shell(Display.getCurrent());
- final FXCanvas canvas = new FXCanvas(shell, SWT.NONE);
- shell.open();
+ private FXCanvas canvas;
- // create and hook scene
- Scene scene = new Scene(new Group());
- canvas.setScene(scene);
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
+ public void testFXCanvas() throws Throwable {
+ runOnSwtThread(() -> {
+ Display display = Display.getCurrent();
+ Shell shell = new Shell(display);
+ canvas = new FXCanvas(shell, SWT.NONE);
+ shell.open();
- // check FXCanvas is properly retrieved
- assertSame(canvas, FXCanvas.getFXCanvas(canvas.getScene()));
+ // create and hook scene
+ Scene scene = new Scene(new Group());
+ canvas.setScene(scene);
- // FIXME: We cannot close the shell here because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=435066.
- // shell.close();
+ display.asyncExec(() -> {
+ // check FXCanvas is properly retrieved
+ assertSame(canvas, FXCanvas.getFXCanvas(canvas.getScene()));
+
+ shell.close();
+ });
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ });
}
}
diff --git a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTCursorsTest.java b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTCursorsTest.java
index 2414270b4e0..73e06200096 100644
--- a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTCursorsTest.java
+++ b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTCursorsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,35 +33,45 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
-import static org.junit.Assert.assertNotNull;
+import java.util.concurrent.TimeUnit;
-public class SWTCursorsTest {
+import static org.junit.jupiter.api.Assertions.assertNotNull;
- @Rule
- public SwtRule ctx = new SwtRule();
+public class SWTCursorsTest extends SWTTest {
- @Test(timeout = 10000)
+ private FXCanvas canvas;
+
+ @Test
+ @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testImageCursor() throws Throwable {
- final Shell shell = new Shell(Display.getCurrent());
- final FXCanvas canvas = new FXCanvas(shell, SWT.NONE);
- shell.open();
+ runOnSwtThread(() -> {
+ Display display = Display.getCurrent();
+ final Shell shell = new Shell(display);
+ canvas = new FXCanvas(shell, SWT.NONE);
+ shell.open();
+
+ // create and hook scene
+ Scene scene = new Scene(new Group());
+ canvas.setScene(scene);
- // create and hook scene
- Scene scene = new Scene(new Group());
- canvas.setScene(scene);
+ // set image cursor to scene
+ Image cursorImage = new Image("test/javafx/embed/swt/cursor.png");
+ scene.setCursor(new ImageCursor(cursorImage));
- // set image cursor to scene
- Image cursorImage = new Image("test/javafx/embed/swt/cursor.png");
- scene.setCursor(new ImageCursor(cursorImage));
+ display.asyncExec(() -> {
+ assertNotNull(canvas.getCursor());
- Display.getCurrent().asyncExec(() -> {
- assertNotNull(canvas.getCursor());
+ shell.close();
+ });
- // FIXME: We cannot close the shell here because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=435066.
- //shell.close();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
});
}
}
diff --git a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTTest.java b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTTest.java
new file mode 100644
index 00000000000..0b959061991
--- /dev/null
+++ b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SWTTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.javafx.embed.swt;
+
+import javafx.application.Platform;
+import org.eclipse.swt.widgets.Display;
+import org.junit.jupiter.api.BeforeAll;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+public abstract class SWTTest {
+
+ private static Display display;
+
+ @BeforeAll
+ static void beforeAll() {
+ Platform.setImplicitExit(false);
+
+ display = Display.getDefault();
+ }
+
+ protected final void runOnSwtThread(Runnable runnable) throws Throwable {
+ final AtomicReference throwableRef = new AtomicReference<>();
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ display.asyncExec(() -> {
+ try {
+ runnable.run();
+ } catch (Throwable e) {
+ throwableRef.set(e);
+ } finally {
+ display.asyncExec(latch::countDown);
+ }
+ });
+
+ while (latch.getCount() > 0) {
+ // run SWT event loop
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ Throwable thrown = throwableRef.get();
+ if (thrown != null) {
+ throw thrown;
+ }
+ }
+}
diff --git a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SwtRule.java b/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SwtRule.java
deleted file mode 100644
index 4476219a637..00000000000
--- a/modules/javafx.swt/src/test/java/test/javafx/embed/swt/SwtRule.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package test.javafx.embed.swt;
-
-import org.eclipse.swt.widgets.Display;
-import org.junit.rules.MethodRule;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.Statement;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * A {@code MethodRule} to execute test methods synchronously on the SWT UI thread. The execution will wait for any
- * asynchronous runnables scheduled by the test method on the SWT UI thread during its execution.
- */
-public class SwtRule implements MethodRule {
-
- private void rethrow(final AtomicReference throwableRef) throws Throwable {
- Throwable thrown = throwableRef.get();
- if (thrown != null) {
- throw thrown;
- }
- }
-
- @Override
- public Statement apply(final Statement base, final FrameworkMethod testMethod, final Object target) {
- return new Statement() {
-
- @Override
- public void evaluate() throws Throwable {
- Display display = Display.getDefault();
-
- // keep track of exceptions thrown in UI thread
- final AtomicReference throwableRef = new AtomicReference<>();
-
- final CountDownLatch latch = new CountDownLatch(1);
- display.asyncExec(() -> {
- try {
- // ensure test method is synchronously executed (without spawning a new thread)
- testMethod.invokeExplosively(target);
- } catch (Throwable throwable) {
- throwableRef.set(throwable);
- } finally {
- display.asyncExec(() -> {
- // wait for any runnables scheduled (asynchronously)
- // by test method on the UI thread
- latch.countDown();
- });
- }
- });
-
- while (latch.getCount() > 0) {
- // run SWT event loop
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
-
- rethrow(throwableRef);
- }
- };
- }
-}
diff --git a/tests/system/src/test/java/test/robot/javafx/scene/NodeInitializationStressTest.java b/tests/system/src/test/java/test/robot/javafx/scene/NodeInitializationStressTest.java
index 4276b2f631c..c5808340577 100644
--- a/tests/system/src/test/java/test/robot/javafx/scene/NodeInitializationStressTest.java
+++ b/tests/system/src/test/java/test/robot/javafx/scene/NodeInitializationStressTest.java
@@ -24,8 +24,9 @@
*/
package test.robot.javafx.scene;
-import static org.junit.Assume.assumeFalse;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;