|
7 | 7 |
|
8 | 8 | class Lesson15Test {
|
9 | 9 |
|
10 |
| - @Test |
11 |
| - public void testLesson15() { |
12 |
| - assertThat(new Lesson15()).isNotNull(); |
13 |
| - } |
14 |
| - |
15 |
| - @Test |
16 |
| - public void testGetGreeting() { |
17 |
| - // Act |
18 |
| - Lesson15.main(null); |
19 |
| - } |
20 |
| - |
21 |
| - @Test |
22 |
| - void testAddEmployee() { |
23 |
| - // Arrange |
24 |
| - EmployeeManager manager = new EmployeeManager(); |
25 |
| - Employee employee = new Employee(1, "Jane Doe", "Marketing", 65000.00); |
26 |
| - |
27 |
| - // Act |
28 |
| - manager.addEmployee(employee); |
29 |
| - Employee retrievedEmployee = manager.getEmployee(1); |
30 |
| - |
31 |
| - // Assert |
32 |
| - assertThat(retrievedEmployee).isNotNull(); |
33 |
| - assertThat(retrievedEmployee.getName()).isEqualTo("Jane Doe"); |
34 |
| - } |
35 |
| - |
36 |
| - @Test |
37 |
| - void testUpdateEmployee() { |
38 |
| - // Arrange |
39 |
| - EmployeeManager manager = new EmployeeManager(); |
40 |
| - Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
41 |
| - manager.addEmployee(employee); |
42 |
| - |
43 |
| - // Act |
44 |
| - employee.setName("John Smith"); |
45 |
| - manager.updateEmployee(employee); |
46 |
| - Employee updatedEmployee = manager.getEmployee(1); |
47 |
| - |
48 |
| - // Assert |
49 |
| - assertThat(updatedEmployee.getName()).isEqualTo("John Smith"); |
50 |
| - } |
51 |
| - |
52 |
| - @Test |
53 |
| - void testEmployeeCount() { |
54 |
| - // Arrange |
55 |
| - EmployeeManager manager = new EmployeeManager(); |
56 |
| - manager.addEmployee(new Employee(1, "John Doe", "Engineering", 75000.00)); |
57 |
| - manager.addEmployee(new Employee(2, "Jane Doe", "Marketing", 65000.00)); |
58 |
| - |
59 |
| - // Act |
60 |
| - int count = manager.getEmployeeCount(); |
61 |
| - |
62 |
| - // Assert |
63 |
| - assertThat(count).isEqualTo(2); |
64 |
| - } |
65 |
| - |
66 |
| - @Test |
67 |
| - void testRemoveEmployeeThrowsExceptionWhenNotFound() { |
68 |
| - // Arrange |
69 |
| - EmployeeManager manager = new EmployeeManager(); |
70 |
| - |
71 |
| - // Act & Assert |
72 |
| - assertThatThrownBy(() -> manager.removeEmployee(99)) |
73 |
| - .isInstanceOf(IllegalArgumentException.class) |
74 |
| - .hasMessageContaining("Employee does not in collection with id 99"); |
75 |
| - } |
76 |
| - |
77 |
| - @Test |
78 |
| - void testGetEmployeeThrowsExceptionWhenNotFound() { |
79 |
| - // Arrange |
80 |
| - EmployeeManager manager = new EmployeeManager(); |
81 |
| - |
82 |
| - // Act & Assert |
83 |
| - assertThatThrownBy(() -> manager.getEmployee(99)) |
84 |
| - .isInstanceOf(IllegalArgumentException.class) |
85 |
| - .hasMessageContaining("Employee does not in collection with id 99"); |
86 |
| - } |
87 |
| - |
88 |
| - @Test |
89 |
| - void testUpdateEmployeeThrowsExceptionWhenNotFound() { |
90 |
| - // Arrange |
91 |
| - EmployeeManager manager = new EmployeeManager(); |
92 |
| - Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
93 |
| - |
94 |
| - // Act & Assert |
95 |
| - assertThatThrownBy(() -> manager.updateEmployee(employee)) |
96 |
| - .isInstanceOf(IllegalArgumentException.class) |
97 |
| - .hasMessageContaining("Employee does not in collection with id 1"); |
98 |
| - } |
99 |
| - |
100 |
| - @Test |
101 |
| - void testEmployeeCreationAndDetails() { |
102 |
| - // Arrange |
103 |
| - Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
104 |
| - |
105 |
| - // Act |
106 |
| - String details = employee.getDetails(); |
107 |
| - |
108 |
| - // Assert |
109 |
| - assertThat(details).isEqualTo("ID: 1, Name: John Doe, Department: Engineering, Salary: 75000.0"); |
110 |
| - } |
111 |
| - |
112 |
| - @Test |
113 |
| - void testGetters() { |
114 |
| - // Arrange |
115 |
| - Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
116 |
| - |
117 |
| - // Act & Assert |
118 |
| - assertThat(employee.getId()).isEqualTo(1); |
119 |
| - assertThat(employee.getName()).isEqualTo("John Doe"); |
120 |
| - assertThat(employee.getDepartment()).isEqualTo("Engineering"); |
121 |
| - assertThat(employee.getSalary()).isEqualTo(75000.00); |
122 |
| - } |
123 |
| - |
124 |
| - @Test |
125 |
| - void testSetters() { |
126 |
| - // Arrange |
127 |
| - Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
128 |
| - |
129 |
| - // Act |
130 |
| - employee.setId(2); |
131 |
| - employee.setName("Jane Doe"); |
132 |
| - employee.setDepartment("Marketing"); |
133 |
| - employee.setSalary(65000.00); |
134 |
| - |
135 |
| - // Assert |
136 |
| - assertThat(employee.getId()).isEqualTo(2); |
137 |
| - assertThat(employee.getName()).isEqualTo("Jane Doe"); |
138 |
| - assertThat(employee.getDepartment()).isEqualTo("Marketing"); |
139 |
| - assertThat(employee.getSalary()).isEqualTo(65000.00); |
140 |
| - } |
| 10 | + @Test |
| 11 | + public void testLesson15() { |
| 12 | + assertThat(new Lesson15()).isNotNull(); |
| 13 | + } |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testGetGreeting() { |
| 17 | + // Act |
| 18 | + Lesson15.main(null); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + void testAddEmployee() { |
| 23 | + // Arrange |
| 24 | + EmployeeManager manager = new EmployeeManager(); |
| 25 | + Employee employee = new Employee(1, "Jane Doe", "Marketing", 65000.00); |
| 26 | + |
| 27 | + // Act |
| 28 | + manager.addEmployee(employee); |
| 29 | + Employee retrievedEmployee = manager.getEmployee(1); |
| 30 | + |
| 31 | + // Assert |
| 32 | + assertThat(retrievedEmployee).isNotNull(); |
| 33 | + assertThat(retrievedEmployee.getName()).isEqualTo("Jane Doe"); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void testUpdateEmployee() { |
| 38 | + // Arrange |
| 39 | + EmployeeManager manager = new EmployeeManager(); |
| 40 | + Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
| 41 | + manager.addEmployee(employee); |
| 42 | + |
| 43 | + // Act |
| 44 | + employee.setName("John Smith"); |
| 45 | + manager.updateEmployee(employee); |
| 46 | + Employee updatedEmployee = manager.getEmployee(1); |
| 47 | + |
| 48 | + // Assert |
| 49 | + assertThat(updatedEmployee.getName()).isEqualTo("John Smith"); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void testEmployeeCount() { |
| 54 | + // Arrange |
| 55 | + EmployeeManager manager = new EmployeeManager(); |
| 56 | + manager.addEmployee(new Employee(1, "John Doe", "Engineering", 75000.00)); |
| 57 | + manager.addEmployee(new Employee(2, "Jane Doe", "Marketing", 65000.00)); |
| 58 | + |
| 59 | + // Act |
| 60 | + int count = manager.getEmployeeCount(); |
| 61 | + |
| 62 | + // Assert |
| 63 | + assertThat(count).isEqualTo(2); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + void testRemoveEmployeeThrowsExceptionWhenNotFound() { |
| 68 | + // Arrange |
| 69 | + EmployeeManager manager = new EmployeeManager(); |
| 70 | + |
| 71 | + // Act & Assert |
| 72 | + assertThatThrownBy(() -> manager.removeEmployee(99)) |
| 73 | + .isInstanceOf(IllegalArgumentException.class) |
| 74 | + .hasMessageContaining("Employee does not in collection with id 99"); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void testGetEmployeeThrowsExceptionWhenNotFound() { |
| 79 | + // Arrange |
| 80 | + EmployeeManager manager = new EmployeeManager(); |
| 81 | + |
| 82 | + // Act & Assert |
| 83 | + assertThatThrownBy(() -> manager.getEmployee(99)) |
| 84 | + .isInstanceOf(IllegalArgumentException.class) |
| 85 | + .hasMessageContaining("Employee does not in collection with id 99"); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + void testUpdateEmployeeThrowsExceptionWhenNotFound() { |
| 90 | + // Arrange |
| 91 | + EmployeeManager manager = new EmployeeManager(); |
| 92 | + Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
| 93 | + |
| 94 | + // Act & Assert |
| 95 | + assertThatThrownBy(() -> manager.updateEmployee(employee)) |
| 96 | + .isInstanceOf(IllegalArgumentException.class) |
| 97 | + .hasMessageContaining("Employee does not in collection with id 1"); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + void testEmployeeCreationAndDetails() { |
| 102 | + // Arrange |
| 103 | + Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
| 104 | + |
| 105 | + // Act |
| 106 | + String details = employee.getDetails(); |
| 107 | + |
| 108 | + // Assert |
| 109 | + assertThat(details) |
| 110 | + .isEqualTo("ID: 1, Name: John Doe, Department: Engineering, Salary: 75000.0"); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + void testGetters() { |
| 115 | + // Arrange |
| 116 | + Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
| 117 | + |
| 118 | + // Act & Assert |
| 119 | + assertThat(employee.getId()).isEqualTo(1); |
| 120 | + assertThat(employee.getName()).isEqualTo("John Doe"); |
| 121 | + assertThat(employee.getDepartment()).isEqualTo("Engineering"); |
| 122 | + assertThat(employee.getSalary()).isEqualTo(75000.00); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + void testSetters() { |
| 127 | + // Arrange |
| 128 | + Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00); |
| 129 | + |
| 130 | + // Act |
| 131 | + employee.setId(2); |
| 132 | + employee.setName("Jane Doe"); |
| 133 | + employee.setDepartment("Marketing"); |
| 134 | + employee.setSalary(65000.00); |
| 135 | + |
| 136 | + // Assert |
| 137 | + assertThat(employee.getId()).isEqualTo(2); |
| 138 | + assertThat(employee.getName()).isEqualTo("Jane Doe"); |
| 139 | + assertThat(employee.getDepartment()).isEqualTo("Marketing"); |
| 140 | + assertThat(employee.getSalary()).isEqualTo(65000.00); |
| 141 | + } |
141 | 142 | }
|
0 commit comments