Skip to content

Commit

Permalink
Add PurchaseTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Solveig Natvig committed Mar 24, 2026
1 parent 4b12887 commit ba8f76e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/PurchaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.math.BigDecimal;

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

public class PurchaseTest {
Stock stock;
Share share;
Purchase purchase;

@BeforeEach
void setUp() {
this.stock = new Stock("symbol", "company", new BigDecimal(100));
this.share = new Share(this.stock, new BigDecimal(20), new BigDecimal(50));
this.purchase = new Purchase(this.share, 18);
}

@Test
void commit_validPurchase_updatesPlayer() {

// Arrange
Player player = new Player("Jane", new BigDecimal(500000));
BigDecimal startingMoney = player.getMoney();

// Act
this.purchase.commit(player);

// Assert
assertEquals(1, startingMoney.subtract(player.getMoney()).signum());

}



}

0 comments on commit ba8f76e

Please sign in to comment.