11package ihm ;
22
33import logic .Controller ;
4- import logic .Warehouse ;
54import org .jspecify .annotations .NullMarked ;
5+ import org .junit .jupiter .api .AfterEach ;
66import org .junit .jupiter .api .BeforeEach ;
77import org .junit .jupiter .api .Test ;
88import org .junit .jupiter .params .ParameterizedTest ;
@@ -30,6 +30,11 @@ void setUp() {
3030 controller = window .getController ();
3131 }
3232
33+ @ AfterEach
34+ void tearDown () {
35+ window .dispose ();
36+ }
37+
3338 /**
3439 * Creates and returns a test window with the default test level.
3540 * This is the happy path setup used by most tests.
@@ -56,14 +61,17 @@ private SokobanWindow createTestWindow(String levelPath) {
5661 @ Test
5762 void window_has_correct_initial_state () {
5863 // then
64+ then (window ).isNotNull ();
5965 then (window .isVisible ()).isTrue ();
66+
67+ // The test level should be treated as a custom level
68+ then (window .getController ().isOnCustomLevel ()).isTrue ();
69+ then (window .getTitle ()).isEqualTo ("Custom level" );
6070 then (window .isResizable ()).isFalse ();
61- then (window .getDefaultCloseOperation ()).isEqualTo (JFrame .EXIT_ON_CLOSE );
6271
63- // Verify the window size is set based on the warehouse
64- Warehouse warehouse = controller .warehouse ;
65- int columns = warehouse .getColumns ();
66- int lines = warehouse .getLines ();
72+ // Verify window size is at least as large as the game content
73+ int columns = controller .warehouse .getColumns ();
74+ int lines = controller .warehouse .getLines ();
6775 int imageWidth = columns * SokobanWindow .IMAGE_SIZE ;
6876 int imageHeight = lines * SokobanWindow .IMAGE_SIZE ;
6977
@@ -72,6 +80,20 @@ void window_has_correct_initial_state() {
7280 then (window .getSize ().height ).isGreaterThanOrEqualTo (imageHeight );
7381 }
7482
83+ @ Test
84+ void window_title_reflects_standard_level () {
85+ // given - a standard level (level 1)
86+ String levelPath = "levels/level1.txt" ;
87+
88+ // when - creating window with standard level using helper method
89+ window = createTestWindow (levelPath );
90+
91+ // then - should be a standard level with level number 1
92+ then (window .getController ().isOnCustomLevel ()).isFalse ();
93+ then (window .getController ().getLevel ()).isEqualTo (1 );
94+ then (window .getTitle ()).isEqualTo ("Level 1" );
95+ }
96+
7597 @ Test
7698 void handles_right_direction_key_press () {
7799 // given - initial positions
0 commit comments