Skip to content

Commit

Permalink
Added ShareTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed Mar 10, 2026
1 parent b42502d commit cb88b74
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
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());
}


}
Binary file modified target/classes/PurchaseCalculator.class
Binary file not shown.

0 comments on commit cb88b74

Please sign in to comment.