| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package cz.davza.studentadventure.rooms;
- import cz.davza.studentadventure.Items.Book;
- import cz.davza.studentadventure.TestHelpers;
- import cz.davza.studentadventure.enums.CommandState;
- import cz.davza.studentadventure.objects.CommandResult;
- import cz.davza.studentadventure.objects.GameData;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.*;
- class ExamRoomTest {
- private GameData context;
- private ExamRoomRoom examRoom;
- @BeforeEach
- void setUp() {
- context = TestHelpers.buildGameData();
- // Navigate to exam room entrance: bedroom → hallway → classroom → examroom
- context.getPlayer().getInventory().Add(new Book(), 1);
- context.getMap().setNextRoom(context.getMap().getCurrentRoom().getExit("hallway"));
- context.getMap().commitRoomChange();
- context.getMap().setNextRoom(context.getMap().getCurrentRoom().getExit("classroom"));
- context.getMap().commitRoomChange();
- examRoom = (ExamRoomRoom) context.getMap().getCurrentRoom().getExit("examroom");
- }
- @Test
- void onEnterReturnsActionPending() {
- CommandResult result = examRoom.onEnter(context);
- assertEquals(CommandState.ACTION_PENDING, result.getResultState());
- }
- @Test
- void onEnterSetsExamRoomAsHandler() {
- CommandResult result = examRoom.onEnter(context);
- assertEquals(examRoom, result.getNewCommandHandler());
- }
- @Test
- void correctIdAllowsEntry() {
- examRoom.onEnter(context);
- String correctId = context.getPlayer().getId();
- CommandResult result = examRoom.handleCommand(correctId, context);
- assertEquals(CommandState.ACTION_RESUMED, result.getResultState());
- }
- @Test
- void wrongIdReturnsFailed() {
- examRoom.onEnter(context);
- CommandResult result = examRoom.handleCommand("wrongid999", context);
- assertEquals(CommandState.FAILED, result.getResultState());
- }
- @Test
- void leaveCommandCancelsEntry() {
- examRoom.onEnter(context);
- CommandResult result = examRoom.handleCommand("leave", context);
- assertEquals(CommandState.ACTION_RESUMED, result.getResultState());
- }
- @Test
- void leaveCommandCancelsRoomChange() {
- context.getMap().setNextRoom(examRoom);
- examRoom.onEnter(context);
- examRoom.handleCommand("leave", context);
- assertNull(context.getMap().getNextRoom());
- }
- @Test
- void idCheckIsCaseInsensitive() {
- examRoom.onEnter(context);
- String id = context.getPlayer().getId();
- CommandResult result = examRoom.handleCommand(id.toUpperCase(), context);
- assertEquals(CommandState.ACTION_RESUMED, result.getResultState());
- }
- @Test
- void examRoomHasTakeExamCommand() {
- assertTrue(examRoom.getAllowedCommands().contains("takeexam"));
- }
- }
|