Skip to content

Commit

Permalink
(refactor) Use verifyThat instead of assertThat where FxRobot is used
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Aug 22, 2017
1 parent 2b5664d commit 276cb4b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public void setup() throws Exception {
@Test
public void missing_is_null() {
// expect:
verifyThat("#missing", isNull());
verifyThat("#missing", isNull(), this);
}

@Test
public void button_is_not_null() {
// expect:
verifyThat("#button", isNotNull());
verifyThat("#button", isNotNull(), this);
}

@Test
public void button_is_enabled() {
// expect:
verifyThat("#button", isEnabled());
verifyThat("#button", isEnabled(), this);
}

@Test
Expand All @@ -72,13 +72,13 @@ public void button_is_disabled() {
interact(() -> lookup("#button").query().setDisable(true));

// then:
verifyThat("#button", isDisabled());
verifyThat("#button", isDisabled(), this);
}

@Test
public void button_is_visible() {
// expect:
verifyThat("#button", isVisible());
verifyThat("#button", isVisible(), this);
}

@Test
Expand All @@ -87,7 +87,7 @@ public void button_is_invisible() {
interact(() -> lookup("#button").query().setVisible(false));

// then:
verifyThat("#button", isInvisible());
verifyThat("#button", isInvisible(), this);
}

@Test
Expand All @@ -96,13 +96,13 @@ public void button_has_label() {
clickOn("#button");

// then:
verifyThat("#button", hasText("clicked!"));
verifyThat("#button", hasText("clicked!"), this);
}

@Test
public void button_has_not_label() {
// expect:
verifyThat("#button", not(hasText("clicked!")));
verifyThat("#button", not(hasText("clicked!")), this);
}

//@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.testfx.api.FxAssert.verifyThat;

public class FxToolkitBasicTest extends TestCaseBase {

Expand All @@ -54,7 +54,7 @@ public void registerPrimaryStage_should_return_the_primary_stage() throws Except
Stage stage = FxToolkit.registerPrimaryStage();

// then:
assertThat(stage, instanceOf(Stage.class));
verifyThat(stage, instanceOf(Stage.class));
}

@Test
Expand All @@ -66,7 +66,7 @@ public void registerPrimaryStage_should_update_the_registered_stage() throws Exc
Stage stage = FxToolkit.registerPrimaryStage();

// then:
assertThat(FxToolkit.toolkitContext().getRegisteredStage(), is(stage));
verifyThat(FxToolkit.toolkitContext().getRegisteredStage(), is(stage));
}

@Test
Expand All @@ -75,7 +75,7 @@ public void registerStage_should_return_the_stage() throws Exception {
Stage stage = FxToolkit.registerStage(Stage::new);

// then:
assertThat(stage, instanceOf(Stage.class));
verifyThat(stage, instanceOf(Stage.class));
}

@Test
Expand All @@ -87,7 +87,7 @@ public void registerStage_should_update_the_registered_stage() throws Exception
Stage stage = FxToolkit.registerStage(Stage::new);

// then:
assertThat(FxToolkit.toolkitContext().getRegisteredStage(), is(stage));
verifyThat(FxToolkit.toolkitContext().getRegisteredStage(), is(stage));
}

@Test
Expand All @@ -99,7 +99,7 @@ public void showStage_should_show_the_registered_stage() throws Exception {
FxToolkit.showStage();

// then:
assertThat(stage.isShowing(), is(true));
verifyThat(stage.isShowing(), is(true));
}

