Skip to content

Commit

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

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

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

class SaleTest {

@Test
public void testHappyPath() {
Stock stock = new Stock("TestStock", "TST", BigDecimal.valueOf(10));
Share share = new Share(stock, 2, BigDecimal.valueOf(10));
Player player = new Player("TestPlayer", BigDecimal.valueOf(100));
player.getPortfolio().addShare(share);
Sale sale = new Sale(share, 1);
sale.commit(player);
assertTrue(sale.isCommitted());

assertEquals(120, player.getMoney().intValue());
assertFalse(player.getPortfolio().getShares().contains(share));
}

@Test
public void testNullsAndInvalid() {
Stock stock = new Stock("TestStock", "TST", BigDecimal.valueOf(10));
Share share = new Share(stock, 2, BigDecimal.valueOf(10));
Player player = new Player("TestPlayer", BigDecimal.valueOf(100));
Sale sale = new Sale(share, 1);
assertThrows(IllegalStateException.class, () -> sale.commit(player));
}
}

0 comments on commit 54bc98c

Please sign in to comment.