From e6736910fb35b7b2cfc42c6cac41a6e7ec7ca218 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 25 May 2026 19:50:37 +0200 Subject: [PATCH] Create SaveGameTest.java --- .../g40/mappe/model/SaveGameTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGameTest.java diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGameTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGameTest.java new file mode 100644 index 0000000..907431e --- /dev/null +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGameTest.java @@ -0,0 +1,53 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.model; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Test class for {@link SaveGame}. + * */ +class SaveGameTest { + + /** + * {@link SaveGame} object to use for testing. + * */ + private SaveGame testSaveGame; + + @BeforeEach + void setUp() { + testSaveGame = new SaveGame("Save 1", 10, 100, "Stock path"); + } + + @Test + void constructorSetsValuesAsExpected() { + Assertions.assertEquals("Save 1", testSaveGame.getName()); + Assertions.assertEquals(10, testSaveGame.getBalance()); + Assertions.assertEquals(100, testSaveGame.getStartingCapital()); + Assertions.assertEquals("Stock path", testSaveGame.getStockDataPath()); + } + + @Test + void constructorThrowsExceptionOnIllegalArguments() { + assertDoesNotThrow( + () -> new SaveGame("Save 2", 10, 100, "Stock path 2") + ); + + assertThrows(IllegalArgumentException.class, + () -> new SaveGame("", 10, 100, "Stock path 2") + ); + + assertThrows(IllegalArgumentException.class, + () -> new SaveGame("Save 2", 0, 100, "Stock path 2") + ); + + assertThrows(IllegalArgumentException.class, + () -> new SaveGame("Save 2", 10, -10, "Stock path 2") + ); + } +} \ No newline at end of file