Skip to content

Commit

Permalink
Added more tests to PortfolioTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Mar 10, 2026
1 parent 6baafb4 commit b42502d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/test/java/ExchangeTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class ExchangeTest {

private Exchange exchange;
private Stock apple;
private Stock google;

@Before
@BeforeAll
public void setUp() {
apple = new Stock("AAPL", "Apple", new BigDecimal("100"));
google = new Stock("GOOGL", "Google", new BigDecimal("200"));
Expand Down
50 changes: 48 additions & 2 deletions src/test/java/PortfolioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class PortfolioTest {

@Test
void testAddShare() {
void testAddSharePortfolio() {
Portfolio portfolio = new Portfolio();

Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150"));
Expand All @@ -19,7 +19,7 @@ void testAddShare() {
}

@Test
void testRemoveShare() {
void testRemoveSharePortfolio() {
Portfolio portfolio = new Portfolio();

Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150"));
Expand All @@ -33,5 +33,51 @@ void testRemoveShare() {
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));
}


}
5 changes: 2 additions & 3 deletions src/test/java/StockTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.math.BigDecimal;

import org.junit.Test;


public class StockTest {

Expand Down

0 comments on commit b42502d

Please sign in to comment.