77import java .util .concurrent .TimeUnit ;
88import java .util .concurrent .atomic .AtomicReference ;
99
10- import org .junit .jupiter .api .AfterAll ;
1110import org .junit .jupiter .api .AssertionFailureBuilder ;
1211import org .junit .jupiter .api .BeforeAll ;
1312import org .junit .jupiter .api .Test ;
13+ import org .junit .jupiter .api .Timeout ;
1414
1515import javafx .animation .Animation ;
1616import javafx .application .Platform ;
@@ -21,20 +21,21 @@ class KeyButtonTest {
2121
2222 @ BeforeAll
2323 static void initToolkit () throws Exception {
24- // Initialize JavaFX toolkit
25- var latch = new CountDownLatch (1 );
26- Platform .startup (latch ::countDown );
27- if (!latch .await (3 , TimeUnit .SECONDS )) {
28- throw new IllegalStateException ("JavaFX toolkit failed to initialize" );
24+ // Ensure headless property is set early in CI via JAVA_TOOL_OPTIONS; this is
25+ // just in case.
26+ System .setProperty ("java.awt.headless" , System .getProperty ("java.awt.headless" , "true" ));
27+
28+ // Initialize JavaFX toolkit (safe if already started)
29+ try {
30+ Platform .startup (() -> {
31+ /* no-op */ });
32+ } catch (IllegalStateException ex ) {
33+ // toolkit already started
2934 }
3035 }
3136
32- @ AfterAll
33- static void exitToolkit () throws Exception {
34- Platform .exit ();
35- }
36-
3737 @ Test
38+ @ Timeout (value = 20 , unit = TimeUnit .SECONDS )
3839 void previousTimelineStoppedWhenNewPressed () throws Exception {
3940 var latch = new CountDownLatch (1 );
4041 var exception = new AtomicReference <Throwable >();
0 commit comments