-
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/67-purchasecalculato…
…rtest'
- Loading branch information
Showing
1 changed file
with
44 additions
and
2 deletions.
There are no files selected for viewing
46 changes: 44 additions & 2 deletions
46
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseCalculatorTest.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,45 @@ | ||
| public class PurchaseCalculatorTest { | ||
|
|
||
| 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; | ||
|
|
||
| class PurchaseCalculatorTest { | ||
|
|
||
| @Test | ||
| void calculateGrossReturnsPurchasePriceTimesQuantity() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("200"), calculator.calculateGross()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateCommissionReturnsHalfPercentOfGross() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("1.000"), calculator.calculateCommission()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTaxReturnsZero() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(BigDecimal.ZERO, calculator.calculateTax()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTotalReturnsGrossPlusCommission() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("201.000"), calculator.calculateTotal()); | ||
| } | ||
| } |