Employee.java
package com.javaskool;
public class Employee {
private String name;
private double monthlySalary;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMonthlySalary() {
return monthlySalary;
}
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
EmployeeSalaryProcess.java
package com.javaskool;
public class EmployeeSalaryProcess
{
// Calculate the yearly salary of employee
public double calculateYearlySalary(Employee employeeDetails){
double yearlySalary=0;
yearlySalary = employeeDetails.getMonthlySalary() * 12;
return yearlySalary;
}
// Calculate the appraisal amount of employee
public double calculateAppraisal(Employee employeeDetails){
double appraisal=0;
if(employeeDetails.getMonthlySalary() < 10000){
appraisal = 1500;
}else{
appraisal = 2000;
}
return appraisal;
}
}
EmployeeSalaryProcessTest.java
package com.javaskool;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class EmployeeSalaryProcessTest {
EmployeeSalaryProcess empBusinessLogic =new EmployeeSalaryProcess();
Employee employee = new Employee();
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCalculateYearlySalary() {
//fail("Not yet implemented");
employee.setName("James");
employee.setAge(25);
employee.setMonthlySalary(8000);
double salary= empBusinessLogic.calculateYearlySalary(employee);
assertEquals(96000, salary, 0.0);
}
@Test
public void testCalculateAppraisal() {
//fail("Not yet implemented");
employee.setName("James");
employee.setAge(25);
employee.setMonthlySalary(8000);
double appraisal= empBusinessLogic.calculateAppraisal(employee);
assertEquals(1500, appraisal, 0.0);
}
}
MyEmpTestRunner.java
package com.javaskool;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class MyEmpTestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(EmployeeSalaryProcessTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
Click here to Download Annotation based JUnit Example
Click here to Download Shopping Cart JUnit Example
Recent Comments