Skip to content

Commit 7dce287

Browse files
authored
Update salary calculator to use test runner v3 features (#2492)
* Update salary calculator to use test runner v3 features * shortened display names * shortened more display names
1 parent 172b4ee commit 7dce287

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

exercises/concept/salary-calculator/build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
apply plugin: "java"
2-
apply plugin: "eclipse"
3-
apply plugin: "idea"
4-
5-
// set default encoding to UTF-8
6-
compileJava.options.encoding = "UTF-8"
7-
compileTestJava.options.encoding = "UTF-8"
1+
plugins {
2+
id "java"
3+
}
84

95
repositories {
106
mavenCentral()
117
}
128

139
dependencies {
14-
testImplementation "junit:junit:4.13"
10+
testImplementation platform("org.junit:junit-bom:5.10.0")
11+
testImplementation "org.junit.jupiter:junit-jupiter"
1512
testImplementation "org.assertj:assertj-core:3.15.0"
1613
}
1714

1815
test {
16+
useJUnitPlatform()
17+
1918
testLogging {
20-
exceptionFormat = 'full'
19+
exceptionFormat = "full"
2120
showStandardStreams = true
2221
events = ["passed", "failed", "skipped"]
2322
}

exercises/concept/salary-calculator/src/test/java/SalaryCalculatorTest.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import org.junit.Before;
2-
import org.junit.Test;
1+
import org.junit.jupiter.api.BeforeEach;
2+
import org.junit.jupiter.api.DisplayName;
3+
import org.junit.jupiter.api.Tag;
4+
import org.junit.jupiter.api.Test;
35

46
import static org.assertj.core.api.Assertions.*;
57

@@ -8,63 +10,84 @@ public class SalaryCalculatorTest {
810

911
public SalaryCalculator calculator;
1012

11-
12-
@Before
13+
@BeforeEach
1314
public void setUp() {
1415
calculator = new SalaryCalculator();
1516
}
1617

1718
@Test
19+
@Tag("task:3")
20+
@DisplayName("The finalSalary method returns the regular salary without multiplier and bonus")
1821
public void regularSalary() {
1922
assertThat(calculator.finalSalary(0, 0)).isEqualTo(1000.0);
2023
}
2124

2225
@Test
26+
@Tag("task:3")
27+
@DisplayName("The finalSalary method returns the correct result when daysSkipped below threshold")
2328
public void skippedBelowThreshold () {
2429
assertThat(calculator.finalSalary(3, 0)).isEqualTo(1000.0);
2530
}
2631

2732
@Test
33+
@Tag("task:3")
34+
@DisplayName("The finalSalary method returns the correct result when daysSkipped above threshold")
2835
public void skippedAboveThreshold() {
2936
assertThat(calculator.finalSalary(7, 0)).isEqualTo(850.0);
3037
}
3138

3239
@Test
40+
@Tag("task:3")
41+
@DisplayName("The finalSalary method returns the correct result when productsSold below threshold")
3342
public void soldBelowThreshold() {
3443
assertThat(calculator.finalSalary(0, 10)).isEqualTo(1100.0);
3544
}
3645

3746
@Test
47+
@Tag("task:3")
48+
@DisplayName("The finalSalary method returns the correct result when productsSold above threshold")
3849
public void soldAboveThreshold() {
3950
assertThat(calculator.finalSalary(0, 25)).isEqualTo(1325.0);
4051
}
4152

4253
@Test
54+
@Tag("task:3")
55+
@DisplayName("The finalSalary method returns the correct result when daysSkipped and productsSold below threshold")
4356
public void skippedBelowThresholdAndSoldBelowThreshold() {
4457
assertThat(calculator.finalSalary(2, 5)).isEqualTo(1050.0);
4558
}
4659

4760
@Test
61+
@Tag("task:3")
62+
@DisplayName("finalSalary method returns correct result when daysSkipped below and productsSold above threshold")
4863
public void skippedBelowThresholdAndSoldAboveThreshold() {
4964
assertThat(calculator.finalSalary(4, 40)).isEqualTo(1520.0);
5065
}
5166

5267
@Test
68+
@Tag("task:3")
69+
@DisplayName("finalSalary method returns correct result when daysSkipped above and productsSold below threshold")
5370
public void skippedAboveThresholdAndSoldBelowThreshold() {
5471
assertThat(calculator.finalSalary(10, 2)).isEqualTo(870.0);
5572
}
5673

5774
@Test
75+
@Tag("task:3")
76+
@DisplayName("The finalSalary method returns the correct result when daysSkipped and productsSold above threshold")
5877
public void skippedAboveThresholdAndSoldAboveThreshold() {
5978
assertThat(calculator.finalSalary(7, 50)).isEqualTo(1500.0);
6079
}
6180

6281
@Test
82+
@Tag("task:3")
83+
@DisplayName("The finalSalary method returns the correct result getting closer to the maximum")
6384
public void salaryCanReachCloseToMaximum() {
6485
assertThat(calculator.finalSalary(0, 76)).isEqualTo(1988.0);
6586
}
6687

6788
@Test
89+
@Tag("task:3")
90+
@DisplayName("The finalSalary method returns the correct result capped at maximum salary")
6891
public void salaryRespectMaximum() {
6992
assertThat(calculator.finalSalary(0, 77)).isEqualTo(2000.0);
7093
}

0 commit comments

Comments
 (0)