diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/audio/Audio.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/audio/Audio.java index 61ec2e1..63e1c4f 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/audio/Audio.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/audio/Audio.java @@ -11,7 +11,6 @@ public enum Audio { CLOCK("/audio/clock.wav", true), // Background music - WORK_THEME("/audio/work_theme.mp3", false), WEEKEND_THEME("/audio/weekend_theme.mp3", false); private final String path; diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/GameController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/GameController.java index 5a255d4..eec5cfc 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/GameController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/GameController.java @@ -44,7 +44,7 @@ public void setGameState(final GameState gameState) { this.gameState = gameState; if (gameState == GameState.WORKDAY && !workMusicPlaying) { - audioManager.playBgMusic(Audio.WORK_THEME); + //audioManager.playBgMusic(Audio.WORK_THEME); workMusicPlaying = true; weekendMusicPlaying = false; } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketController.java index 2cc9048..914d1a1 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketController.java @@ -7,6 +7,7 @@ import edu.ntnu.idi.idatt2003.gruppe42.model.exceptions.StockFileParseException; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/StartViewController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/StartViewController.java index 3743dcf..fb8d6e7 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/StartViewController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/controller/viewcontrollers/StartViewController.java @@ -17,10 +17,8 @@ public class StartViewController { - private static final System.Logger LOGGER = - System.getLogger(StartViewController.class.getName()); - private String username = ""; + private static final Random random = new Random(); private final StartView startView; private final Millions application; @@ -127,14 +125,6 @@ private Difficulty resolveDifficulty() { return Difficulty.EASY; } - if (Objects.isNull(userSelectedPath)) { - try { - userSelectedPath = Path.of(Objects.requireNonNull( - getClass().getClassLoader().getResource("stocks.csv")).toURI()); - } catch (Exception e) { - LOGGER.log(System.Logger.Level.WARNING, "Could not resolve default stocks.csv resource", e); - } - if (selectedMode.startsWith("Medium")) { return Difficulty.MEDIUM; } @@ -148,7 +138,7 @@ private Difficulty resolveDifficulty() { private String resolveUsername(String input) { if (input == null || input.trim().isEmpty() || !input.matches("[a-zA-Z0-9]+")) { - return TATE_NAMES.get(new Random().nextInt(TATE_NAMES.size())); + return TATE_NAMES.get(random.nextInt(TATE_NAMES.size())); } return input; } diff --git a/src/main/resources/Audio/.work_theme.mp3.icloud b/src/main/resources/Audio/.work_theme.mp3.icloud deleted file mode 100644 index d50b58b..0000000 Binary files a/src/main/resources/Audio/.work_theme.mp3.icloud and /dev/null differ diff --git a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketControllerTest.java b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketControllerTest.java index 4bcb4f7..588c7eb 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketControllerTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/controller/MarketControllerTest.java @@ -6,7 +6,7 @@ import edu.ntnu.idi.idatt2003.gruppe42.model.exceptions.StockFileParseException; import java.io.IOException; -import java.math.BigDecimal; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import org.junit.jupiter.api.AfterEach; @@ -19,19 +19,21 @@ *
Verifies market initialization, stock price updates, and exchange state. */ public class MarketControllerTest { - private Path tempFile; + private Path tempFile; // ← was: InputStream tempFile private MarketController controller; @BeforeEach void setUp() throws IOException, StockFileParseException { tempFile = Files.createTempFile("market_test", ".csv"); Files.writeString(tempFile, "AAPL,Apple Inc.,100.00\nMSFT,Microsoft,200.00"); - controller = new MarketController(tempFile); + try (InputStream is = Files.newInputStream(tempFile)) { + controller = new MarketController(is); + } } @AfterEach void tearDown() throws IOException { - Files.deleteIfExists(tempFile); + Files.deleteIfExists(tempFile); // ← now works, Path expected } @Test @@ -43,9 +45,9 @@ void testMarketInitialization() { @Test void testUpdateMarket() { - BigDecimal initialPrice = controller.getExchange().getStock("AAPL").getSalesPrice(); + controller.getExchange().getStock("AAPL").getSalesPrice(); controller.updateMarket(); - BigDecimal newPrice = controller.getExchange().getStock("AAPL").getSalesPrice(); + controller.getExchange().getStock("AAPL").getSalesPrice(); // Price history should have grown by one tick assertEquals(122, controller.getExchange().getStock("AAPL").getHistoricalPrices().size()); } diff --git a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/model/StockFileHandlerTest.java b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/model/StockFileHandlerTest.java index f98aceb..985a77d 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/model/StockFileHandlerTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/gruppe42/model/StockFileHandlerTest.java @@ -1,6 +1,7 @@ package edu.ntnu.idi.idatt2003.gruppe42.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import edu.ntnu.idi.idatt2003.gruppe42.model.exceptions.StockFileParseException; import java.io.IOException; @@ -18,8 +19,15 @@ * including handling of valid entries, comments, and empty lines. */ public class StockFileHandlerTest { + + /** Temporary file used by each test, deleted after each test run. */ private Path testFile; + /** + * Deletes the temporary test file after each test, if it was created. + * + * @throws IOException if the file cannot be deleted + */ @AfterEach void tearDown() throws IOException { if (testFile != null) { @@ -28,58 +36,82 @@ void tearDown() throws IOException { } /** - * Tests that a valid CSV file is correctly parsed into Stock objects. + * Tests that a valid CSV file is correctly parsed into {@link Stock} objects. + * + *
Writes two stock entries to a temporary file and verifies that both
+ * are parsed, and that the first entry has the expected ticker symbol.
*
- * @throws Exception if file creation or reading fails
+ * @throws Exception if file creation, writing, or reading fails
*/
@Test
void readFromFileTest() throws Exception {
- Path testFile = Files.createTempFile("stocks", ".csv");
- Files.writeString(testFile,
- "AAPL,Apple Inc.,276.43\nMSFT,Microsoft,404.68");
+ testFile = Files.createTempFile("stocks", ".csv");
+ Files.writeString(testFile, "AAPL,Apple Inc.,276.43\nMSFT,Microsoft,404.68");
try (InputStream in = Files.newInputStream(testFile)) {
List