Fix: radical overhaul of Game UI tests to fix CI pipeline failures

This commit is contained in:
Julian Kropff
2026-04-26 23:04:45 +02:00
parent 52ad32a100
commit ddb3e221ac
2 changed files with 18 additions and 33 deletions
@@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents.TaskbarController;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@@ -17,31 +16,17 @@ class TaskbarControllerSmokeTest {
private static boolean started = false;
@BeforeAll
static void initJavaFX() throws Exception {
static void initJavaFX() {
if (started) {
return;
}
CountDownLatch latch = new CountDownLatch(1);
try {
Platform.startup(() -> {});
} catch (IllegalStateException ignored) {
// already started
}
Thread t =
new Thread(
() -> {
try {
Platform.startup(
() -> {
Platform.setImplicitExit(false);
latch.countDown();
});
} catch (IllegalStateException ignored) {
latch.countDown();
}
});
t.setDaemon(true);
t.start();
latch.await();
started = true;
}
@@ -22,25 +22,17 @@ class TaskbarControllerInputValidationTest {
private static boolean started = false;
@BeforeAll
static void initJavaFX() throws Exception {
static void initJavaFX() {
if (started) {
return;
}
CountDownLatch latch = new CountDownLatch(1);
try {
Platform.startup(
() -> {
Platform.setImplicitExit(false);
latch.countDown();
});
} catch (IllegalStateException e) {
// JavaFX already started → CI safe
latch.countDown();
Platform.startup(() -> {});
} catch (IllegalStateException ignored) {
// already started
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
started = true;
}
@@ -107,6 +99,10 @@ class TaskbarControllerInputValidationTest {
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
CountDownLatch fxLatch = new CountDownLatch(1);
Platform.runLater(fxLatch::countDown);
assertTrue(fxLatch.await(5, TimeUnit.SECONDS));
}
private GameState createGameState() {
@@ -133,6 +129,10 @@ class TaskbarControllerInputValidationTest {
root.applyCss();
root.layout();
CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(latch::countDown);
assertTrue(latch.await(5, TimeUnit.SECONDS));
TaskbarController controller = loader.getController();
TextField input = get(controller, "taskbarInput", TextField.class);