-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Solveig Natvig
committed
Mar 23, 2026
1 parent
33cebc4
commit 0d24756
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class SaleTest { | ||
| Stock stock; | ||
| Share share; | ||
| Sale sale; | ||
|
|
||
| @BeforeEach | ||
| void setUp(){ | ||
| this.stock = new Stock("symbol", "company", new BigDecimal(100)); | ||
| this.share = new Share(this.stock, new BigDecimal(20), new BigDecimal(80)); | ||
| this.sale = new Sale(this.share, 18); | ||
| } | ||
|
|
||
| @Test | ||
| void commit_validSale_updatesPlayerState() { | ||
|
|
||
| // Arrange | ||
| Player player = new Player("Jane", new BigDecimal(500)); | ||
| player.getPortfolio().addShare(this.share); | ||
|
|
||
| // Act | ||
| this.sale.commit(player); | ||
|
|
||
| // Assert | ||
| assertTrue(player.getTransactionArchive().getTransactions(this.sale.getWeek()).contains(this.sale)); | ||
| assertFalse(player.getPortfolio().contains(this.share)); | ||
| assertTrue(this.sale.isCommitted()); | ||
| } | ||
|
|
||
| @Test | ||
| void commit_alreadyCommitted_noAction() { | ||
|
|
||
| // Arrange | ||
| Player player = new Player("Jane", new BigDecimal(500)); | ||
| player.getPortfolio().addShare(this.share); | ||
| this.sale.commit(player); | ||
| BigDecimal moneyAfterFirstCommit = player.getMoney(); | ||
|
|
||
| // Act | ||
| this.sale.commit(player); | ||
|
|
||
| // Assert | ||
| assertEquals(moneyAfterFirstCommit, player.getMoney()); | ||
| assertEquals(1, player.getTransactionArchive().getTransactions(this.sale.getWeek()).size()); | ||
| assertTrue(this.sale.isCommitted()); | ||
| } | ||
|
|
||
|
|
||
| } |