Skip to content

Commit

Permalink
implement ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
toastkidjp committed Jan 17, 2017
1 parent 2539de7 commit ddb4384
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -39,6 +39,8 @@ dependencies {
provided 'org.slf4j:slf4j-log4j12:1.7.21'

testCompile 'junit:junit:4.11'
testCompile 'org.testfx:testfx-junit:4.0.5-alpha'
testCompile 'org.mockito:mockito-all:1.9.5'
}
compileJava {
//add required JavaFX libs to compile classpath
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/jp/toastkid/script/ControllerTest.java
@@ -0,0 +1,61 @@
package jp.toastkid.script;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.fxmisc.richtext.CodeArea;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testfx.framework.junit.ApplicationTest;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
* {@link Controller}'s test.
*
* @author Toast kid
*
*/
public class ControllerTest extends ApplicationTest {

/** Logger. */
private static final Logger LOGGER = LoggerFactory.getLogger(ControllerTest.class);

/**
* UI test.
* @throws InterruptedException
*/
@Test
public void test() throws InterruptedException {
final CodeArea input = (CodeArea) lookup("#scripterInput").query();
final String text = "println 'Hello world.'";
Platform.runLater(() -> {
input.replaceText(text);
assertEquals(text, input.getText());
lookup("#runButton").query().fireEvent(new ActionEvent());
assertEquals("Hello world.", ((CodeArea) lookup("#scripterOutput").query()).getText().trim());
});
}

@Override
public void start(final Stage stage) throws Exception {
try {
final FXMLLoader loader
= new FXMLLoader(getClass().getClassLoader().getResource("scenes/Main.fxml"));
final VBox loaded = (VBox) loader.load();
final Scene scene = new Scene(loaded);
stage.setScene(scene);
} catch (final IOException e) {
LOGGER.error("Scene Reading Error", e);
}
stage.show();
}

}

0 comments on commit ddb4384

Please sign in to comment.