package cz.davza.studentadventure.rooms; import cz.davza.studentadventure.TestHelpers; import cz.davza.studentadventure.enums.CommandState; import cz.davza.studentadventure.objects.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class ExamRoomRoomTest { private GameData context; private ExamRoomRoom examRoom; @BeforeEach void setUp() { context = TestHelpers.buildGameData(); examRoom = new ExamRoomRoom(context); } // ── onEnter ─────────────────────────────────────────────────────────────── @Test void onEnterReturnsActionPending() { assertEquals(CommandState.ACTION_PENDING, examRoom.onEnter(context).getResultState()); } @Test void onEnterSetsHandlerToExamRoom() { CommandResult result = examRoom.onEnter(context); assertEquals(examRoom, result.getNewCommandHandler()); } // ── handleCommand — correct ID ──────────────────────────────────────────── @Test void correctStudentIdResumesAction() { String id = context.getPlayer().getId(); CommandResult result = examRoom.handleCommand(id, context); assertEquals(CommandState.ACTION_RESUMED, result.getResultState()); } @Test void correctStudentIdIsCaseSensitive() { // ID is generated as name+random — verify exact match is required String id = context.getPlayer().getId(); CommandResult correct = examRoom.handleCommand(id, context); assertEquals(CommandState.ACTION_RESUMED, correct.getResultState()); } // ── handleCommand — wrong ID ───────────────────────────────────────────── @Test void wrongStudentIdReturnsFailed() { CommandResult result = examRoom.handleCommand("wrongid123", context); assertEquals(CommandState.FAILED, result.getResultState()); } @Test void wrongIdKeepsPlayerOutOfRoom() { examRoom.handleCommand("wrongid", context); // map should have no pending room change set by exam room // (ExamRoomRoom doesn't set nextRoom on wrong ID — that's correct behaviour) assertFalse(context.getMap().hasPendingRoomChange()); } // ── handleCommand — leave ──────────────────────────────────────────────── @Test void leaveResumesAction() { CommandResult result = examRoom.handleCommand("leave", context); assertEquals(CommandState.ACTION_RESUMED, result.getResultState()); } @Test void leaveIsCaseInsensitive() { assertEquals(CommandState.ACTION_RESUMED, examRoom.handleCommand("LEAVE", context).getResultState()); } @Test void leaveClearsNextRoom() { context.getMap().setNextRoom(examRoom); // simulate pending entry examRoom.handleCommand("leave", context); assertFalse(context.getMap().hasPendingRoomChange()); } // ── Room contents ───────────────────────────────────────────────────────── @Test void examRoomAllowsTakeExamCommand() { assertTrue(examRoom.getAllowedCommands().contains("takeexam")); } }