| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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());
- }
- }
|