diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameControllerUiTest.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameControllerUiTest.java index d623871..e5e1d04 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameControllerUiTest.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/CasinoGameControllerUiTest.java @@ -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; } diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java index 494c8f5..41cc567 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java @@ -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);