Skip to content

Commit ed98ae5

Browse files
Merge pull request #601 from JordanMartinez/cleanupIntegrationTest
Cleanup integration test
2 parents 20f2ce6 + b105dc4 commit ed98ae5

22 files changed

Lines changed: 1135 additions & 978 deletions

richtextfx/build.gradle

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ testSets {
2020

2121
check.dependsOn integrationTest
2222
integrationTest.mustRunAfter test
23-
integrationTest.systemProperty "testfx.robot", "glass"
2423
if (gradle.gradleVersion.substring(0, 1) >= "4") {
2524
// required for Gradle 4 to see custom integrationTest test suite
2625
integrationTest.testClassesDirs = sourceSets.integrationTest.output.classesDirs
@@ -106,6 +105,35 @@ test {
106105
}
107106
}
108107

108+
integrationTest {
109+
testLogging {
110+
// Fancy formatting from http://stackoverflow.com/a/36130467/3634630
111+
// set options for log level LIFECYCLE
112+
events TestLogEvent.PASSED, TestLogEvent.SKIPPED,
113+
TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT
114+
showExceptions true
115+
exceptionFormat TestExceptionFormat.FULL
116+
showCauses true
117+
showStackTraces true
118+
119+
// set options for log level DEBUG and INFO
120+
debug {
121+
events TestLogEvent.STARTED, TestLogEvent.PASSED,
122+
TestLogEvent.SKIPPED, TestLogEvent.FAILED,
123+
TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
124+
}
125+
info.events = debug.events
126+
afterSuite { desc, result ->
127+
if (!desc.parent) { // will match the outermost suite
128+
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
129+
def startItem = '| ', endItem = ' |'
130+
def repeatLength = startItem.length() + output.length() + endItem.length()
131+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
132+
}
133+
}
134+
}
135+
}
136+
109137
task javadocJar(type: Jar, dependsOn: javadoc) {
110138
classifier = 'javadoc'
111139
from 'build/docs/javadoc'
Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,21 @@
11
package org.fxmisc.richtext;
22

33
import javafx.geometry.Pos;
4-
import javafx.scene.Node;
54
import javafx.scene.Scene;
6-
import javafx.scene.control.ContextMenu;
7-
import javafx.scene.control.MenuItem;
85
import javafx.scene.input.MouseButton;
96
import javafx.stage.Stage;
10-
import javafx.stage.Window;
117
import org.testfx.api.FxRobotInterface;
12-
import org.testfx.framework.junit.ApplicationTest;
138
import org.testfx.service.query.PointQuery;
149

15-
import static org.junit.Assume.assumeTrue;
16-
1710
/**
1811
* TestFX tests should subclass this if it needs to run tests on a simple area. Any view-related API needs to be
1912
* wrapped in a {@link #interact(Runnable)} call, but model API does not need to be wrapped in it.
2013
*/
21-
public class InlineCssTextAreaAppTest extends ApplicationTest {
22-
23-
static {
24-
String osName = System.getProperty("os.name").toLowerCase();
25-
26-
isWindows = osName.startsWith("win");
27-
isMac = osName.startsWith("mac");
28-
isLinux = osName.startsWith("linux");
29-
}
30-
31-
public static final boolean isWindows;
32-
public static final boolean isMac;
33-
public static final boolean isLinux;
14+
public class InlineCssTextAreaAppTest extends RichTextFXTestBase {
3415

3516
public Stage stage;
3617
public Scene scene;
3718
public InlineCssTextArea area;
38-
public ContextMenu menu;
3919

4020
@Override
4121
public void start(Stage stage) throws Exception {
@@ -48,28 +28,10 @@ public void start(Stage stage) throws Exception {
4828
stage.setHeight(400);
4929
stage.show();
5030

51-
menu = new ContextMenu(new MenuItem("A menu item"));
52-
area.setContextMenu(menu);
53-
// offset needs to be 5+ to prevent test failures
54-
area.setContextMenuXOffset(30);
55-
area.setContextMenuYOffset(30);
56-
5731
// so tests don't need to do this themselves
5832
area.requestFocus();
5933
}
6034

61-
public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) {
62-
return point(scene).atPosition(pos).atOffset(xOffset, yOffset);
63-
}
64-
65-
public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) {
66-
return point(window).atPosition(pos).atOffset(xOffset, yOffset);
67-
}
68-
69-
public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) {
70-
return point(node).atPosition(pos).atOffset(xOffset, yOffset);
71-
}
72-
7335
public final PointQuery position(Pos pos, double xOffset, double yOffset) {
7436
return position(area, pos, xOffset, yOffset);
7537
}
@@ -98,51 +60,4 @@ public final FxRobotInterface rightClickOnFirstLine() {
9860
return clickOnFirstLine(MouseButton.SECONDARY);
9961
}
10062

101-
/**
102-
* If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
103-
* this in @Test will skip just that test method
104-
*/
105-
public final void run_only_on_windows() {
106-
assumeTrue(isWindows);
107-
}
108-
109-
/**
110-
* If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
111-
* this in @Test will skip just that test method
112-
*/
113-
public final void run_only_on_linux() {
114-
assumeTrue(isLinux);
115-
}
116-
117-
/**
118-
* If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
119-
* this in @Test will skip just that test method
120-
*/
121-
public final void run_only_on_mac() {
122-
assumeTrue(isMac);
123-
}
124-
125-
/**
126-
* If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
127-
* this in @Test will skip just that test method
128-
*/
129-
public final void skip_if_on_windows() {
130-
assumeTrue(!isWindows);
131-
}
132-
133-
/**
134-
* If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
135-
* this in @Test will skip just that test method
136-
*/
137-
public final void skip_if_on_linux() {
138-
assumeTrue(!isLinux);
139-
}
140-
141-
/**
142-
* If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
143-
* this in @Test will skip just that test method
144-
*/
145-
public final void skip_if_on_mac() {
146-
assumeTrue(!isMac);
147-
}
14863
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package org.fxmisc.richtext;
2+
3+
import javafx.geometry.Pos;
4+
import javafx.scene.Node;
5+
import javafx.scene.Scene;
6+
import javafx.stage.Window;
7+
import org.testfx.framework.junit.ApplicationTest;
8+
import org.testfx.service.query.PointQuery;
9+
10+
import static org.junit.Assume.assumeTrue;
11+
12+
/**
13+
* Provides useful static fields and helper methods for RichTextFX integration tests.
14+
*
15+
* <ul>
16+
* <li>
17+
* Helps determine which OS is currently running the test and whether to run/skip a test on that OS
18+
* </li>
19+
* <li>
20+
* Getting the position o
21+
* </li>
22+
* </ul>
23+
*/
24+
public abstract class RichTextFXTestBase extends ApplicationTest {
25+
26+
static {
27+
String osName = System.getProperty("os.name").toLowerCase();
28+
29+
IS_WINDOWS = osName.startsWith("win");
30+
IS_MAC = osName.startsWith("mac");
31+
IS_LINUX = osName.startsWith("linux");
32+
}
33+
34+
/* *********************************************** *
35+
* OS-RELATED
36+
* *********************************************** */
37+
38+
public static final boolean IS_WINDOWS;
39+
public static final boolean IS_MAC;
40+
public static final boolean IS_LINUX;
41+
42+
/**
43+
* If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
44+
* this in @Test will skip just that test method
45+
*/
46+
public final void run_only_on_windows() {
47+
assumeTrue(IS_WINDOWS);
48+
}
49+
50+
/**
51+
* If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
52+
* this in @Test will skip just that test method
53+
*/
54+
public final void run_only_on_linux() {
55+
assumeTrue(IS_LINUX);
56+
}
57+
58+
/**
59+
* If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
60+
* this in @Test will skip just that test method
61+
*/
62+
public final void run_only_on_mac() {
63+
assumeTrue(IS_MAC);
64+
}
65+
66+
/**
67+
* If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
68+
* this in @Test will skip just that test method
69+
*/
70+
public final void skip_if_on_windows() {
71+
assumeTrue(!IS_WINDOWS);
72+
}
73+
74+
/**
75+
* If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
76+
* this in @Test will skip just that test method
77+
*/
78+
public final void skip_if_on_linux() {
79+
assumeTrue(!IS_LINUX);
80+
}
81+
82+
/**
83+
* If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
84+
* this in @Test will skip just that test method
85+
*/
86+
public final void skip_if_on_mac() {
87+
assumeTrue(!IS_MAC);
88+
}
89+
90+
/* *********************************************** *
91+
* Position-Related
92+
* *********************************************** */
93+
94+
/**
95+
* Returns a specific position in the scene, starting at {@code pos} and offsetting from that place by
96+
* {@code xOffset} and {@code yOffset}
97+
*/
98+
public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) {
99+
return point(scene).atPosition(pos).atOffset(xOffset, yOffset);
100+
}
101+
102+
/**
103+
* Returns a specific position in the window, starting at {@code pos} and offsetting from that place by
104+
* {@code xOffset} and {@code yOffset}
105+
*/
106+
public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) {
107+
return point(window).atPosition(pos).atOffset(xOffset, yOffset);
108+
}
109+
110+
/**
111+
* Returns a specific position in the node, starting at {@code pos} and offsetting from that place by
112+
* {@code xOffset} and {@code yOffset}
113+
*/
114+
public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) {
115+
return point(node).atPosition(pos).atOffset(xOffset, yOffset);
116+
}
117+
}

richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CaretTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@
1111

1212
public class CaretTests extends InlineCssTextAreaAppTest {
1313

14+
private static final String FIFTY_PARS_OF_TEXT;
15+
16+
static {
17+
StringBuilder sb = new StringBuilder();
18+
for (int i = 0; i < 50; i++) {
19+
sb.append(i).append("\n");
20+
}
21+
sb.append(50);
22+
FIFTY_PARS_OF_TEXT = sb.toString();
23+
}
24+
1425
@Override
1526
public void start(Stage stage) throws Exception {
1627
super.start(stage);
1728

1829
// insure caret is always visible
1930
area.setShowCaret(Caret.CaretVisibility.ON);
20-
21-
StringBuilder sb = new StringBuilder();
22-
for (int i = 0; i < 50; i++) {
23-
sb.append(i).append("\n");
24-
}
25-
area.replaceText(sb.toString());
31+
area.replaceText(FIFTY_PARS_OF_TEXT);
2632
area.moveTo(0);
2733
area.showParagraphAtTop(0);
2834
}
2935

3036
@Test
31-
public void testMoveCaretAndFollowIt() {
37+
public void caret_bounds_are_present_after_moving_caret_and_following_it() {
3238
assertTrue(area.getCaretBounds().isPresent());
3339

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

4551
@Test
46-
public void testMoveCaretWithoutFollowingIt() {
52+
public void caret_bounds_are_absent_after_moving_caret_without_following_it() {
4753
assertTrue(area.getCaretBounds().isPresent());
4854

4955
// move caret outside of viewport

richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CharacterBoundsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void start(Stage stage) throws Exception {
1616
}
1717

1818
@Test
19-
public void selectionBoundsUnchangedWhenCallGetCharacterBounds() {
19+
public void selection_bounds_are_unchanged_when_call_getCharacterBounds() {
2020
area.selectAll();
2121
Bounds bounds = area.getSelectionBounds().get();
2222

richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)