Skip to content

Commit

Permalink
(refactor) Move ShortcutKeyTest to core package.
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Dec 19, 2016
1 parent a169fe9 commit f12fe61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
* CONDITIONS OF ANY KIND, either express or implied. See the Licence for the
* specific language governing permissions and limitations under the Licence.
*/
package org.testfx.framework.junit;
package org.testfx.robot.impl;

import java.util.Locale;
import java.util.concurrent.TimeoutException;

import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.testfx.api.FxRobot;
import org.testfx.api.FxToolkit;

import static javafx.scene.input.KeyCode.COMMAND;
import static javafx.scene.input.KeyCode.CONTROL;
Expand All @@ -36,7 +40,7 @@
* 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).
*/
public class ShortcutKeyTest extends ApplicationTest {
public class ShortcutKeyTest extends FxRobot {

private final KeyCode osSpecificShortcutKey;

Expand All @@ -49,24 +53,33 @@ public class ShortcutKeyTest extends ApplicationTest {
private final String pressedText = "pressed";
private final String releasedText = "released";

@Override
public void start(Stage stage) throws Exception {
field = new TextField();
field.setOnKeyPressed(e -> {
if (e.getCode().equals(osSpecificShortcutKey)) {
field.setText(pressedText);
}
e.consume();
@Before
public void setup() throws TimeoutException {
FxToolkit.registerPrimaryStage();
FxToolkit.setupStage(stage -> {
field = new TextField();
field.setOnKeyPressed(e -> {
if (e.getCode().equals(osSpecificShortcutKey)) {
field.setText(pressedText);
}
e.consume();
});
field.setOnKeyReleased(e -> {
if (e.getCode().equals(osSpecificShortcutKey)) {
field.setText(releasedText);
}
e.consume();
});
stage.setScene(new Scene(field));
stage.show();
field.requestFocus();
});
field.setOnKeyReleased(e -> {
if (e.getCode().equals(osSpecificShortcutKey)) {
field.setText(releasedText);
}
e.consume();
});
stage.setScene(new Scene(field, 400, 400));
stage.show();
field.requestFocus();
}

@After
public void cleanup() throws TimeoutException {
// prevent hanging if test fails
release(SHORTCUT, osSpecificShortcutKey);
}

@Test
Expand Down

This file was deleted.

0 comments on commit f12fe61

Please sign in to comment.