Fix: radical overhaul of Game UI tests to fix CI pipeline failures
This commit is contained in:
+6
-21
@@ -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 ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents.TaskbarController;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
@@ -17,31 +16,17 @@ class TaskbarControllerSmokeTest {
|
|||||||
private static boolean started = false;
|
private static boolean started = false;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void initJavaFX() throws Exception {
|
static void initJavaFX() {
|
||||||
if (started) {
|
if (started) {
|
||||||
return;
|
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;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -22,25 +22,17 @@ class TaskbarControllerInputValidationTest {
|
|||||||
private static boolean started = false;
|
private static boolean started = false;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void initJavaFX() throws Exception {
|
static void initJavaFX() {
|
||||||
if (started) {
|
if (started) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Platform.startup(
|
Platform.startup(() -> {});
|
||||||
() -> {
|
} catch (IllegalStateException ignored) {
|
||||||
Platform.setImplicitExit(false);
|
// already started
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
// JavaFX already started → CI safe
|
|
||||||
latch.countDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +99,10 @@ class TaskbarControllerInputValidationTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
CountDownLatch fxLatch = new CountDownLatch(1);
|
||||||
|
Platform.runLater(fxLatch::countDown);
|
||||||
|
assertTrue(fxLatch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameState createGameState() {
|
private GameState createGameState() {
|
||||||
@@ -133,6 +129,10 @@ class TaskbarControllerInputValidationTest {
|
|||||||
root.applyCss();
|
root.applyCss();
|
||||||
root.layout();
|
root.layout();
|
||||||
|
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
Platform.runLater(latch::countDown);
|
||||||
|
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
TaskbarController controller = loader.getController();
|
TaskbarController controller = loader.getController();
|
||||||
TextField input = get(controller, "taskbarInput", TextField.class);
|
TextField input = get(controller, "taskbarInput", TextField.class);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user