0% found this document useful (0 votes)
20 views2 pages

junit4

The document contains a series of JUnit test cases for the EmployeeSalary class, validating the salary calculation method under various conditions. It tests for invalid inputs that should throw exceptions, such as negative years of service or salary, and performance ratings outside the valid range. Additionally, it includes tests for valid scenarios to ensure the correct calculation of salary based on years of service and performance ratings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

junit4

The document contains a series of JUnit test cases for the EmployeeSalary class, validating the salary calculation method under various conditions. It tests for invalid inputs that should throw exceptions, such as negative years of service or salary, and performance ratings outside the valid range. Additionally, it includes tests for valid scenarios to ensure the correct calculation of salary based on years of service and performance ratings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// junit4

@Test(expected = IllegalArgumentException.class)
public void testInvalidYearOfService() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
salaryCalculator.calculateSalary(-1, 50000, 4);
}

@Test(expected = IllegalArgumentException.class)
public void testNegativeBasicSalary() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
salaryCalculator.calculateSalary(5, -10000, 3);
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidPerformanceRatingBelowZero() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
salaryCalculator.calculateSalary(5, 50000, -1);
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidPerformanceRatingAboveFive() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
salaryCalculator.calculateSalary(5, 50000, 6);
}

@Test
public void testYearOfServiceGreaterThanTen() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(11, 50000, 4);
assertEquals(55000.0, result, 0.01); // 10% bonus, no deduction
}

@Test
public void testYearOfServiceBetweenSixAndTen() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(7, 50000, 4);
assertEquals(52500.0, result, 0.01); // 5% bonus, no deduction
}

@Test
public void testYearOfServiceLessThanOrEqualToFive() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(5, 50000, 4);
assertEquals(50000.0, result, 0.01); // No bonus, no deduction
}

@Test
public void testPerformanceRatingBelowThree() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(5, 50000, 2);
assertEquals(47500.0, result, 0.01); // 5% deduction
}

@Test
public void testValidInputsEdgeCases() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(10, 60000, 5);
assertEquals(60000.0, result, 0.01); // No bonus or deduction
}
@Test
public void testPerformanceRatingMaxBoundary() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(5, 50000, 5);
assertEquals(50000.0, result, 0.01); // No deduction
}

@Test
public void testYearOfServiceZero() {
EmployeeSalary salaryCalculator = new EmployeeSalary();
double result = salaryCalculator.calculateSalary(0, 50000, 4);
assertEquals(50000.0, result, 0.01); // No bonus, no deduction
}

You might also like