@Test
Expand All @@ -113,7 +113,7 @@ public void hideStage_should_hide_the_registered_stage() throws Exception {
FxToolkit.hideStage();

// then:
assertThat(stage.isShowing(), is(false));
verifyThat(stage.isShowing(), is(false));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.testfx.TestFXRule;
import org.testfx.api.FxAssert;
import org.testfx.api.FxToolkit;

import static org.testfx.api.FxAssert.verifyThat;

@Ignore
public class SceneRootAssertionTest {

Expand All @@ -51,7 +52,7 @@ public void setupSpec() throws Exception {

@Test
public void should_have_stage_root_with_label() {
FxAssert.verifyThat(stackPane, hasChild(label));
verifyThat(stackPane, hasChild(label));
}

private Predicate<Parent> hasChild(Node node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void setupListView(ListView<String> listView) {
@Test
public void should_have_initialized_items() {
// expect:
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3"));
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3"));
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3"), this);
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3"), this);
}

@Test
Expand All @@ -101,8 +101,8 @@ public void should_drag_and_drop_from_left_to_right() {
drop();

// then:
verifyThat(leftListView.getItems(), contains("L2", "L3"));
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3", "L1")); // gets added to end of ListView
verifyThat(leftListView.getItems(), contains("L2", "L3"), this);
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3", "L1"), this); // gets added to end of ListView
}

@Test
Expand All @@ -113,8 +113,8 @@ public void should_drag_and_drop_from_right_to_left() {
WaitForAsyncUtils.waitForFxEvents();

// then:
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3", "R3"));
verifyThat(rightListView.getItems(), contains("R1", "R2"));
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3", "R3"), this);
verifyThat(rightListView.getItems(), contains("R1", "R2"), this);
}

@Ignore("see #383")
Expand All @@ -126,8 +126,8 @@ public void should_drag_and_drop_from_left_to_left() {
WaitForAsyncUtils.waitForFxEvents();

// then:
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3"));
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3"));
verifyThat(leftListView.getItems(), contains("L1", "L2", "L3"), this);
verifyThat(rightListView.getItems(), contains("R1", "R2", "R3"), this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
import org.testfx.api.FxToolkit;
import org.testfx.robot.Motion;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import static org.testfx.api.FxAssert.verifyThat;

public class MenuBarTest {

@Rule
Expand Down Expand Up @@ -99,12 +100,12 @@ public void should_move_vertically_first() throws Exception {
// First we show that it is indeed the case that {@code editMenu} is triggered when moving directly:
editMenu.setOnShown(event -> editMenuShownLatch.countDown());
fxRobot.clickOn("#fileMenu").clickOn("#newItem", Motion.DIRECT);
assertThat(editMenuShownLatch.await(3, TimeUnit.SECONDS), is(true));
assertThat(newMenuShownLatch.getCount(), is(1L));
verifyThat(editMenuShownLatch.await(3, TimeUnit.SECONDS), is(true), fxRobot);
verifyThat(newMenuShownLatch.getCount(), is(1L), fxRobot);

// Next we show that calling the "clickOn" method without specifying the type of motion automatically
// uses Motion.VERTICAL_FIRST because "#newItem" is a MenuItem.
fxRobot.clickOn("#fileMenu").clickOn("#newItem");
assertThat(newMenuShownLatch.await(3, TimeUnit.SECONDS), is(true));
verifyThat(newMenuShownLatch.await(3, TimeUnit.SECONDS), is(true), fxRobot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import static javafx.scene.input.KeyCode.CONTROL;
import static javafx.scene.input.KeyCode.SHORTCUT;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import static org.testfx.api.FxAssert.verifyThat;

/**
* Tests whether pressing {@code KeyCode.SHORTCUT} will convert into the OS-specific KeyCode (i.e.
* {@code KeyCode.COMMAND} for Macs and {@code KeyCode.CONTROL} for everything else).
Expand Down Expand Up @@ -92,7 +93,7 @@ public void shortcut_keyCode_converts_to_OS_specific_keyCode_when_pressed() {
press(SHORTCUT);

// then:
assertThat(field.getText(), equalTo(pressedText));
verifyThat(field.getText(), equalTo(pressedText), this);
}

@Test
Expand All @@ -101,12 +102,12 @@ public void shortcut_keyCode_converts_to_OS_specific_keyCode_when_released() {
press(osSpecificShortcutKey);

// and:
assertThat(field.getText(), equalTo(pressedText));
verifyThat(field.getText(), equalTo(pressedText), this);

// when:
release(SHORTCUT);

// then:
assertThat(field.getText(), equalTo(releasedText));
verifyThat(field.getText(), equalTo(releasedText), this);
}
}

0 comments on commit 276cb4b

Please sign in to comment.