-
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.
Merge remote-tracking branch 'refs/remotes/origin/mappe_del1' into ma…
…ppe_del1
- Loading branch information
Showing
5 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
9 changes: 4 additions & 5 deletions
9
target/test-classes/ExchangeTest.java → src/test/java/ExchangeTest.java
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
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,83 @@ | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import java.math.BigDecimal; | ||
|
|
||
| public class PortfolioTest { | ||
|
|
||
| @Test | ||
| void testAddSharePortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| boolean result = portfolio.addShare(share); | ||
|
|
||
| assertTrue(result); | ||
| assertTrue(portfolio.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveSharePortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| portfolio.addShare(share); | ||
|
|
||
| boolean result = portfolio.removeShare(share); | ||
|
|
||
| assertTrue(result); | ||
| assertFalse(portfolio.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetSharesPortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| portfolio.addShare(share); | ||
|
|
||
| var shares = portfolio.getShares(); | ||
|
|
||
| assertEquals(1, shares.size()); | ||
| assertTrue(shares.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetSharesBySymbolPortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock1 = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Stock stock2 = new Stock("GOOGL", "Google", new BigDecimal("200")); | ||
|
|
||
| Share share1 = new Share(stock1, new BigDecimal("10"), new BigDecimal("140")); | ||
| Share share2 = new Share(stock2, new BigDecimal("10"), new BigDecimal("190")); | ||
|
|
||
| portfolio.addShare(share1); | ||
| portfolio.addShare(share2); | ||
|
|
||
| var result = portfolio.getShares("AAPL"); | ||
|
|
||
| assertEquals(1, result.size()); | ||
| assertTrue(result.contains(share1)); | ||
| } | ||
|
|
||
| @Test | ||
| void testContainsPortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("140")); | ||
|
|
||
| portfolio.addShare(share); | ||
|
|
||
| assertTrue(portfolio.contains(share)); | ||
| } | ||
|
|
||
|
|
||
| } |
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()); | ||
| } | ||
|
|
||
|
|
||
| } |
5 changes: 2 additions & 3 deletions
5
target/test-classes/StockTest.java → src/test/java/StockTest.java
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
Binary file not shown.