Class TaxCalculatorTest
java.lang.Object
me.thiagorigonatti.capitalgains.core.TaxCalculatorTest
Test class for the
TaxCalculator class, ensuring correct tax calculations
for various scenarios including sales with profit, losses, and different cost methods.- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTest case for calculating tax when selling at the average cost.voidTest case for formatting a decimal number using a specific decimal format.voidTest case to verify that an exception is thrown when an invalid operation is encountered.voidTest case for calculating tax when there is a loss from previous sales.voidgivenMixedOperationsWithLossAndProfit_whenCalculatingTax_thenLossesAreOffsetAndTaxIsCorrectlyApplied()Test case for mixed operations with both losses and profits.voidTest case for calculating tax when there are multiple sales with accumulated losses and gains.voidgivenMultipleTransactionsForDifferentTickers_whenCalculatingTax_thenTaxIsCalculatedBasedOnNetProfit()Test case for calculating tax when there are multiple stock transactions involving different tickers.voidgivenOperationWithZeroOrNegativeQuantity_whenCalculateTax_thenThrowZeroOrNegativeQuantityException()Test case to verify that an exception is thrown when an operation is performed with a zero or negative quantity.voidTest case to verify that an exception is thrown when a sale exceeds the available quantity of shares.voidTest case for calculating tax when the sale amount is over 20k with profit.voidTest case for calculating tax with accumulated losses.voidTest case for calculating tax on sales with high profits.voidTest case for calculating tax when the sale amount is under 20k with profit.voidTest case for calculating tax with two independent simulations.voidTest case for calculating tax when selling at weighted average cost.voidsetUp()Sets up theTaxCalculatorinstance before each test.
-
Constructor Details
-
TaxCalculatorTest
public TaxCalculatorTest()Default constructor for TaxCalculatorTest. This constructor can be used to initialize any resources or dependencies needed by the test class.
-
-
Method Details
-
setUp
@BeforeEach public void setUp()Sets up theTaxCalculatorinstance before each test. -
givenSaleUnder20kWithProfit_WhenCalculatingTax_thenNoTaxIsDue
@Test public void givenSaleUnder20kWithProfit_WhenCalculatingTax_thenNoTaxIsDue() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when the sale amount is under 20k with profit. Verifies that no tax is due.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenSaleOver20kWithProfit_WhenCalculatingTax_thenTaxIsApplied
@Test public void givenSaleOver20kWithProfit_WhenCalculatingTax_thenTaxIsApplied() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when the sale amount is over 20k with profit. Verifies that tax is applied.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenTwoIndependentSimulation_whenCalculateTax_thenReturnCorrectTaxPerOperation
@Test public void givenTwoIndependentSimulation_whenCalculateTax_thenReturnCorrectTaxPerOperation() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax with two independent simulations. Verifies that tax is calculated correctly for each operation separately.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenLossFromPreviousSale_whenSellingWithProfit_thenTaxIsAppliedOnNetProfit
@Test public void givenLossFromPreviousSale_whenSellingWithProfit_thenTaxIsAppliedOnNetProfit() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when there is a loss from previous sales. Verifies that tax is applied only on the net profit from subsequent sales.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenAverageCost_whenSellingAtAveragePrice_thenNoTaxIsDue
@Test public void givenAverageCost_whenSellingAtAveragePrice_thenNoTaxIsDue() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when selling at the average cost. Verifies that no tax is due when selling at the average price.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenWeightedAverageCost_whenSellingAtBreakEvenAndThenAtProfit_thenOnlyProfitIsTaxed
@Test public void givenWeightedAverageCost_whenSellingAtBreakEvenAndThenAtProfit_thenOnlyProfitIsTaxed() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when selling at weighted average cost. Verifies that tax is applied only to the profit portion.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenSalesWithAccumulatedLosses_whenCalculatingTax_thenLossesAreProperlyDeducted
@Test public void givenSalesWithAccumulatedLosses_whenCalculatingTax_thenLossesAreProperlyDeducted() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax with accumulated losses. Verifies that losses are properly deducted when calculating tax on subsequent sales.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If there is an error processing the JSON input.
-
givenMultipleSalesWithAccumulatedLossesAndGains_whenCalculatingTax_thenLossesAreDeductedAndTaxApplied
@Test public void givenMultipleSalesWithAccumulatedLossesAndGains_whenCalculatingTax_thenLossesAreDeductedAndTaxApplied() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when there are multiple sales with accumulated losses and gains. It verifies that losses are properly deducted and tax is applied correctly based on the net profit.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON input
-
givenSalesWithHighProfit_whenCalculatingTax_thenTaxIsApplied
@Test public void givenSalesWithHighProfit_whenCalculatingTax_thenTaxIsApplied() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax on sales with high profits. It ensures that tax is applied correctly on profits above the threshold.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON input
-
givenMixedOperationsWithLossAndProfit_whenCalculatingTax_thenLossesAreOffsetAndTaxIsCorrectlyApplied
@Test public void givenMixedOperationsWithLossAndProfit_whenCalculatingTax_thenLossesAreOffsetAndTaxIsCorrectlyApplied() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for mixed operations with both losses and profits. It verifies that losses are properly offset and tax is applied correctly on the net profit.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON input
-
givenDecimalNumber_whenFormattedWithDecimalFormat_thenMatchExpectedPattern
@Test public void givenDecimalNumber_whenFormattedWithDecimalFormat_thenMatchExpectedPattern()Test case for formatting a decimal number using a specific decimal format. It checks that the formatted number matches the expected pattern. -
givenInvalidOperation_whenCalculatingTax_thenThrowInvalidOperationException
@Test public void givenInvalidOperation_whenCalculatingTax_thenThrowInvalidOperationException()Test case to verify that an exception is thrown when an invalid operation is encountered. It checks that theInvalidOperationExceptionis thrown for unsupported operations. -
givenOperationWithZeroOrNegativeQuantity_whenCalculateTax_thenThrowZeroOrNegativeQuantityException
@Test public void givenOperationWithZeroOrNegativeQuantity_whenCalculateTax_thenThrowZeroOrNegativeQuantityException()Test case to verify that an exception is thrown when an operation is performed with a zero or negative quantity. It ensures that theZeroOrNegativeQuantityExceptionis thrown for such cases. -
givenMultipleTransactionsForDifferentTickers_whenCalculatingTax_thenTaxIsCalculatedBasedOnNetProfit
@Test public void givenMultipleTransactionsForDifferentTickers_whenCalculatingTax_thenTaxIsCalculatedBasedOnNetProfit() throws com.fasterxml.jackson.core.JsonProcessingExceptionTest case for calculating tax when there are multiple stock transactions involving different tickers. It verifies that the tax is correctly calculated based on the net profit or loss for each ticker. The test ensures that transactions for different tickers are handled separately, and the calculation of tax takes into account accumulated gains and losses.- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON input
-