|
9 | 9 | public class EmployeeManagerTest {
|
10 | 10 | EmployeeManager employeeManager;
|
11 | 11 | Employee employee;
|
| 12 | + Employee employee2; |
12 | 13 |
|
13 | 14 | @BeforeEach
|
14 | 15 | void setUp() {
|
15 | 16 | employeeManager = new EmployeeManager();
|
16 |
| - employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
17 |
| - employeeManager.addEmployee(employee); |
18 | 17 | }
|
19 | 18 |
|
20 | 19 | @Test
|
21 | 20 | void testAddEmployee() {
|
22 |
| - assertThat(employeeManager.getEmployee(999)).isEqualTo(employee); |
| 21 | + employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
| 22 | + employeeManager.addEmployee(employee); |
| 23 | + assertThat(employeeManager.getEmployeeCount()).isEqualTo(1); |
23 | 24 | }
|
24 | 25 |
|
25 | 26 | @Test
|
26 | 27 | void testGetEmployee() {
|
| 28 | + employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
| 29 | + employeeManager.addEmployee(employee); |
27 | 30 | assertThat(employeeManager.getEmployee(999)).isEqualTo(employee);
|
28 | 31 | }
|
29 | 32 |
|
30 | 33 | @Test
|
31 | 34 | void testGetEmployee_failedDueToNull() throws RuntimeException {
|
32 | 35 | assertThatThrownBy(() -> employeeManager.getEmployee(9))
|
33 |
| - .isInstanceOf(NullPointerException.class) |
34 |
| - .hasMessage("Employee with id 9 not found"); |
| 36 | + .isInstanceOf(IllegalArgumentException.class) |
| 37 | + .hasMessage("Employee does not in collection with id 9"); |
35 | 38 | }
|
36 | 39 |
|
37 | 40 | @Test
|
38 | 41 | void testEmployeeUpdate() {
|
39 |
| - Employee employee2 = new Employee(99, "Angelica", "CodeDifferently", 900.55); |
| 42 | + employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
| 43 | + employeeManager.addEmployee(employee); |
| 44 | + employee2 = new Employee(99, "Angelica", "CodeDifferently", 900.55); |
40 | 45 | employeeManager.addEmployee(employee2);
|
41 | 46 | employeeManager.updateEmployee(employee2);
|
42 | 47 | assertThat(employeeManager.getEmployeeCount()).isEqualTo(2);
|
43 | 48 | }
|
44 | 49 |
|
45 | 50 | @Test
|
46 | 51 | void testRemoveEmployee() throws RuntimeException {
|
| 52 | + employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
| 53 | + employeeManager.addEmployee(employee); |
47 | 54 | employeeManager.removeEmployee(999);
|
48 | 55 | assertThat(employeeManager.getEmployeeCount()).isEqualTo(0);
|
49 | 56 | }
|
50 | 57 |
|
51 | 58 | @Test
|
52 | 59 | void testRemoveEmployee_errorFromNullEmployeeId() throws RuntimeException {
|
53 | 60 | assertThatThrownBy(() -> employeeManager.removeEmployee(9))
|
54 |
| - .isInstanceOf(NullPointerException.class) |
55 |
| - .hasMessage("Employee with id 9 not found"); |
56 |
| - } |
57 |
| - |
58 |
| - @Test |
59 |
| - void testGetEmployeeCount_whenNoEmployeesAreInMap() { |
60 |
| - employeeManager.removeEmployee(999); |
61 |
| - assertThat(employeeManager.getEmployeeCount()).isEqualTo(0); |
| 61 | + .isInstanceOf(IllegalArgumentException.class) |
| 62 | + .hasMessage("Employee does not in collection with id 9"); |
62 | 63 | }
|
63 | 64 |
|
64 | 65 | @Test
|
65 | 66 | void testGetEmployeeCount_whenOneEmployeeIsInTheMap() {
|
| 67 | + employee = new Employee(999, "Joseph", "Boxing", 150000000.5); |
| 68 | + employeeManager.addEmployee(employee); |
66 | 69 | assertThat(employeeManager.getEmployeeCount()).isEqualTo(1);
|
67 | 70 | }
|
68 | 71 | }
|
0 commit comments