Skip to content

Commit

Permalink
test: adding ShareTest
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 6, 2026
1 parent 54bc98c commit 963481b
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/test/java/millions/ShareTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,33 @@

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

class ShareTest {}
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;

class ShareTest {

@Test
public void testHappyPath() {
Stock stock = new Stock("AYO", "Ayhoo", BigDecimal.valueOf(10));
Share share = new Share(stock, 5, BigDecimal.valueOf(10));
assertEquals(BigDecimal.valueOf(5), share.getQuantity());
}

@Test
public void testGetters() {
Stock stock = new Stock("AYO", "Ayhoo", BigDecimal.valueOf(10));
Share share = new Share(stock, 5, BigDecimal.valueOf(10));
assertEquals(BigDecimal.valueOf(5), share.getQuantity());
assertEquals(stock, share.getStock());
assertEquals(BigDecimal.valueOf(10), share.getPurchasePrice());
}

@Test
public void testNullsAndInvalid() {
Stock stock = new Stock("AYO", "Ayhoo", BigDecimal.valueOf(10));
assertThrows(IllegalArgumentException.class, () -> new Share(null, 2, BigDecimal.valueOf(2)));
assertThrows(IllegalArgumentException.class, () -> new Share(stock, 2, null));
assertThrows(
IllegalArgumentException.class, () -> new Share(stock, null, BigDecimal.valueOf(2)));
}
}

0 comments on commit 963481b

Please sign in to comment.