package cz.davza.studentadventure.integration; import cz.davza.studentadventure.Items.Book; import cz.davza.studentadventure.TestHelpers; import cz.davza.studentadventure.TestHelpers.CapturingOutputSink; import cz.davza.studentadventure.enums.CommandState; import cz.davza.studentadventure.objects.CommandResult; import cz.davza.studentadventure.objects.Game; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class GameIntegrationTest { private Game game; private CapturingOutputSink sink; @BeforeEach void setUp() { sink = new CapturingOutputSink(); game = new Game(sink); } @Test void quitReturnsGameOver() { CommandResult result = game.sendCommand("quit"); assertEquals(CommandState.GAME_OVER, result.getResultState()); } @Test void commandAfterQuitIsRejected() { game.sendCommand("quit"); CommandResult result = game.sendCommand("study 1"); assertEquals(CommandState.GAME_OVER, result.getResultState()); } @Test void unknownCommandReturnsFailed() { CommandResult result = game.sendCommand("fly"); assertEquals(CommandState.FAILED, result.getResultState()); } @Test void walkToHallwayChangesRoom() { CommandResult result = game.sendCommand("walk hallway"); assertEquals(CommandState.ROOM_CHANGED, result.getResultState()); assertEquals("hallway", game.getContext().getMap().getCurrentRoom().getExitCode()); } @Test void walkToInvalidRoomFails() { CommandResult result = game.sendCommand("walk narnia"); assertEquals(CommandState.FAILED, result.getResultState()); } @Test void studyInBedroomWorks() { int intBefore = game.getContext().getPlayer().getIntelligence().getValue(); game.sendCommand("study 1"); assertEquals(intBefore + 5, game.getContext().getPlayer().getIntelligence().getValue()); } @Test void deadlinePassedCausesGameOver() { // Advance time past day 7, 09:00 for (int i = 0; i < 7; i++) game.getContext().getTime().advanceToNextMorning(); game.getContext().getTime().advanceHours(2); // Any command should trigger the deadline check CommandResult result = game.sendCommand("stats"); assertEquals(CommandState.GAME_OVER, result.getResultState()); } @Test void stressAt100CausesGameOver() { game.getContext().getPlayer().getStress().increase(100); CommandResult result = game.sendCommand("stats"); assertEquals(CommandState.GAME_OVER, result.getResultState()); } @Test void fullWalkSequenceBedroomToHallway() { game.sendCommand("walk hallway"); assertEquals("hallway", game.getContext().getMap().getCurrentRoom().getExitCode()); } @Test void enteringClassroomWithoutBookFails() { game.sendCommand("walk hallway"); CommandResult result = game.sendCommand("walk classroom"); assertEquals(CommandState.FAILED, result.getResultState()); // should still be in hallway assertEquals("hallway", game.getContext().getMap().getCurrentRoom().getExitCode()); } @Test void fullPathToExamAndPass() { // Max out intelligence, walk to exam room, enter with correct ID, take exam game.getContext().getPlayer().getIntelligence().increase(100); game.getContext().getPlayer().getInventory().Add(new Book(), 1); game.sendCommand("walk hallway"); game.sendCommand("walk classroom"); game.sendCommand("walk examroom"); // triggers ID prompt String studentId = game.getContext().getPlayer().getId(); game.sendCommand(studentId); // enter exam room CommandResult result = game.sendCommand("takeexam"); assertEquals(CommandState.GAME_WIN, result.getResultState()); } @Test void buyAndConsumeEnergyDrinkFlow() { // Walk to shop: hallway → studyroom → computerlab → shop game.sendCommand("walk hallway"); game.sendCommand("walk studyroom"); game.sendCommand("walk computerlab"); game.sendCommand("walk shop"); game.getContext().getPlayer().getEnergy().decrease(50); int energyBefore = game.getContext().getPlayer().getEnergy().getValue(); game.sendCommand("buy energy_drink"); game.sendCommand("consume energy_drink"); assertTrue(game.getContext().getPlayer().getEnergy().getValue() > energyBefore); } @Test void computerInteractionFullFlow() { game.sendCommand("walk hallway"); game.sendCommand("walk studyroom"); game.sendCommand("walk computerlab"); game.sendCommand("interact computer"); // → asks for password game.sendCommand("wrongpassword"); // → wrong game.sendCommand("java123"); // → correct, now active int intBefore = game.getContext().getPlayer().getIntelligence().getValue(); game.sendCommand("study 1"); // study while at computer assertEquals(intBefore + 5, game.getContext().getPlayer().getIntelligence().getValue()); CommandResult result = game.sendCommand("exit"); // leave computer assertEquals(CommandState.ACTION_RESUMED, result.getResultState()); } }