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 4
4
import java .util .Map ;
5
5
6
6
public class EmployeeManager {
7
- private Map <Integer , Employee > employees ;
7
+
8
+ private final Map <Integer , Employee > employees ;
8
9
9
10
public EmployeeManager () {
10
11
employees = new HashMap <>();
@@ -15,17 +16,27 @@ public void addEmployee(Employee employee) {
15
16
}
16
17
17
18
public Employee getEmployee (int id ) {
19
+ assertEmployeeInCollection (id );
18
20
return employees .get (id );
19
21
}
20
22
21
23
public void updateEmployee (Employee employee ) {
24
+ assertEmployeeInCollection (employee .getId ());
22
25
employees .put (employee .getId (), employee );
23
26
}
24
27
25
28
public void removeEmployee (int id ) {
29
+ assertEmployeeInCollection (id );
26
30
employees .remove (id );
27
31
}
28
32
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
+
29
40
public int getEmployeeCount () {
30
41
return employees .size ();
31
42
}
You can’t perform that action at this time.
0 commit comments