Skip to content

Commit 5831a17

Browse files
author
AmiyahJo
committed
feat: adds add and remove employee , employee count , and assertion(s) test
1 parent 51304ea commit 5831a17

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

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

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

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45
import org.junit.jupiter.api.BeforeEach;
56
import org.junit.jupiter.api.Test;
67

@@ -44,18 +45,61 @@ void testUpdateEmployee() {
4445
@Test
4546
void testGetEmployee() {
4647
//Arrange
48+
Employee employee = new Employee(1, "John Doe", null, 0);
49+
4750
//Act
51+
employeeManager.addEmployee(employee);
52+
Employee retrievedEmployee = employeeManager.getEmployee(1);
53+
54+
//Assert
55+
assertEquals(employee.getId(), retrievedEmployee.getId());
56+
assertEquals(employee.getName(), retrievedEmployee.getName());
57+
4858
}
4959

5060
@Test
5161
void testRemoveEmployee() {
52-
//Arrange
53-
//Act
62+
63+
Employee employee = new Employee(1, "John Doe", null, 0);
64+
65+
employeeManager.addEmployee(employee);
66+
assertEquals(1, employeeManager.getEmployeeCount());
67+
68+
employeeManager.removeEmployee(1);
69+
assertEquals(0, employeeManager.getEmployeeCount());
70+
5471
}
5572

5673
@Test
5774
void testGetEmployeeCount() {
58-
//Arrange
59-
//Act
75+
76+
assertEquals(0, employeeManager.getEmployeeCount());
77+
78+
employeeManager.addEmployee(new Employee(1, "John Doe", null, 0));
79+
employeeManager.addEmployee(new Employee(2, "Jane Doe", null, 0));
80+
81+
assertEquals(2, employeeManager.getEmployeeCount());
82+
}
83+
84+
@Test
85+
void testGetEmployeeThrowsExceptionForNonExistentId() {
86+
assertThrows(IllegalArgumentException.class, () -> {
87+
employeeManager.getEmployee(999);
88+
});
89+
}
90+
91+
@Test
92+
void testUpdateEmployeeThrowsExceptionForNonExistentId() {
93+
Employee employee = new Employee(1, "John Doe", null, 0);
94+
assertThrows(IllegalArgumentException.class, () -> {
95+
employeeManager.updateEmployee(employee);
96+
});
97+
}
98+
99+
@Test
100+
void testRemoveEmployeeThrowsExceptionForNonExistentId() {
101+
assertThrows(IllegalArgumentException.class, () -> {
102+
employeeManager.removeEmployee(999);
103+
});
60104
}
61105
}

0 commit comments

Comments
 (0)