File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
lesson_15/tdd/tdd_app/src/main/java/com/codedifferently/lesson15 Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 44import java .util .Map ;
55
66public class EmployeeManager {
7- private Map <Integer , Employee > employees ;
7+
8+ private final Map <Integer , Employee > employees ;
89
910 public EmployeeManager () {
1011 employees = new HashMap <>();
@@ -15,17 +16,27 @@ public void addEmployee(Employee employee) {
1516 }
1617
1718 public Employee getEmployee (int id ) {
19+ assertEmployeeInCollection (id );
1820 return employees .get (id );
1921 }
2022
2123 public void updateEmployee (Employee employee ) {
24+ assertEmployeeInCollection (employee .getId ());
2225 employees .put (employee .getId (), employee );
2326 }
2427
2528 public void removeEmployee (int id ) {
29+ assertEmployeeInCollection (id );
2630 employees .remove (id );
2731 }
2832
33+ private void assertEmployeeInCollection (int id ) {
34+ if (this .employees .containsKey (id )) {
35+ return ;
36+ }
37+ throw new IllegalArgumentException ("Employee does not in collection with id " + id );
38+ }
39+
2940 public int getEmployeeCount () {
3041 return employees .size ();
3142 }
You can’t perform that action at this time.
0 commit comments