Skip to content

Commit

Permalink
Update StockTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 25, 2026
1 parent e6a3914 commit 98bdd9f
Showing 1 changed file with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package edu.ntnu.idi.idatt2003.g40.mappe.model;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

final class StockTest {

/**
* Stock to use for testing.
* */
private Stock testStock;

@BeforeEach
Expand All @@ -23,6 +28,28 @@ void constructorSetsSymbolAndCompany() {
assertEquals("Apple Inc.", testStock.getCompany());
}

@Test
void constructorThrowsExceptionOnIllegalArguments() {
assertDoesNotThrow(
() -> new Stock("AAPL", "APPLE INC.", new BigDecimal("100"))
);

assertThrows(IllegalArgumentException.class,
() -> new Stock("", "APPLE INC.", new BigDecimal("100"))
);

assertThrows(IllegalArgumentException.class,
() -> new Stock("AAPL", "", new BigDecimal("100"))
);

assertThrows(IllegalArgumentException.class,
() -> new Stock("AAPL", "APPLE INC.", new BigDecimal("0"))
);
assertThrows(IllegalArgumentException.class,
() -> new Stock("AAPL", "APPLE INC.", null)
);
}

@Test
void addNewSalesPriceThenGetSalesPriceReturnsLastAddedPrice() {
testStock.addNewSalesPrice(new BigDecimal("123.45"));
Expand All @@ -39,11 +66,18 @@ void addNewSalesPriceTwiceGetSalesPriceReturnsMostRecent() {
}

@Test
void addNewSalesPriceDoesNotAllowNullCurrentImplementation() {

void addNewSalesPriceThrowsExceptionOnIllegalArguments() {
assertThrows(IllegalArgumentException.class, () -> {
testStock.addNewSalesPrice(null);
});

assertThrows(IllegalArgumentException.class, () -> {
testStock.addNewSalesPrice(new BigDecimal("0"));
});

assertThrows(IllegalArgumentException.class, () -> {
testStock.addNewSalesPrice(new BigDecimal("-10"));
});
}

@Test
Expand Down

0 comments on commit 98bdd9f

Please sign in to comment.