Skip to content

Commit 4604aff

Browse files
committed
feat: updated lesson15 unit test HW to handle exception case by Yemi
1 parent b6c43af commit 4604aff

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

lesson_15/tdd/tdd_app/src/test/java/EmployeeManagerTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
12
import static org.junit.jupiter.api.Assertions.assertEquals;
2-
import static org.junit.jupiter.api.Assertions.assertNull;
33

44
import com.codedifferently.lesson15.Employee;
55
import com.codedifferently.lesson15.EmployeeManager;
@@ -30,40 +30,44 @@ public void testAddEmployee() {
3030
}
3131

3232
@Test
33-
public void testgetEmployee() {
33+
public void testUpdateEmployee() {
3434
// Arrange
35-
Employee employee = new Employee(2, "Washington", "Finance", 29.23);
35+
Employee employee = new Employee(5, "John", "Safety", 50);
36+
cut.addEmployee(employee);
3637

3738
// Act
38-
Employee returnedEmployee = cut.getEmployee(employee.getId());
39+
cut.updateEmployee(employee);
3940

4041
// Assert
41-
assertNull(returnedEmployee);
42+
int expectedId = 5;
43+
assertEquals(expectedId, employee.getId());
4244
}
4345

4446
@Test
4547
public void testRemoveEmployee() {
4648
// Arrange
47-
Employee employee = new Employee(3, "Belvedere", "Finance", 100.1);
48-
49+
Employee employee = new Employee(2, "Belvedere", "Finance", 100.1);
50+
cut.addEmployee(employee);
4951
// Act
5052
cut.removeEmployee(employee.getId());
5153

5254
// Assert
53-
int removedId = 3;
54-
assertNull(cut.getEmployee(removedId));
55+
int removedId = 2;
56+
assertThatThrownBy(() -> cut.removeEmployee(removedId))
57+
.isInstanceOf(IllegalArgumentException.class)
58+
.hasMessage("Employee does not in collection with id " + removedId);
5559
}
5660

5761
@Test
58-
public void testUpdateEmployee() {
62+
public void testGetEmployee() {
5963
// Arrange
60-
Employee employee = new Employee(5, "John", "Safety", 50);
61-
64+
Employee employee = new Employee(2, "Washington", "Finance", 29.23);
6265
// Act
63-
cut.updateEmployee(employee);
66+
cut.addEmployee(employee);
6467

68+
int employeeId = employee.getId();
69+
Employee returnedEmployee = cut.getEmployee(employeeId);
6570
// Assert
66-
int expectedId = 5;
67-
assertEquals(expectedId, employee.getId());
71+
assertEquals(employee, returnedEmployee);
6872
}
69-
}
73+
}

lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/EmployeeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testGetSalary() {
6161
double expectedSalary = cut.getSalary();
6262

6363
// Assert
64-
double actualSalary = cut.getSalary();
64+
double actualSalary = 200.00;
6565
assertEquals(expectedSalary, actualSalary, "The Salary should be '200.00'");
6666
}
6767

0 commit comments

Comments
 (0)