fixed GroupServiceTest for new Method in GroupService
This commit is contained in:
@ -77,8 +77,4 @@ public class Group extends Aggregate {
|
|||||||
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyEvent(DeleteGroupEvent event) {
|
|
||||||
this.id = this.id * -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
|
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -21,12 +23,14 @@ public class GroupService {
|
|||||||
this.eventService = eventService;
|
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) {
|
for (Event event : events) {
|
||||||
if (event instanceof CreateGroupEvent) {
|
if (event instanceof CreateGroupEvent) {
|
||||||
groupMap.put(event.getGroup_id(), new Group());
|
groupMap.put(event.getGroup_id(), new Group());
|
||||||
}
|
}
|
||||||
|
if (event instanceof DeleteGroupEvent) {
|
||||||
|
groupMap.remove(event.getGroup_id());
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
Group group = groupMap.get(event.getGroup_id());
|
Group group = groupMap.get(event.getGroup_id());
|
||||||
|
|
||||||
@ -36,15 +40,19 @@ public class GroupService {
|
|||||||
|
|
||||||
group.applyEvent(event);
|
group.applyEvent(event);
|
||||||
} catch (EventException e) {
|
} catch (EventException e) {
|
||||||
|
if (e instanceof GroupDoesNotExistException) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<>(groupMap.values());
|
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);
|
return projectEventList(new HashMap<>(), events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package mops.gruppen2.domain;
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
|
||||||
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
|
|||||||
@ -10,18 +10,23 @@ import mops.gruppen2.domain.event.Event;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.configuration.IMockitoConfiguration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
class GroupServiceTest {
|
class GroupServiceTest {
|
||||||
GroupService groupService = new GroupService();
|
GroupService groupService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
groupService = new GroupService(mock(EventService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -36,7 +41,7 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
|
|
||||||
Assertions.assertThrows(GroupDoesNotExistException.class, () -> {
|
Assertions.assertThrows(GroupDoesNotExistException.class, () -> {
|
||||||
groupService.buildGroupFromEvents(eventList);
|
groupService.projectEventList(eventList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,30 +53,20 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
||||||
|
|
||||||
assertThat(groupService.buildGroupFromEvents(eventList)).isEqualTo(null);
|
List<Group> list = new ArrayList<>();
|
||||||
|
|
||||||
|
assertThat(groupService.projectEventList(eventList)).isEqualTo(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void firstEventNotCreateGroup() throws Exception {
|
void rightClassForSucsessfulGroup() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
|
||||||
|
|
||||||
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
|
||||||
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
|
||||||
|
|
||||||
Assertions.assertThrows(GroupDoesNotExistException.class, () -> {
|
|
||||||
groupService.buildGroupFromEvents(eventList);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void sucsessfullReturnGroup() throws Exception {
|
|
||||||
List<Event> eventList = new ArrayList<>();
|
List<Event> eventList = new ArrayList<>();
|
||||||
|
|
||||||
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
||||||
|
|
||||||
eventList.add(new AddUserEvent(900L, 10L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
eventList.add(new AddUserEvent(900L, 10L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||||
|
|
||||||
assertThat(groupService.buildGroupFromEvents(eventList)).isInstanceOf(Group.class);
|
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user