1

added deserialization tests

This commit is contained in:
Christoph
2020-03-10 16:29:28 +01:00
parent d229b2089a
commit 2f4af867e8
2 changed files with 9 additions and 39 deletions

View File

@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -20,41 +21,6 @@ public class GroupService {
this.eventService = eventService;
}
/**
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
*
* @param eventList Die restlichen Events für diese Gruppe
* @return Gruppe auf aktuellem Stand
*/
Group buildGroupFromEvents(List<Event> eventList) throws EventException {
Group newGroup = new Group();
try {
if (!(eventList.get(0) instanceof CreateGroupEvent)) {
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
} else {
newGroup.applyEvent(eventList.get(0));
eventList.remove(0);
}
for (Event event : eventList) {
if (!(newGroup.getId() > 0)) {
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
}
newGroup.applyEvent(event);
}
} catch (EventException e) {
if (e instanceof GroupDoesNotExistException) {
throw e;
}
e.printStackTrace();
}
if (newGroup.getId() < 0) {
return null;
}
return newGroup;
}
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) {
for (Event event : events) {
if (event instanceof CreateGroupEvent) {
@ -77,4 +43,8 @@ public class GroupService {
return new ArrayList<>(groupMap.values());
}
public List<Group> projectEventList(List<Event> events) {
return projectEventList(new HashMap<>(), events);
}
}