Skip to content

Commit 328c058

Browse files
committed
chore: tried to fix tests/ removeEmployee and
assertEmployeeInCollection still failing
1 parent b56345f commit 328c058

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed
Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,80 @@
11
package com.codedifferently.lesson15;
22

3-
import static org.assertj.core.api.Assertions.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
45
import static org.junit.jupiter.api.Assertions.*;
56

67
import org.junit.jupiter.api.BeforeEach;
78
import org.junit.jupiter.api.Test;
89

910
class EmployeeManagerTest {
1011

11-
public EmployeeManager manager;
12-
public Employee emp;
12+
private EmployeeManager employeeManager;
13+
private Employee employee;
1314

1415
@BeforeEach
15-
public void setUp() {
16-
manager = new EmployeeManager();
17-
emp = new Employee(1, "Edgar Allen Poe", "Writer", 0.0);
16+
void setUp() {
17+
employeeManager = new EmployeeManager();
18+
employee = new Employee(1, "Edgar Allen Poe", "Publications", 0.0);
19+
employeeManager.addEmployee(employee);
1820
}
1921

2022
@Test
21-
public void testAddEmployee() {
23+
void testAddEmployee() {
24+
// Arrange
25+
Employee newEmployee = new Employee(2, "Sheet Ghost", "Administration", 0.0);
2226
// Act
23-
manager.addEmployee(emp);
27+
employeeManager.addEmployee(newEmployee);
2428
// Assert
25-
assertEquals(1, manager.getEmployeeCount());
26-
assertEquals(emp, manager.getEmployee(1));
29+
assertThat(employeeManager.getEmployee(2)).isEqualTo(newEmployee);
2730
}
2831

2932
@Test
30-
public void testGetEmployee() {
31-
// Arrange
32-
manager.addEmployee(emp);
33-
Employee expectedValue = emp;
33+
void testGetEmployee() {
3434
// Act
35-
Employee actualValue = manager.getEmployee(1);
35+
Employee actualEmployee = employeeManager.getEmployee(1);
3636
// Assert
37-
assertEquals(expectedValue, actualValue, "The value retrieved should match the value added.");
37+
assertThat(actualEmployee).isEqualTo(employee);
3838
}
3939

4040
@Test
41-
public void testUpdateEmployee() {
41+
void testUpdateEmployee() {
4242
// Arrange
43-
manager.addEmployee(emp);
44-
Employee updatedEmployee = new Employee(1, "Frankenstein", "Admin", 0.0);
43+
Employee updatedEmployee = new Employee(1, "Frankenstein", "Development", 0.0);
4544
// Act
46-
manager.updateEmployee(updatedEmployee);
45+
employeeManager.updateEmployee(updatedEmployee);
46+
Employee actualEmployee = employeeManager.getEmployee(1);
4747
// Assert
48-
assertEquals(
49-
updatedEmployee,
50-
manager.getEmployee(1),
51-
"Updated employee details should match the new information.");
48+
assertThat(actualEmployee).isEqualTo(updatedEmployee);
5249
}
5350

5451
@Test
55-
public void testRemoveEmployee() {
56-
// Arrange
57-
manager.addEmployee(emp);
52+
void testRemoveEmployee() {
5853
// Act
59-
manager.removeEmployee(1);
60-
Employee removedEmployee = manager.getEmployee(1);
54+
employeeManager.removeEmployee(1);
55+
Employee removedEmployee = employeeManager.getEmployee(1);
6156
// Assert
62-
assertEquals(0, manager.getEmployeeCount(), "Employee count should be 0.");
63-
assertNull(removedEmployee, "Employee should be removed from system.");
57+
assertEquals(0, employeeManager.getEmployeeCount(), "Employee count should be 0");
58+
assertNull(removedEmployee, "Employee should be removed from directory.");
6459
}
6560

6661
@Test
67-
public void testAssertEmployeeInCollection() throws Exception {
68-
// Act
69-
assertThatThrownBy(() -> manager.getEmployee(1))
62+
void testAssertEmployeeInCollection() {
63+
// Arrange & Act & Assert
64+
assertThatThrownBy(() -> employeeManager.getEmployee(52))
7065
.isInstanceOf(IllegalArgumentException.class)
71-
.hasMessage("Employee does not in collection with id 1");
66+
.hasMessage("Employee does not exist in collection with Id 1");
67+
}
68+
69+
@Test
70+
void testGetEmployeeCount() {
71+
// Arrange
72+
Employee addNew1 = new Employee(2, "Dracula", "Medical", 0.0);
73+
Employee addNew2 = new Employee(3, "Blade", "Security", 0.0);
74+
// Act
75+
employeeManager.addEmployee(addNew1);
76+
employeeManager.addEmployee(addNew2);
77+
// Assert
78+
assertEquals(3, employeeManager.getEmployeeCount());
7279
}
7380
}

0 commit comments

Comments
 (0)