Skip to content

Commit

Permalink
Tax service implementation + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-anufriev committed Dec 5, 2018
1 parent ffb5cd8 commit 85621fa
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
27 changes: 27 additions & 0 deletions pom.xml
Expand Up @@ -11,6 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<junit.version>5.3.2</junit.version>
</properties>

<build>
Expand All @@ -23,6 +25,31 @@
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -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);
}
}
@@ -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);
}
}

0 comments on commit 85621fa

Please sign in to comment.