From 5332d70a276c4eb02c0e204f4348e85dd8f78ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pereda?= Date: Wed, 27 Nov 2024 22:07:22 +0100 Subject: [PATCH] Clean up stages before each test (#14) --- .../org/testfx/assertions/api/ButtonAssertTest.java | 6 ++++++ .../testfx/assertions/api/ComboBoxAssertTest.java | 6 ++++++ .../testfx/assertions/api/ListViewAssertTest.java | 6 ++++++ .../org/testfx/assertions/api/NodeAssertTest.java | 6 ++++++ .../org/testfx/assertions/api/ParentAssertTest.java | 6 ++++++ .../testfx/assertions/api/StyleableAssertTest.java | 6 ++++++ .../testfx/assertions/api/TableViewAssertTest.java | 6 ++++++ .../cases/acceptance/NodeAndPointQueryTest.java | 6 ++++++ .../testfx/cases/integration/SimpleLabelTest.java | 10 ++++++++-- .../testfx/matcher/control/ButtonMatchersTest.java | 6 ++++++ .../testfx/matcher/control/ComboBoxMatchersTest.java | 6 ++++++ .../testfx/matcher/control/ListViewMatchersTest.java | 6 ++++++ .../matcher/control/TableViewMatchersTest.java | 6 ++++++ .../java/org/testfx/robot/impl/ShortcutKeyTest.java | 3 ++- .../org/testfx/robot/impl/WriteRobotImplTest.java | 6 ++++++ .../service/adapter/impl/GlassRobotAdapterTest.java | 3 ++- .../service/adapter/impl/JavafxRobotAdapterTest.java | 3 ++- .../service/finder/impl/NodeFinderImplTest.java | 2 +- .../service/locator/impl/BoundsLocatorImplTest.java | 1 + .../service/support/impl/CaptureSupportImplTest.java | 6 ++++++ .../testfx/toolkit/impl/ToolkitServiceImplTest.java | 12 ++++++------ 21 files changed, 106 insertions(+), 12 deletions(-) diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ButtonAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ButtonAssertTest.java index 2779514be..bc14aa68f 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ButtonAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ButtonAssertTest.java @@ -19,6 +19,7 @@ import javafx.scene.control.Button; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -46,6 +47,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void isCancelButton() { // given: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ComboBoxAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ComboBoxAssertTest.java index 113844dad..6fcc64dc8 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ComboBoxAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ComboBoxAssertTest.java @@ -20,6 +20,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -50,6 +51,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasExactlyNumItems() { assertThat(comboBox).hasExactlyNumItems(4); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ListViewAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ListViewAssertTest.java index 3d10ca157..398661ba1 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ListViewAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ListViewAssertTest.java @@ -21,6 +21,7 @@ import javafx.scene.control.ListView; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -52,6 +53,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasListCell() { assertThat(listView).hasListCell("alice"); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/NodeAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/NodeAssertTest.java index 98b5e84b6..856126df8 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/NodeAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/NodeAssertTest.java @@ -26,6 +26,7 @@ import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.testfx.api.FxRobot; @@ -48,6 +49,11 @@ public static void setupSpec() throws Exception { FxToolkit.registerPrimaryStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasText_with_button() throws Exception { // given: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ParentAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ParentAssertTest.java index f434f0206..9b6626fc3 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ParentAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/ParentAssertTest.java @@ -20,6 +20,7 @@ import javafx.scene.control.Label; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.testfx.api.FxRobot; @@ -35,6 +36,11 @@ public static void setupSpec() throws Exception { FxToolkit.registerPrimaryStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasAnyChild() throws Exception { // given (a StackPane with children which is-a Parent): diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/StyleableAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/StyleableAssertTest.java index 7db5e82bd..ccc4b30a6 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/StyleableAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/StyleableAssertTest.java @@ -20,6 +20,7 @@ import javafx.scene.control.Button; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.testfx.api.FxRobot; @@ -34,6 +35,11 @@ public static void setupSpec() throws Exception { FxToolkit.registerPrimaryStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasId() throws Exception { // given (a Button which is-a Styleable): diff --git a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/TableViewAssertTest.java b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/TableViewAssertTest.java index 10b0dd7b3..cdfb1cf52 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/TableViewAssertTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/assertions/api/TableViewAssertTest.java @@ -26,6 +26,7 @@ import javafx.scene.control.cell.MapValueFactory; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -80,6 +81,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasTableCell() { assertThat(tableView).hasTableCell("alice"); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/cases/acceptance/NodeAndPointQueryTest.java b/subprojects/testfx-core/src/test/java/org/testfx/cases/acceptance/NodeAndPointQueryTest.java index 2fa32f4a4..5c272120d 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/cases/acceptance/NodeAndPointQueryTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/cases/acceptance/NodeAndPointQueryTest.java @@ -29,6 +29,7 @@ import javafx.scene.layout.VBox; import org.assertj.core.api.Assertions; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -82,6 +83,11 @@ public void setup() throws Exception { }); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void node_queryFirst_returns_node() { // when: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/cases/integration/SimpleLabelTest.java b/subprojects/testfx-core/src/test/java/org/testfx/cases/integration/SimpleLabelTest.java index 04a381b57..5c494d71b 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/cases/integration/SimpleLabelTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/cases/integration/SimpleLabelTest.java @@ -21,17 +21,23 @@ import javafx.scene.layout.StackPane; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.testfx.TestFXRule; +import org.testfx.api.FxRobot; import org.testfx.api.FxToolkit; -import org.testfx.cases.TestCaseBase; -public class SimpleLabelTest extends TestCaseBase { +public class SimpleLabelTest extends FxRobot { @Rule public TestFXRule testFXRule = new TestFXRule(); + @BeforeClass + public static void setupSpec() throws Exception { + FxToolkit.registerPrimaryStage(); + } + @Before public void setup() throws Exception { FxToolkit.setupStage(stage -> { diff --git a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ButtonMatchersTest.java b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ButtonMatchersTest.java index a3279b268..58c5983a2 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ButtonMatchersTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ButtonMatchersTest.java @@ -19,6 +19,7 @@ import javafx.scene.control.Button; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -56,6 +57,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void isCancelButton() { // given: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ComboBoxMatchersTest.java b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ComboBoxMatchersTest.java index fd7b913a4..5a91b04e2 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ComboBoxMatchersTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ComboBoxMatchersTest.java @@ -20,6 +20,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -56,6 +57,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasItems() { assertThat(comboBox, ComboBoxMatchers.hasItems(4)); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ListViewMatchersTest.java b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ListViewMatchersTest.java index 24b1b635c..08ba5cfde 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ListViewMatchersTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/ListViewMatchersTest.java @@ -21,6 +21,7 @@ import javafx.scene.control.ListView; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -58,6 +59,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasListCell() { assertThat(listView, ListViewMatchers.hasListCell("alice")); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/TableViewMatchersTest.java b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/TableViewMatchersTest.java index 5f64acd3f..3359addd1 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/TableViewMatchersTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/matcher/control/TableViewMatchersTest.java @@ -35,6 +35,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.layout.StackPane; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; @@ -101,6 +102,11 @@ public void setup() throws Exception { FxToolkit.showStage(); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void hasTableCell() { assertThat(tableView, TableViewMatchers.hasTableCell("alice")); diff --git a/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/ShortcutKeyTest.java b/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/ShortcutKeyTest.java index c0c6f46d5..41477b1d5 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/ShortcutKeyTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/ShortcutKeyTest.java @@ -112,9 +112,10 @@ public void setup() throws TimeoutException { } @After - public void cleanup() { + public final void tearDown() throws Throwable { // prevent hanging if test fails release(new KeyCode[0]); + FxToolkit.cleanupStages(); } /** diff --git a/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/WriteRobotImplTest.java b/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/WriteRobotImplTest.java index 9e8c3f6ec..6078bb0c4 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/WriteRobotImplTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/robot/impl/WriteRobotImplTest.java @@ -21,6 +21,7 @@ import javafx.scene.layout.Region; import javafx.stage.Stage; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -66,6 +67,11 @@ public void setup() throws Exception { writeRobot = new WriteRobotImpl(baseRobot, sleepRobot, windowFinder); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void write_char() { // given: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/GlassRobotAdapterTest.java b/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/GlassRobotAdapterTest.java index a05907fda..a8b0ae072 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/GlassRobotAdapterTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/GlassRobotAdapterTest.java @@ -103,9 +103,10 @@ public void setup() throws Exception { } @After - public void cleanup() { + public final void tearDown() throws Throwable { robotAdapter.keyRelease(KeyCode.A); robotAdapter.mouseRelease(MouseButton.PRIMARY); + FxToolkit.cleanupStages(); } @Test diff --git a/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/JavafxRobotAdapterTest.java b/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/JavafxRobotAdapterTest.java index 773fe21c3..0602ac9e7 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/JavafxRobotAdapterTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/service/adapter/impl/JavafxRobotAdapterTest.java @@ -109,9 +109,10 @@ public void setup() throws Exception { } @After - public void cleanup() { + public final void tearDown() throws Throwable { robotAdapter.keyRelease(KeyCode.A); robotAdapter.mouseRelease(MouseButton.PRIMARY); + FxToolkit.cleanupStages(); } @Test diff --git a/subprojects/testfx-core/src/test/java/org/testfx/service/finder/impl/NodeFinderImplTest.java b/subprojects/testfx-core/src/test/java/org/testfx/service/finder/impl/NodeFinderImplTest.java index 37969897e..4b0d67111 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/service/finder/impl/NodeFinderImplTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/service/finder/impl/NodeFinderImplTest.java @@ -78,7 +78,7 @@ public class NodeFinderImplTest { @After public void cleanup() throws TimeoutException { - FxToolkit.setupFixture(this::cleanupStages); + FxToolkit.cleanupStages(); } @Before diff --git a/subprojects/testfx-core/src/test/java/org/testfx/service/locator/impl/BoundsLocatorImplTest.java b/subprojects/testfx-core/src/test/java/org/testfx/service/locator/impl/BoundsLocatorImplTest.java index 819b03d6e..9e81c2bc8 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/service/locator/impl/BoundsLocatorImplTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/service/locator/impl/BoundsLocatorImplTest.java @@ -83,6 +83,7 @@ public class BoundsLocatorImplTest { @After public void cleanupSpec() throws TimeoutException { FxToolkit.setupFixture(() -> primaryWindow.close()); + FxToolkit.cleanupStages(); } @Before diff --git a/subprojects/testfx-core/src/test/java/org/testfx/service/support/impl/CaptureSupportImplTest.java b/subprojects/testfx-core/src/test/java/org/testfx/service/support/impl/CaptureSupportImplTest.java index 862ffb4bc..4f14050a0 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/service/support/impl/CaptureSupportImplTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/service/support/impl/CaptureSupportImplTest.java @@ -33,6 +33,7 @@ import javafx.scene.layout.StackPane; import javafx.stage.Stage; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -87,6 +88,11 @@ public void setup() throws Exception { FxToolkit.setupApplication(LoginDialog.class); } + @After + public final void tearDown() throws Throwable { + FxToolkit.cleanupStages(); + } + @Test public void capture_node() { // given: diff --git a/subprojects/testfx-core/src/test/java/org/testfx/toolkit/impl/ToolkitServiceImplTest.java b/subprojects/testfx-core/src/test/java/org/testfx/toolkit/impl/ToolkitServiceImplTest.java index db17f03d5..2fb774f72 100644 --- a/subprojects/testfx-core/src/test/java/org/testfx/toolkit/impl/ToolkitServiceImplTest.java +++ b/subprojects/testfx-core/src/test/java/org/testfx/toolkit/impl/ToolkitServiceImplTest.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Parent; @@ -34,6 +35,7 @@ import org.junit.Rule; import org.junit.Test; import org.testfx.TestFXRule; +import org.testfx.api.FxToolkit; import org.testfx.toolkit.PrimaryStageApplication; import org.testfx.toolkit.ToolkitService; @@ -66,6 +68,7 @@ public static void setupSpec() throws Exception { @Before public void setup() { waitForAsyncFx(2000, () -> { + Platform.setImplicitExit(false); primaryStage.show(); primaryStage.toBack(); primaryStage.toFront(); @@ -73,11 +76,8 @@ public void setup() { } @After - public void cleanup() { - waitForAsyncFx(2000, () -> { - Platform.setImplicitExit(false); - primaryStage.hide(); - }); + public void cleanup() throws TimeoutException { + FxToolkit.cleanupStages(); } @Test @@ -131,7 +131,7 @@ private String getApplicationParameter(String parameterName) { public static class FixtureScene extends Scene { public FixtureScene() { - super(new Region(), 400, 200); + super(new Region(), 300, 150); printCurrentThreadName("Scene#init()"); Parent parent = new StackPane(new Label(getClass().getSimpleName())); setRoot(parent);