Skip to content

Commit

Permalink
fix merge conflict related errors
Browse files Browse the repository at this point in the history
  • Loading branch information
einaskoi committed May 25, 2026
1 parent afaf17e commit c7ee519
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Binary file removed src/main/resources/Audio/.work_theme.mp3.icloud
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,19 +19,21 @@
* <p>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
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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.
*
* <p>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<Stock> 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<Stock> stocks = StockFileHandler.readFromFile(testFile);
assertEquals(1, stocks.size());
try (InputStream in = Files.newInputStream(testFile)) {
List<Stock> 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)));
}
}

0 comments on commit c7ee519

Please sign in to comment.