Skip to content

Commit 36c2e3f

Browse files
committed
Enable unit tests
1 parent 4636702 commit 36c2e3f

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

Dockerfile_build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apt-get -qq update && apt-get dist-upgrade -y && apt-get install -qq --no-i
1010
&& mkdir code
1111
COPY . /code
1212
WORKDIR /code
13-
RUN mvn package -Dmaven.test.skip=true
13+
RUN mvn package
1414
# ENTRYPOINT java -jar /code/target/javafxlibrary-*-SNAPSHOT-jar-with-dependencies.jar
1515

1616
FROM ubuntu:16.04

Dockerfile_release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN apt-get -qq update && apt-get dist-upgrade -y && apt-get install -qq --no-i
1111
&& mkdir code
1212
RUN wget latest https://github.com/eficode/JavaFXLibrary/releases Source code.zip && unzip
1313
WORKDIR /code
14-
RUN mvn package -Dmaven.test.skip=true
14+
RUN mvn package
1515

1616
FROM ubuntu:16.04
1717
RUN apt-get -qq update && apt-get dist-upgrade -y && apt-get install -qq --no-install-recommends --allow-unauthenticated -y \

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@
322322
<artifactId>testfx-junit</artifactId>
323323
<version>4.0.13-alpha</version>
324324
</dependency>
325+
<dependency>
326+
<groupId>org.testfx</groupId>
327+
<artifactId>openjfx-monocle</artifactId>
328+
<version>8u76-b04</version>
329+
<scope>test</scope>
330+
</dependency>
325331
<dependency>
326332
<groupId>org.robotframework</groupId>
327333
<artifactId>javalib-core</artifactId>

src/test/java/javafxlibrary/TestFxAdapterTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
package javafxlibrary;
1919

20-
import javafx.application.Platform;
2120
import javafxlibrary.utils.TestFxAdapter;
2221
import mockit.Mocked;
2322
import org.junit.Before;
23+
import org.junit.BeforeClass;
2424
import org.testfx.api.FxRobotInterface;
2525

26+
import static junit.framework.TestCase.fail;
27+
2628
public abstract class TestFxAdapterTest {
2729
public FxRobotInterface getRobot() {
2830
return robot;
@@ -31,11 +33,22 @@ public FxRobotInterface getRobot() {
3133
@Mocked
3234
private FxRobotInterface robot;
3335

36+
@BeforeClass
37+
public static void setupTests() {
38+
System.setProperty("testfx.robot", "glass");
39+
System.setProperty("testfx.headless", "true");
40+
System.setProperty("prism.order", "sw");
41+
System.setProperty("prism.text", "t2k");
42+
try {
43+
org.testfx.api.FxToolkit.registerPrimaryStage();
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
fail("Initialization failed");
47+
}
48+
}
49+
3450
@Before
3551
public void initJfxToolkit() {
36-
new javafx.embed.swing.JFXPanel();
3752
TestFxAdapter.setRobot(robot);
38-
Platform.setImplicitExit(false);
3953
}
40-
4154
}

src/test/java/javafxlibrary/utils/HelperFunctionsTests/CallMethodTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package javafxlibrary.utils.HelperFunctionsTests;
22

3-
import javafx.application.Platform;
3+
import javafx.scene.control.Button;
44
import javafx.stage.Stage;
55
import javafxlibrary.TestFxAdapterTest;
66
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
@@ -54,27 +54,20 @@ public void callMethod_InSameThread_WithArgs_NoReturnValue() {
5454

5555
@Test
5656
public void callMethod_InJavaFXThread_WithArgs() {
57-
Stage stage = setupStageInJavaFXThread();
58-
stage.setTitle("Original title");
59-
Platform.runLater(() -> stage.show());
60-
waitForEventsInJavaFXThread();
61-
62-
Object[] arguments = {"Changed Title"};
63-
HelperFunctions.callMethod(stage, "setTitle", arguments, true);
57+
Button button = new Button("Button");
58+
Object[] arguments = {"Changed"};
59+
HelperFunctions.callMethod(button, "setText", arguments, true);
6460
waitForEventsInJavaFXThread();
65-
66-
Assert.assertEquals("Changed Title", stage.getTitle());
67-
Platform.runLater(() -> stage.close());
61+
Assert.assertEquals("Changed", button.getText());
6862
}
6963

7064
@Test
7165
public void callMethod_InJavaFXThread_NoArgs() {
72-
Stage stage = setupStageInJavaFXThread();
73-
Assert.assertFalse(stage.isShowing());
74-
HelperFunctions.callMethod(stage, "show", new Object[]{}, true);
66+
Button button = new Button("Button");
67+
button.setOnAction((e) -> button.setText("Clicked"));
68+
HelperFunctions.callMethod(button, "fire", new Object[]{}, true);
7569
waitForEventsInJavaFXThread();
76-
Assert.assertTrue(stage.isShowing());
77-
Platform.runLater(() -> stage.close());
70+
Assert.assertEquals("Clicked", button.getText());
7871
}
7972

8073
@Test

0 commit comments

Comments
 (0)