Skip to content

Commit

Permalink
Merge pull request #601 from JordanMartinez/cleanupIntegrationTest
Browse files Browse the repository at this point in the history
Cleanup integration test
  • Loading branch information
JordanMartinez authored Oct 1, 2017
2 parents 20f2ce6 + b105dc4 commit ed98ae5
Show file tree
Hide file tree
Showing 22 changed files with 1,135 additions and 978 deletions.
30 changes: 29 additions & 1 deletion richtextfx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ testSets {

check.dependsOn integrationTest
integrationTest.mustRunAfter test
integrationTest.systemProperty "testfx.robot", "glass"
if (gradle.gradleVersion.substring(0, 1) >= "4") {
// required for Gradle 4 to see custom integrationTest test suite
integrationTest.testClassesDirs = sourceSets.integrationTest.output.classesDirs
Expand Down Expand Up @@ -106,6 +105,35 @@ test {
}
}

integrationTest {
testLogging {
// Fancy formatting from http://stackoverflow.com/a/36130467/3634630
// set options for log level LIFECYCLE
events TestLogEvent.PASSED, TestLogEvent.SKIPPED,
TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT
showExceptions true
exceptionFormat TestExceptionFormat.FULL
showCauses true
showStackTraces true

// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED, TestLogEvent.PASSED,
TestLogEvent.SKIPPED, TestLogEvent.FAILED,
TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
}
info.events = debug.events
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
package org.fxmisc.richtext;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.testfx.api.FxRobotInterface;
import org.testfx.framework.junit.ApplicationTest;
import org.testfx.service.query.PointQuery;

import static org.junit.Assume.assumeTrue;

/**
* TestFX tests should subclass this if it needs to run tests on a simple area. Any view-related API needs to be
* wrapped in a {@link #interact(Runnable)} call, but model API does not need to be wrapped in it.
*/
public class InlineCssTextAreaAppTest extends ApplicationTest {

static {
String osName = System.getProperty("os.name").toLowerCase();

isWindows = osName.startsWith("win");
isMac = osName.startsWith("mac");
isLinux = osName.startsWith("linux");
}

public static final boolean isWindows;
public static final boolean isMac;
public static final boolean isLinux;
public class InlineCssTextAreaAppTest extends RichTextFXTestBase {

public Stage stage;
public Scene scene;
public InlineCssTextArea area;
public ContextMenu menu;

@Override
public void start(Stage stage) throws Exception {
Expand All @@ -48,28 +28,10 @@ public void start(Stage stage) throws Exception {
stage.setHeight(400);
stage.show();

menu = new ContextMenu(new MenuItem("A menu item"));
area.setContextMenu(menu);
// offset needs to be 5+ to prevent test failures
area.setContextMenuXOffset(30);
area.setContextMenuYOffset(30);

// so tests don't need to do this themselves
area.requestFocus();
}

public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) {
return point(scene).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) {
return point(window).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) {
return point(node).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Pos pos, double xOffset, double yOffset) {
return position(area, pos, xOffset, yOffset);
}
Expand Down Expand Up @@ -98,51 +60,4 @@ public final FxRobotInterface rightClickOnFirstLine() {
return clickOnFirstLine(MouseButton.SECONDARY);
}

/**
* If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_windows() {
assumeTrue(isWindows);
}

/**
* If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_linux() {
assumeTrue(isLinux);
}

/**
* If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_mac() {
assumeTrue(isMac);
}

/**
* If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_windows() {
assumeTrue(!isWindows);
}

/**
* If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_linux() {
assumeTrue(!isLinux);
}

/**
* If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_mac() {
assumeTrue(!isMac);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.fxmisc.richtext;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Window;
import org.testfx.framework.junit.ApplicationTest;
import org.testfx.service.query.PointQuery;

import static org.junit.Assume.assumeTrue;

/**
* Provides useful static fields and helper methods for RichTextFX integration tests.
*
* <ul>
* <li>
* Helps determine which OS is currently running the test and whether to run/skip a test on that OS
* </li>
* <li>
* Getting the position o
* </li>
* </ul>
*/
public abstract class RichTextFXTestBase extends ApplicationTest {

static {
String osName = System.getProperty("os.name").toLowerCase();

IS_WINDOWS = osName.startsWith("win");
IS_MAC = osName.startsWith("mac");
IS_LINUX = osName.startsWith("linux");
}

/* *********************************************** *
* OS-RELATED
* *********************************************** */

public static final boolean IS_WINDOWS;
public static final boolean IS_MAC;
public static final boolean IS_LINUX;

/**
* If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_windows() {
assumeTrue(IS_WINDOWS);
}

/**
* If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_linux() {
assumeTrue(IS_LINUX);
}

/**
* If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void run_only_on_mac() {
assumeTrue(IS_MAC);
}

/**
* If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_windows() {
assumeTrue(!IS_WINDOWS);
}

/**
* If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_linux() {
assumeTrue(!IS_LINUX);
}

/**
* If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
* this in @Test will skip just that test method
*/
public final void skip_if_on_mac() {
assumeTrue(!IS_MAC);
}

/* *********************************************** *
* Position-Related
* *********************************************** */

/**
* Returns a specific position in the scene, starting at {@code pos} and offsetting from that place by
* {@code xOffset} and {@code yOffset}
*/
public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) {
return point(scene).atPosition(pos).atOffset(xOffset, yOffset);
}

/**
* Returns a specific position in the window, starting at {@code pos} and offsetting from that place by
* {@code xOffset} and {@code yOffset}
*/
public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) {
return point(window).atPosition(pos).atOffset(xOffset, yOffset);
}

/**
* Returns a specific position in the node, starting at {@code pos} and offsetting from that place by
* {@code xOffset} and {@code yOffset}
*/
public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) {
return point(node).atPosition(pos).atOffset(xOffset, yOffset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@

public class CaretTests extends InlineCssTextAreaAppTest {

private static final String FIFTY_PARS_OF_TEXT;

static {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 50; i++) {
sb.append(i).append("\n");
}
sb.append(50);
FIFTY_PARS_OF_TEXT = sb.toString();
}

@Override
public void start(Stage stage) throws Exception {
super.start(stage);

// insure caret is always visible
area.setShowCaret(Caret.CaretVisibility.ON);

StringBuilder sb = new StringBuilder();
for (int i = 0; i < 50; i++) {
sb.append(i).append("\n");
}
area.replaceText(sb.toString());
area.replaceText(FIFTY_PARS_OF_TEXT);
area.moveTo(0);
area.showParagraphAtTop(0);
}

@Test
public void testMoveCaretAndFollowIt() {
public void caret_bounds_are_present_after_moving_caret_and_following_it() {
assertTrue(area.getCaretBounds().isPresent());

// move caret outside of viewport
Expand All @@ -43,7 +49,7 @@ public void testMoveCaretAndFollowIt() {
}

@Test
public void testMoveCaretWithoutFollowingIt() {
public void caret_bounds_are_absent_after_moving_caret_without_following_it() {
assertTrue(area.getCaretBounds().isPresent());

// move caret outside of viewport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void start(Stage stage) throws Exception {
}

@Test
public void selectionBoundsUnchangedWhenCallGetCharacterBounds() {
public void selection_bounds_are_unchanged_when_call_getCharacterBounds() {
area.selectAll();
Bounds bounds = area.getSelectionBounds().get();

Expand Down

This file was deleted.

Loading

0 comments on commit ed98ae5

Please sign in to comment.