From c7ee5193479b071d95f02565a528212ea2db1551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Sk=C3=B8ien?= Date: Mon, 25 May 2026 11:56:43 +0200 Subject: [PATCH] fix merge conflict related errors --- .../idi/idatt2003/gruppe42/audio/Audio.java | 1 - .../gruppe42/controller/GameController.java | 2 +- .../gruppe42/controller/MarketController.java | 1 + .../viewcontrollers/StartViewController.java | 14 +--- .../resources/Audio/.work_theme.mp3.icloud | Bin 164 -> 0 bytes .../controller/MarketControllerTest.java | 14 ++-- .../gruppe42/model/StockFileHandlerTest.java | 72 +++++++++++++----- 7 files changed, 64 insertions(+), 40 deletions(-) delete mode 100644 src/main/resources/Audio/.work_theme.mp3.icloud 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 d50b58b2991958306c05dc89ce77b534a455fb94..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 164 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFxbpm>?D&$5)ZA3P+yY}E22VSNcmWx#%7aqVOLG#7IQV7sy&~fnz<`kv MLNl;KX&6-t0GgvLBme*a 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 stocks = StockFileHandler.readFromFile(in); - assertEquals(2, stocks.size()); assertEquals("AAPL", stocks.get(0).getSymbol()); } } /** - * Tests that comments and empty lines are ignored when parsing. + * Tests that comment lines (prefixed with {@code #}) and blank lines are + * ignored during parsing, leaving only valid stock entries in the result. * - * @throws Exception if file creation or reading fails + * @throws IOException if file creation or writing fails + * @throws StockFileParseException if the file content cannot be parsed */ @Test void readFromFileWithCommentsAndEmptyLines() throws IOException, StockFileParseException { - testFile = Files.createTempFile("stocks", "csv"); + testFile = Files.createTempFile("stocks", ".csv"); Files.writeString(testFile, "#Comment\n\nAAPL,Apple Inc.,276.43"); - List stocks = StockFileHandler.readFromFile(testFile); - assertEquals(1, stocks.size()); + try (InputStream in = Files.newInputStream(testFile)) { + List stocks = StockFileHandler.readFromFile(in); + assertEquals(1, stocks.size()); + } } + /** + * Tests that a ticker symbol exceeding the maximum allowed length causes a + * {@link StockFileParseException} to be thrown. + * + * @throws IOException if file creation or writing fails + */ @Test void testReadInvalidSymbol() throws IOException { - testFile = Files.createTempFile("invalid_symbol", "csv"); + testFile = Files.createTempFile("invalid_symbol", ".csv"); Files.writeString(testFile, "INVALIDTOOLONG,Apple,100.00"); - org.junit.jupiter.api.Assertions.assertThrows(StockFileParseException.class, () -> - StockFileHandler.readFromFile(testFile)); + assertThrows(StockFileParseException.class, () -> + StockFileHandler.readFromFile(Files.newInputStream(testFile))); } + /** + * Tests that a price value lacking a decimal component causes a + * {@link StockFileParseException} to be thrown. + * + * @throws IOException if file creation or writing fails + */ @Test void testReadInvalidPrice() throws IOException { - testFile = Files.createTempFile("invalid_price", "csv"); + testFile = Files.createTempFile("invalid_price", ".csv"); Files.writeString(testFile, "AAPL,Apple,100"); - org.junit.jupiter.api.Assertions.assertThrows(StockFileParseException.class, () -> - StockFileHandler.readFromFile(testFile)); + assertThrows(StockFileParseException.class, () -> + StockFileHandler.readFromFile(Files.newInputStream(testFile))); } + /** + * Tests that a CSV row with fewer than the required number of fields causes a + * {@link StockFileParseException} to be thrown. + * + * @throws IOException if file creation or writing fails + */ @Test void testReadMissingFields() throws IOException { - testFile = Files.createTempFile("missing_fields", "csv"); + testFile = Files.createTempFile("missing_fields", ".csv"); Files.writeString(testFile, "AAPL,Apple"); - org.junit.jupiter.api.Assertions.assertThrows(StockFileParseException.class, () -> - StockFileHandler.readFromFile(testFile)); + assertThrows(StockFileParseException.class, () -> + StockFileHandler.readFromFile(Files.newInputStream(testFile))); + } } \ No newline at end of file