Skip to content

Commit fd9ad19

Browse files
committed
fix: created separate test files
1 parent e174339 commit fd9ad19

File tree

3 files changed

+137
-123
lines changed

3 files changed

+137
-123
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.codedifferently.lesson15;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class EmployeeManagerTest {
9+
@Test
10+
void testAddEmployee() {
11+
// Arrange
12+
EmployeeManager manager = new EmployeeManager();
13+
Employee employee = new Employee(1, "Jane Doe", "Marketing", 65000.00);
14+
15+
// Act
16+
manager.addEmployee(employee);
17+
Employee retrievedEmployee = manager.getEmployee(1);
18+
19+
// Assert
20+
assertThat(retrievedEmployee).isNotNull();
21+
assertThat(retrievedEmployee.getName()).isEqualTo("Jane Doe");
22+
}
23+
24+
@Test
25+
void testUpdateEmployee() {
26+
// Arrange
27+
EmployeeManager manager = new EmployeeManager();
28+
Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00);
29+
manager.addEmployee(employee);
30+
31+
// Act
32+
employee.setName("John Smith");
33+
manager.updateEmployee(employee);
34+
Employee updatedEmployee = manager.getEmployee(1);
35+
36+
// Assert
37+
assertThat(updatedEmployee.getName()).isEqualTo("John Smith");
38+
}
39+
40+
@Test
41+
void testEmployeeCount() {
42+
// Arrange
43+
EmployeeManager manager = new EmployeeManager();
44+
manager.addEmployee(new Employee(1, "John Doe", "Engineering", 75000.00));
45+
manager.addEmployee(new Employee(2, "Jane Doe", "Marketing", 65000.00));
46+
47+
// Act
48+
int count = manager.getEmployeeCount();
49+
50+
// Assert
51+
assertThat(count).isEqualTo(2);
52+
}
53+
54+
@Test
55+
void testRemoveEmployeeThrowsExceptionWhenNotFound() {
56+
// Arrange
57+
EmployeeManager manager = new EmployeeManager();
58+
59+
// Act & Assert
60+
assertThatThrownBy(() -> manager.removeEmployee(99))
61+
.isInstanceOf(IllegalArgumentException.class)
62+
.hasMessageContaining("Employee does not in collection with id 99");
63+
}
64+
65+
@Test
66+
void testGetEmployeeThrowsExceptionWhenNotFound() {
67+
// Arrange
68+
EmployeeManager manager = new EmployeeManager();
69+
70+
// Act & Assert
71+
assertThatThrownBy(() -> manager.getEmployee(99))
72+
.isInstanceOf(IllegalArgumentException.class)
73+
.hasMessageContaining("Employee does not in collection with id 99");
74+
}
75+
76+
@Test
77+
void testUpdateEmployeeThrowsExceptionWhenNotFound() {
78+
// Arrange
79+
EmployeeManager manager = new EmployeeManager();
80+
Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00);
81+
82+
// Act & Assert
83+
assertThatThrownBy(() -> manager.updateEmployee(employee))
84+
.isInstanceOf(IllegalArgumentException.class)
85+
.hasMessageContaining("Employee does not in collection with id 1");
86+
}
87+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.codedifferently.lesson15;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class EmployeeTest {
8+
@Test
9+
void testEmployeeCreationAndDetails() {
10+
// Arrange
11+
Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00);
12+
13+
// Act
14+
String details = employee.getDetails();
15+
16+
// Assert
17+
assertThat(details)
18+
.isEqualTo("ID: 1, Name: John Doe, Department: Engineering, Salary: 75000.0");
19+
}
20+
21+
@Test
22+
void testGetters() {
23+
// Arrange
24+
Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00);
25+
26+
// Act & Assert
27+
assertThat(employee.getId()).isEqualTo(1);
28+
assertThat(employee.getName()).isEqualTo("John Doe");
29+
assertThat(employee.getDepartment()).isEqualTo("Engineering");
30+
assertThat(employee.getSalary()).isEqualTo(75000.00);
31+
}
32+
33+
@Test
34+
void testSetters() {
35+
// Arrange
36+
Employee employee = new Employee(1, "John Doe", "Engineering", 75000.00);
37+
38+
// Act
39+
employee.setId(2);
40+
employee.setName("Jane Doe");
41+
employee.setDepartment("Marketing");
42+
employee.setSalary(65000.00);
43+
44+
// Assert
45+
assertThat(employee.getId()).isEqualTo(2);
46+
assertThat(employee.getName()).isEqualTo("Jane Doe");
47+
assertThat(employee.getDepartment()).isEqualTo("Marketing");
48+
assertThat(employee.getSalary()).isEqualTo(65000.00);
49+
}
50+
}
Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.codedifferently.lesson15;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54

65
import 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

Comments
 (0)