Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffb5cd8
commit 85621fa
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
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
12 changes: 11 additions & 1 deletion
12
src/main/java/com/aa/gitbisect/service/TaxCalculationService.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,10 +1,20 @@ | ||
package com.aa.gitbisect.service; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
public class TaxCalculationService { | ||
|
||
private static final BigDecimal HUNDRED = BigDecimal.valueOf(100); | ||
private static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; | ||
|
||
public BigDecimal getNetSalaryInCurrency(BigDecimal grossSalaryInCurrency, int taxInPercent) { | ||
return null; | ||
BigDecimal taxInCurrency = grossSalaryInCurrency | ||
.multiply(BigDecimal.valueOf(taxInPercent)) | ||
.divide(HUNDRED, ROUNDING_MODE); | ||
|
||
return grossSalaryInCurrency | ||
.subtract(taxInCurrency) | ||
.setScale(2, ROUNDING_MODE); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/aa/gitbisect/service/TaxCalculationServiceTest.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.aa.gitbisect.service; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class TaxCalculationServiceTest { | ||
|
||
private TaxCalculationService taxCalculationService = new TaxCalculationService(); | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"100.00, 10, 90.00", | ||
"100.00, 3, 97.00", | ||
"123.45, 5, 117.28" | ||
|
||
}) | ||
public void testNetSalaryCalculation( | ||
BigDecimal grossSalaryInCurrency, int taxInPercent, BigDecimal expectedNetSalaryInCurrency) { | ||
|
||
BigDecimal actualNetSalaryInCurrency = | ||
taxCalculationService.getNetSalaryInCurrency(grossSalaryInCurrency, taxInPercent); | ||
|
||
Assertions.assertEquals(expectedNetSalaryInCurrency, actualNetSalaryInCurrency); | ||
} | ||
} |