Skip to content

Commit 03df1f3

Browse files
committed
testing
1 parent dc6cbd9 commit 03df1f3

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
55
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
66
import org.junit.jupiter.api.Test;
7-
import org.awaitility.Awaitility;
87
import org.testfx.framework.junit5.ApplicationTest;
98
import javafx.application.Platform;
109

11-
import java.time.Duration;
10+
import java.util.concurrent.CountDownLatch;
11+
import java.util.concurrent.TimeUnit;
1212

1313
import static com.github.tomakehurst.wiremock.client.WireMock.*;
1414
import static org.assertj.core.api.Assertions.assertThat;
15+
import static org.assertj.core.api.Assertions.fail;
1516

1617
@WireMockTest
1718
class ChatModelTest extends ApplicationTest {
@@ -45,7 +46,7 @@ void sendMessageToFakeServer_viaNtfyConnectionImpl(WireMockRuntimeInfo wmRunTime
4546

4647

4748
@Test
48-
void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo wmRunTimeInfo) {
49+
void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo wmRunTimeInfo) throws InterruptedException {
4950
var conImp = new NtfyConnectionImpl("http://localhost:" + wmRunTimeInfo.getHttpPort());
5051

5152
String expectedMessage = "Async Data Received";
@@ -59,15 +60,22 @@ void checkReceivedMessagesAfterSendingAMessageToAFakeServer(WireMockRuntimeInfo
5960
var model = new ChatModel(conImp);
6061
model.startReceiving();
6162

62-
Awaitility.await()
63-
.atMost(Duration.ofSeconds(4))
64-
.pollInterval(Duration.ofMillis(100))
65-
.untilAsserted(() -> {
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-
});
71-
});
63+
CountDownLatch latch = new CountDownLatch(1);
64+
65+
Platform.runLater(() -> {
66+
try {
67+
assertThat(model.getMessages()).isNotEmpty();
68+
assertThat(model.getMessages().getLast().content()).isEqualTo(expectedMessage);
69+
assertThat(model.getMessages().getLast().timestamp()).isEqualTo(expectedTimestamp);
70+
} catch (AssertionError e) {
71+
fail("Assertion failed inside Platform.runLater: " + e.getMessage());
72+
} finally {
73+
latch.countDown();
74+
}
75+
});
76+
77+
assertThat(latch.await(5, TimeUnit.SECONDS))
78+
.as("Timed out waiting for JavaFX thread to execute assertions.")
79+
.isTrue();
7280
}
7381
}

0 commit comments

Comments
 (0)