Skip to content

Commit

Permalink
Clean up stages before each test (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jperedadnr authored Nov 27, 2024
1 parent 880a5ac commit 5332d70
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class NodeFinderImplTest {

@After
public void cleanup() throws TimeoutException {
FxToolkit.setupFixture(this::cleanupStages);
FxToolkit.cleanupStages();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class BoundsLocatorImplTest {
@After
public void cleanupSpec() throws TimeoutException {
FxToolkit.setupFixture(() -> primaryWindow.close());
FxToolkit.cleanupStages();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 5332d70

Please sign in to comment.