Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/mappe_del1' into ma…
Browse files Browse the repository at this point in the history
…ppe_del1
  • Loading branch information
Solveig Natvig committed Mar 22, 2026
2 parents 5ec6c53 + cb88b74 commit cbf8f06
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 8 deletions.
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
83 changes: 83 additions & 0 deletions src/test/java/PortfolioTest.java
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));
}


}
71 changes: 71 additions & 0 deletions src/test/java/ShareTest.java
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());
}


}
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
Binary file modified target/classes/PurchaseCalculator.class
Binary file not shown.

0 comments on commit cbf8f06

Please sign in to comment.