11package com .codedifferently .lesson15 ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
54
65import org .junit .jupiter .api .Test ;
76
@@ -17,126 +16,4 @@ public void testGetGreeting() {
1716 // Act
1817 Lesson15 .main (null );
1918 }
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- }
14219}
0 commit comments