Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Moved ShortcutKeyTest to core package. #342

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.