The following Java method calculates the bonus for employee based on item year of service,salary, and performance. The method involves different calculations for various scenarios. Your task is to design test cases using JUnit for this method. You should apply equivalence partitioning and boundary value analysis for the input parameters. Additionally, ensure that your test cases cover all branches of the code to achieve 100% code coverage.
public class EmployeeBonusCalculator {
public double calculateBonus (int yearsofservice, double salary, boolean hasOutstandingPerformance) {
if (yearsOfService < || salary <= 0) {
throw new IllegalArgumentException("Invalid input: yearsOfService and salary must be positive.");
double bonusPercentage 0.0;
if (yearsOfService > 10) {
bonus Percentage = 0.10;
} else if (yearsOfService >= 5) (
bonus Percentage = 0.07;} else if (yearsOfService > 2) {
bonusPercentage 0.05;
} else {
bonus Percentage = 0.02;
19 20日
21
22
23
24
25
26
}
if (hasOutstandingPerformance) {
bonus Percentage + 0.03;
return salary bonusPercentage;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Sample JUnit Test Class for Completion
The following is a partially completed JUnit test class for the EmployeeBonus Calculator method. Students are required to complete this class by adding the necessary test cases to achieve full equivalence partitioning, boundary value analysis, and branch coverage for the Employee Bonus Calculator method. After completing the tests, students should copy and paste the test code into a Word document for evaluation.
Zoom
100%
Close
Activate Wir
Go to Settings to