Skip to content

Commit

Permalink
Create SaveGameTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 25, 2026
1 parent 76f784d commit e673691
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
);
}
}

0 comments on commit e673691

Please sign in to comment.