1

fixed GroupServiceTest for new Method in GroupService

This commit is contained in:
Mahgs
2020-03-11 13:52:26 +01:00
parent 31f19f0199
commit d102f9b0ee
4 changed files with 30 additions and 32 deletions

View File

@ -1,9 +1,11 @@
package mops.gruppen2.service;
import lombok.EqualsAndHashCode;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteGroupEvent;
import mops.gruppen2.domain.event.Event;
import org.springframework.stereotype.Service;
@ -21,22 +23,28 @@ public class GroupService {
this.eventService = eventService;
}
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) {
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) throws EventException {
for (Event event : events) {
if (event instanceof CreateGroupEvent) {
groupMap.put(event.getGroup_id(), new Group());
}
if (event instanceof DeleteGroupEvent) {
groupMap.remove(event.getGroup_id());
} else {
try {
Group group = groupMap.get(event.getGroup_id());
try {
Group group = groupMap.get(event.getGroup_id());
if (group == null) {
throw new GroupDoesNotExistException("Gruppe " + event.getGroup_id() + " existiert nicht");
}
if (group == null) {
throw new GroupDoesNotExistException("Gruppe " + event.getGroup_id() + " existiert nicht");
group.applyEvent(event);
} catch (EventException e) {
if (e instanceof GroupDoesNotExistException) {
throw e;
}
e.printStackTrace();
}
group.applyEvent(event);
} catch (EventException e) {
e.printStackTrace();
}
}
@ -44,7 +52,7 @@ public class GroupService {
return new ArrayList<>(groupMap.values());
}
public List<Group> projectEventList(List<Event> events) {
public List<Group> projectEventList(List<Event> events) throws EventException {
return projectEventList(new HashMap<>(), events);
}
}