-
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 'origin/enhancement/39-unittest-share-cl…
…ass' merge manually
- Loading branch information
Showing
1 changed file
with
48 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 48 additions & 3 deletions
51
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,48 @@ | ||
| public class ShareTest { | ||
|
|
||
| } | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
|
||
| class ShareTest { | ||
|
|
||
| @Test | ||
| void constructorStoresAllValuesCorrectly() { | ||
| Stock stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("150.00")); | ||
| BigDecimal quantity = new BigDecimal("10"); | ||
| BigDecimal purchasePrice = new BigDecimal("145.50"); | ||
|
|
||
| Share share = new Share(stock, quantity, purchasePrice); | ||
|
|
||
| assertSame(stock, share.getStock()); | ||
| assertEquals(quantity, share.getQuantity()); | ||
| assertEquals(purchasePrice, share.getPurchasePrice()); | ||
| } | ||
|
|
||
| @Test | ||
| void shareSupportsDecimalValues() { | ||
| Stock stock = new Stock("TSLA", "Tesla Inc.", new BigDecimal("200.00")); | ||
|
|
||
| Share share = new Share( | ||
| stock, | ||
| new BigDecimal("2.5"), | ||
| new BigDecimal("198.75") | ||
| ); | ||
|
|
||
| assertEquals(new BigDecimal("2.5"), share.getQuantity()); | ||
| assertEquals(new BigDecimal("198.75"), share.getPurchasePrice()); | ||
| } | ||
|
|
||
| @Test | ||
| void getStockReturnsCorrectStockObject() { | ||
| Stock stock = new Stock("NVDA", "NVIDIA Corporation", new BigDecimal("875.40")); | ||
| Share share = new Share(stock, new BigDecimal("4"), new BigDecimal("850.00")); | ||
|
|
||
| assertSame(stock, share.getStock()); | ||
| assertEquals("NVDA", share.getStock().getSymbol()); | ||
| assertEquals("NVIDIA Corporation", share.getStock().getCompany()); | ||
| } | ||
| } |