1717import java .nio .file .Paths ;
1818
1919import static org .assertj .core .api .BDDAssertions .then ;
20+ import static org .junit .jupiter .api .Assertions .assertTimeoutPreemptively ;
2021
2122import java .util .Arrays ;
2223
@@ -361,7 +362,7 @@ void completing_level_1_loads_next_level() {
361362 // Simulate the user clicking Next Level to proceed to the next level
362363 // This has to be done before the move to push the box to the target
363364 // because the dialog will wait for user input
364- Timer timer = new Timer (10 , _ -> window .clickNextLevelButton ());
365+ Timer timer = new Timer (100 , _ -> window .clickNextLevelButton ());
365366 timer .setRepeats (false );
366367 SwingUtilities .invokeLater (timer ::start );
367368
@@ -377,6 +378,37 @@ void completing_level_1_loads_next_level() {
377378 .anyMatch (w -> w instanceof SokobanWindow sw && sw .getTitle ().equals ("Level 2" ));
378379 }
379380
381+ @ Test
382+ void no_more_levels_after_completing_level_10 () {
383+ // given - create a test window with the simplified test level
384+ window .dispose ();
385+ window = createTestWindow ("src/test/resources/levels/level10.txt" );
386+
387+ // Simulate the user clicking Next Level to proceed to the next level
388+ // This has to be done before the move to push the box to the target
389+ // because the dialog will wait for user input
390+ Timer timer = new Timer (100 , _ -> window .clickOkButton ());
391+ timer .setRepeats (false );
392+ SwingUtilities .invokeLater (timer ::start );
393+
394+ // When:
395+ // Perform a single move to push the box onto the target and end the level
396+
397+ assertTimeoutPreemptively (
398+ java .time .Duration .ofSeconds (2 ),
399+ () -> pressKey (KeyEvent .VK_RIGHT ),
400+ "Too long to complete the level"
401+ );
402+
403+ then (window .isShowing ())
404+ .as ("Current window is disposed after level completion" )
405+ .isFalse ();
406+
407+ then (Window .getWindows ())
408+ .as ("Contains a visible HomeWindow" )
409+ .anyMatch (w -> w instanceof HomeWindow && w .isShowing ());
410+ }
411+
380412 private void pressKey (int keyCode ) {
381413 KeyEvent keyEvent = new KeyEvent (window ,
382414 KeyEvent .KEY_PRESSED ,
0 commit comments