|
1 | 1 | package com.codedifferently.lesson15;
|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 4 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
4 | 5 | import org.junit.jupiter.api.BeforeEach;
|
5 | 6 | import org.junit.jupiter.api.Test;
|
6 | 7 |
|
@@ -44,18 +45,61 @@ void testUpdateEmployee() {
|
44 | 45 | @Test
|
45 | 46 | void testGetEmployee() {
|
46 | 47 | //Arrange
|
| 48 | + Employee employee = new Employee(1, "John Doe", null, 0); |
| 49 | + |
47 | 50 | //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 | + |
48 | 58 | }
|
49 | 59 |
|
50 | 60 | @Test
|
51 | 61 | 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 | + |
54 | 71 | }
|
55 | 72 |
|
56 | 73 | @Test
|
57 | 74 | 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 | + }); |
60 | 104 | }
|
61 | 105 | }
|
0 commit comments