test(menu): cover pickSlot selection and Back sentinel
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user