Skip to content

Commit 22aff2a

Browse files
feat: added tests 82% coverage
1 parent 43b0c16 commit 22aff2a

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15/Employee.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ public double getSalary() {
4545
public void setSalary(double salary) {
4646
this.salary = salary;
4747
}
48+
49+
public String getDetails(){
50+
return "ID: " + getId() + ", Name: " + getName() + ", Department: " + getDepartment() + ", Salary: " + getSalary();
51+
}
4852
}

lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/Lesson15Test.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.codedifferently.lesson15;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
55
import org.junit.jupiter.api.Test;
66

77
class Lesson15Test {
@@ -16,4 +16,68 @@ public void testGetGreeting() {
1616
// Act
1717
Lesson15.main(null);
1818
}
19+
20+
@Test
21+
public void employeeManagerAddEmployee(){
22+
Employee employee = new Employee(0, null, null, 0);
23+
EmployeeManager manager = new EmployeeManager();
24+
manager.addEmployee(employee);
25+
26+
assertEquals(employee, manager.getEmployee(0));
27+
}
28+
29+
@Test
30+
public void employeeManagerRemoveEmployee(){
31+
Employee employee = new Employee(0, null, null, 0);
32+
EmployeeManager manager = new EmployeeManager();
33+
manager.addEmployee(employee);
34+
35+
manager.removeEmployee(0);
36+
37+
assertEquals(0, manager.getEmployeeCount());
38+
}
39+
40+
41+
@Test
42+
public void employeeManagerUpdateEmployee(){
43+
Employee employee = new Employee(0, null, null, 0);
44+
Employee employee2 = new Employee(0, "test", "dept", 0);
45+
EmployeeManager manager = new EmployeeManager();
46+
manager.addEmployee(employee);
47+
48+
manager.updateEmployee(employee2);
49+
50+
assertEquals("ID: 0, Name: test, Department: dept, Salary: 0.0", manager.getEmployee(0).getDetails());
51+
52+
}
53+
54+
55+
@Test
56+
public void getEmployeeDepartment(){
57+
Employee employee = new Employee(0, null, "fryCook", 0);
58+
59+
assertEquals("fryCook", employee.getDepartment());
60+
}
61+
62+
@Test
63+
public void getEmployeeSalary(){
64+
Employee employee = new Employee(0, null, "fryCook", 999_999);
65+
66+
assertEquals(999_999, employee.getSalary());
67+
68+
}
69+
70+
@Test
71+
public void getEmployeeName(){
72+
Employee employee = new Employee(0, "James Bartholomew the III", "fryCook", 999_999);
73+
assertEquals("James Bartholomew the III", employee.getName());
74+
75+
}
76+
77+
78+
@Test
79+
public void getEmployeeDetails(){
80+
Employee employee = new Employee(0, "James Bartholomew the III", "fryCook", 999_999);
81+
assertEquals("ID: 0, Name: James Bartholomew the III, Department: fryCook, Salary: 999999.0", employee.getDetails());
82+
}
1983
}

0 commit comments

Comments
 (0)