diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Playthrough.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Playthrough.java index 12904787e7dd5b99dadd54759b2615e7ab52edee..0433bdbdf3917141aa0e72c7cb124f69b26fafe0 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Playthrough.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Playthrough.java @@ -70,7 +70,7 @@ public class Playthrough { return; } - if (!currentPassage.hasLinks()) { + if (currentPassage != null && !currentPassage.hasLinks()) { gameState = PlaythroughState.STUCK; } } diff --git a/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlayhtroughTest.java b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlayhtroughTest.java new file mode 100644 index 0000000000000000000000000000000000000000..859a2db43357a58f713374025addd2ec1a4757fd --- /dev/null +++ b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlayhtroughTest.java @@ -0,0 +1,46 @@ +package edu.ntnu.idatt2001.group_30.paths.model; + +import static org.junit.jupiter.api.Assertions.*; + +import edu.ntnu.idatt2001.group_30.paths.model.goals.Goal; +import edu.ntnu.idatt2001.group_30.paths.model.goals.GoldGoal; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class PlaythroughTest { + + private Playthrough playthrough; + Passage openingPassage; + + @BeforeEach + void setUp() { + openingPassage = new Passage("Opening passage", "This is the opening passage"); + Player player = new Player("Player", 10, 20, 30); + Story story = new Story("My story", openingPassage); + List<Goal> goals = List.of(new GoldGoal(50)); + Game game = new Game(player, story, goals); + + playthrough = new Playthrough(game); + } + + @Test + void testBeginPlaythrough() { + PlaythroughState state = playthrough.beginPlaythrough(); + assertEquals(PlaythroughState.STUCK, state); + assertEquals(openingPassage, playthrough.getCurrentPassage()); + } + + @Test + void testMakeTurn() { + playthrough.beginPlaythrough(); + Link link = new Link("Link", "Passage123"); + PlaythroughState state = playthrough.makeTurn(link); + assertEquals(PlaythroughState.STUCK, state); + } + + @Test + void testMakeTurnWithNullLink() { + assertThrows(NullPointerException.class, () -> playthrough.makeTurn(null)); + } +}