Skip to content

Commit dc6cbd9

Browse files
committed
simpler tests
1 parent dbcb3bf commit dc6cbd9

2 files changed

Lines changed: 33 additions & 61 deletions

File tree

pom.xml

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@
1515
<assertj.core.version>3.27.6</assertj.core.version>
1616
<mockito.version>5.20.0</mockito.version>
1717
<javafx.version>25</javafx.version>
18-
<surefire.version>3.2.5</surefire.version>
1918
</properties>
2019
<dependencies>
21-
<dependency>
22-
<groupId>org.junit.jupiter</groupId>
23-
<artifactId>junit-jupiter</artifactId>
24-
<version>${junit.jupiter.version}</version>
25-
<scope>test</scope>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.assertj</groupId>
29-
<artifactId>assertj-core</artifactId>
30-
<version>${assertj.core.version}</version>
31-
<scope>test</scope>
32-
</dependency>
33-
<dependency>
34-
<groupId>org.mockito</groupId>
35-
<artifactId>mockito-junit-jupiter</artifactId>
36-
<version>${mockito.version}</version>
37-
<scope>test</scope>
38-
</dependency>
3920
<dependency>
4021
<groupId>org.openjfx</groupId>
4122
<artifactId>javafx-controls</artifactId>
@@ -56,15 +37,40 @@
5637
<artifactId>jackson-databind</artifactId>
5738
<version>3.0.1</version>
5839
</dependency>
40+
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter</artifactId>
44+
<version>${junit.jupiter.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.assertj</groupId>
49+
<artifactId>assertj-core</artifactId>
50+
<version>${assertj.core.version}</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.mockito</groupId>
55+
<artifactId>mockito-junit-jupiter</artifactId>
56+
<version>${mockito.version}</version>
57+
<scope>test</scope>
58+
</dependency>
5959
<dependency>
6060
<groupId>org.wiremock</groupId>
6161
<artifactId>wiremock</artifactId>
6262
<version>4.0.0-beta.15</version>
6363
<scope>test</scope>
6464
</dependency>
65+
<dependency>
66+
<groupId>org.awaitility</groupId>
67+
<artifactId>awaitility</artifactId>
68+
<version>4.3.0</version>
69+
<scope>test</scope>
70+
</dependency>
6571
<dependency>
6672
<groupId>org.testfx</groupId>
67-
<artifactId>testfx-core</artifactId>
73+
<artifactId>testfx-junit5</artifactId>
6874
<version>4.0.16-alpha</version>
6975
<scope>test</scope>
7076
</dependency>
@@ -74,30 +80,9 @@
7480
<version>2.0.12</version>
7581
<scope>test</scope>
7682
</dependency>
77-
<dependency>
78-
<groupId>org.awaitility</groupId>
79-
<artifactId>awaitility</artifactId>
80-
<version>4.3.0</version>
81-
<scope>test</scope>
82-
</dependency>
8383
</dependencies>
8484
<build>
8585
<plugins>
86-
<plugin>
87-
<groupId>org.apache.maven.plugins</groupId>
88-
<artifactId>maven-surefire-plugin</artifactId>
89-
<version>${surefire.version}</version>
90-
<configuration>
91-
<argLine>
92-
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
93-
--add-exports javafx.base/com.sun.javafx.runtime=ALL-UNNAMED
94-
-Djava.awt.headless=true
95-
-Dprism.order=sw
96-
-Dtestfx.robot=glass
97-
-Dtestfx.headless=true
98-
</argLine>
99-
</configuration>
100-
</plugin>
10186
<plugin>
10287
<groupId>org.openjfx</groupId>
10388
<artifactId>javafx-maven-plugin</artifactId>

src/test/java/com/example/ChatModelTest.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
package com.example;
22

3-
43
import com.github.tomakehurst.wiremock.client.WireMock;
54
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
65
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
7-
import org.junit.jupiter.api.BeforeAll;
8-
import org.junit.jupiter.api.DisplayName;
96
import org.junit.jupiter.api.Test;
107
import org.awaitility.Awaitility;
8+
import org.testfx.framework.junit5.ApplicationTest;
119
import javafx.application.Platform;
1210

1311
import java.time.Duration;
1412

1513
import static com.github.tomakehurst.wiremock.client.WireMock.*;
1614
import static org.assertj.core.api.Assertions.assertThat;
1715

18-
1916
@WireMockTest
20-
class ChatModelTest {
21-
22-
@BeforeAll
23-
static void initJavaFX() {
24-
try {
25-
Platform.startup(() -> {});
26-
Platform.setImplicitExit(false);
27-
} catch (IllegalStateException e) {
28-
}
29-
}
30-
17+
class ChatModelTest extends ApplicationTest {
3118

3219
@Test
3320
void sendMessageCallsConnectionWithMessagesToSend() {
@@ -76,11 +63,11 @@ void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo
7663
.atMost(Duration.ofSeconds(4))
7764
.pollInterval(Duration.ofMillis(100))
7865
.untilAsserted(() -> {
79-
assertThat(model.getMessages()).isNotEmpty();
80-
81-
assertThat(model.getMessages().getLast().content()).isEqualTo(expectedMessage);
82-
83-
assertThat(model.getMessages().getLast().timestamp()).isEqualTo(expectedTimestamp);
66+
Platform.runLater(() -> {
67+
assertThat(model.getMessages()).isNotEmpty();
68+
assertThat(model.getMessages().getLast().content()).isEqualTo(expectedMessage);
69+
assertThat(model.getMessages().getLast().timestamp()).isEqualTo(expectedTimestamp);
70+
});
8471
});
8572
}
8673
}

0 commit comments

Comments
 (0)