-
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
Showing
2 changed files
with
71 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,71 @@ | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import java.math.BigDecimal; | ||
|
|
||
|
|
||
| public class ShareTest { | ||
|
|
||
| @Test | ||
| void testShareConstructor() { | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| BigDecimal quantity = new BigDecimal("10"); | ||
| BigDecimal purchasePrice = new BigDecimal("140"); | ||
|
|
||
| Share share = new Share(stock, quantity, purchasePrice); | ||
| assertNotNull(share); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetStock() { | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| Stock result = share.getStock(); | ||
|
|
||
| assertEquals(stock, result); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetQuantity() { | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| BigDecimal result = share.getQuantity(); | ||
|
|
||
| assertEquals(new BigDecimal("10"), result); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetPurchasePrice() { | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| BigDecimal result = share.getPurchasePrice(); | ||
|
|
||
| assertEquals(new BigDecimal("140"), result); | ||
| } | ||
|
|
||
| @Test | ||
| void testNullStock() { | ||
|
|
||
| Share share = new Share(null, new BigDecimal("10"), new BigDecimal("100")); | ||
|
|
||
| assertNull(share.getStock()); | ||
| } | ||
|
|
||
| @Test | ||
| void testNegativePrice() { | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("-50")); | ||
|
|
||
| assertEquals(new BigDecimal("-50"), share.getPurchasePrice()); | ||
| } | ||
|
|
||
|
|
||
| } |
Binary file not shown.