| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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 ClassroomRoomTest {
- private GameData context;
- @BeforeEach
- void setUp() {
- context = TestHelpers.buildGameData();
- // Bedroom → Hallway
- context.getMap().setNextRoom(context.getMap().getCurrentRoom().getExit("hallway"));
- context.getMap().commitRoomChange();
- }
- private ClassroomRoom getClassroomRoom() {
- return (ClassroomRoom) context.getMap().getCurrentRoom().getExit("classroom");
- }
- @Test
- void enterWithoutBookReturnsFailed() {
- CommandResult result = getClassroomRoom().onEnter(context);
- assertEquals(CommandState.FAILED, result.getResultState());
- }
- @Test
- void enterWithoutBookAppliesStressPenalty() {
- int stressBefore = context.getPlayer().getStress().getValue();
- getClassroomRoom().onEnter(context);
- assertEquals(stressBefore + 15, context.getPlayer().getStress().getValue());
- }
- @Test
- void enterWithoutBookCancelsRoomChange() {
- getClassroomRoom().onEnter(context);
- assertFalse(context.getMap().hasPendingRoomChange());
- }
- @Test
- void enterWithBookReturnsSuccess() {
- context.getPlayer().getInventory().Add(new Book(), 1);
- CommandResult result = getClassroomRoom().onEnter(context);
- assertEquals(CommandState.SUCCESS, result.getResultState());
- }
- @Test
- void enterWithBookDoesNotAddStress() {
- context.getPlayer().getInventory().Add(new Book(), 1);
- int stressBefore = context.getPlayer().getStress().getValue();
- getClassroomRoom().onEnter(context);
- assertEquals(stressBefore, context.getPlayer().getStress().getValue());
- }
- @Test
- void classroomHasSleepCommand() {
- assertTrue(getClassroomRoom().getAllowedCommands().contains("sleep"));
- }
- @Test
- void classroomHasStickyNote() {
- assertNotNull(getClassroomRoom().getItems().GetByItemCode("sticky_note"));
- }
- }
|