Skip to content

Commit

Permalink
Added PortfolioTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Mar 10, 2026
1 parent 32b5cb7 commit 2aa2af0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/PortfolioTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import java.math.BigDecimal;

public class PortfolioTest {

@Test
void testAddShare() {
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 testRemoveShare() {
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));
}


}

0 comments on commit 2aa2af0

Please sign in to comment.