From e4238e45533fd329a5358a1f5efbb5358e4fce18 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 1 Jun 2026 15:03:18 +0200 Subject: [PATCH] test(menu): cover pickSlot selection and Back sentinel Co-Authored-By: Claude Sonnet 4.6 --- .../thb/jeanluc/adventure/menu/MenuTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/menu/MenuTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/menu/MenuTest.java index 40419cf..3088e3b 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/menu/MenuTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/menu/MenuTest.java @@ -2,8 +2,11 @@ package thb.jeanluc.adventure.menu; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import thb.jeanluc.adventure.game.GameSession; import thb.jeanluc.adventure.io.TestIO; +import thb.jeanluc.adventure.loader.WorldLoader; import thb.jeanluc.adventure.save.SaveService; +import thb.jeanluc.adventure.save.SaveSlotInfo; import thb.jeanluc.adventure.save.Settings; import thb.jeanluc.adventure.save.SettingsStore; import thb.jeanluc.adventure.io.ConsoleIO; @@ -36,6 +39,28 @@ class MenuTest { assertThat(io.allOutput()).contains("No saved games"); } + private void saveSlot(Path dir, String name) { + var r = new WorldLoader().load(); + new SaveService(dir).save(new GameSession(r.world(), r.player(), name)); + } + + @Test + void pickSlotReturnsChosenSlot(@TempDir Path dir) { + saveSlot(dir, "Alpha"); + TestIO io = new TestIO().enqueue("1"); + SaveSlotInfo result = MainMenu.pickSlot(io, new SaveService(dir)); + assertThat(result).isNotNull(); + assertThat(result.slotName()).isEqualTo("Alpha"); + } + + @Test + void pickSlotReturnsNullOnBack(@TempDir Path dir) { + saveSlot(dir, "Alpha"); + // one slot → options are [1: Alpha, 2: Back] + TestIO io = new TestIO().enqueue("2"); + assertThat(MainMenu.pickSlot(io, new SaveService(dir))).isNull(); + } + @Test void settingsMenuTogglesGlyphAndPersists(@TempDir Path dir) { SettingsStore store = new SettingsStore(dir.resolve("settings.json"));