diff --git a/lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15/EmployeeManager.java b/lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15/EmployeeManager.java index 66337295..4ac9edc4 100644 --- a/lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15/EmployeeManager.java +++ b/lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15/EmployeeManager.java @@ -4,7 +4,8 @@ import java.util.Map; public class EmployeeManager { - private Map employees; + + private final Map employees; public EmployeeManager() { employees = new HashMap<>(); @@ -15,17 +16,27 @@ public void addEmployee(Employee employee) { } public Employee getEmployee(int id) { + assertEmployeeInCollection(id); return employees.get(id); } public void updateEmployee(Employee employee) { + assertEmployeeInCollection(employee.getId()); employees.put(employee.getId(), employee); } public void removeEmployee(int id) { + assertEmployeeInCollection(id); employees.remove(id); } + private void assertEmployeeInCollection(int id) { + if (this.employees.containsKey(id)) { + return; + } + throw new IllegalArgumentException("Employee does not in collection with id " + id); + } + public int getEmployeeCount() { return employees.size(); }