BAEL 6249: Gray Box Testing (#13610)
* test implementation and sut class * finishing up unit tests * format * fix test name * changing method source name * creating new module testing-techniques * fix package name --------- Co-authored-by: Ashley Frieze <ashley@incredible.org.uk>
This commit is contained in:
parent
0938194300
commit
dfa2ef7a8e
@ -52,6 +52,7 @@
|
|||||||
<module>xmlunit-2</module>
|
<module>xmlunit-2</module>
|
||||||
<module>zerocode</module>
|
<module>zerocode</module>
|
||||||
<module>mockito-2</module>
|
<module>mockito-2</module>
|
||||||
|
<module>testing-techniques</module>
|
||||||
<module>gatling-java</module>
|
<module>gatling-java</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
14
testing-modules/testing-techniques/pom.xml
Normal file
14
testing-modules/testing-techniques/pom.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<artifactId>testing-techniques</artifactId>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>testing-modules</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
</project>
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.baeldung.greyboxtesting;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.stream.DoubleStream;
|
||||||
|
|
||||||
|
public class SalaryCommissionPercentageCalculator {
|
||||||
|
public BigDecimal calculate(Level level, Type type, Seniority seniority, SalesImpact impact) {
|
||||||
|
return BigDecimal.valueOf(DoubleStream.of(level.getBonus(), type.getBonus(), seniority.getBonus(), impact.getBonus(), type.getBonus())
|
||||||
|
.average()
|
||||||
|
.orElse(0))
|
||||||
|
.setScale(2, RoundingMode.CEILING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Level {
|
||||||
|
L1(0.06), L2(0.12), L3(0.2);
|
||||||
|
private double bonus;
|
||||||
|
|
||||||
|
Level(double bonus) {
|
||||||
|
this.bonus = bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBonus() {
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
FULL_TIME_COMMISSIONED(0.18), CONTRACTOR(0.1), FREELANCER(0.06);
|
||||||
|
|
||||||
|
private double bonus;
|
||||||
|
|
||||||
|
Type(double bonus) {
|
||||||
|
this.bonus = bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBonus() {
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Seniority {
|
||||||
|
JR(0.8), MID(0.13), SR(0.19);
|
||||||
|
private double bonus;
|
||||||
|
|
||||||
|
Seniority(double bonus) {
|
||||||
|
this.bonus = bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBonus() {
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SalesImpact {
|
||||||
|
LOW(0.06), MEDIUM(0.12), HIGH(0.2);
|
||||||
|
private double bonus;
|
||||||
|
|
||||||
|
SalesImpact(double bonus) {
|
||||||
|
this.bonus = bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBonus() {
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.greyboxtesting;
|
||||||
|
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static com.baeldung.greyboxtesting.SalaryCommissionPercentageCalculator.*;
|
||||||
|
import static com.baeldung.greyboxtesting.SalaryCommissionPercentageCalculator.Level.*;
|
||||||
|
import static com.baeldung.greyboxtesting.SalaryCommissionPercentageCalculator.SalesImpact.*;
|
||||||
|
import static com.baeldung.greyboxtesting.SalaryCommissionPercentageCalculator.Seniority.*;
|
||||||
|
import static com.baeldung.greyboxtesting.SalaryCommissionPercentageCalculator.Type.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class SalaryCommissionPercentageCalculatorUnitTest {
|
||||||
|
|
||||||
|
private SalaryCommissionPercentageCalculator testTarget = new SalaryCommissionPercentageCalculator();
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideReferenceTestScenarioTable")
|
||||||
|
void givenReferenceTable_whenCalculateAverageCommission_thenReturnExpectedResult(Level level, Type type, Seniority seniority, SalesImpact impact, double expected) {
|
||||||
|
BigDecimal got = testTarget.calculate(level, type, seniority, impact);
|
||||||
|
assertEquals(BigDecimal.valueOf(expected), got);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> provideReferenceTestScenarioTable() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of(L1, FULL_TIME_COMMISSIONED, JR, LOW, 0.26),
|
||||||
|
Arguments.of(L1, CONTRACTOR, SR, MEDIUM, 0.12),
|
||||||
|
Arguments.of(L1, FREELANCER, MID, HIGH, 0.11),
|
||||||
|
Arguments.of(L2, FULL_TIME_COMMISSIONED, SR, HIGH, 0.18),
|
||||||
|
Arguments.of(L2, CONTRACTOR, MID, LOW, 0.11),
|
||||||
|
Arguments.of(L2, FREELANCER, JR, MEDIUM, 0.24),
|
||||||
|
Arguments.of(L3, FULL_TIME_COMMISSIONED, MID, MEDIUM, 0.17),
|
||||||
|
Arguments.of(L3, CONTRACTOR, JR, HIGH, 0.28),
|
||||||
|
Arguments.of(L3, FREELANCER, SR, LOW, 0.12)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user