1

Merge pull request #57 from hhu-propra2/GroupLogicProjection

Group logic projection
This commit is contained in:
Talha Caliskan
2020-03-11 14:04:23 +01:00
committed by GitHub
6 changed files with 69 additions and 66 deletions

View File

@ -21,7 +21,7 @@ public class EventBuilder {
);
}
public static AddUserEvent randomAddUserEvent() {
public static AddUserEvent randomAddUserEvent(long group_id) {
Faker faker = new Faker();
String firstname = faker.name().firstName();
@ -29,7 +29,7 @@ public class EventBuilder {
return new AddUserEvent(
faker.random().nextLong(),
faker.random().nextLong(),
group_id,
faker.random().hex(),
firstname,
lastname,
@ -37,11 +37,11 @@ public class EventBuilder {
);
}
public static List<Event> randomAddUserEvents(int count) {
public static List<Event> randomAddUserEvents(int count, long group_id) {
List<Event> eventList = new ArrayList<>();
for (int i = 0; i < count; i++) {
eventList.add(EventBuilder.randomAddUserEvent());
eventList.add(EventBuilder.randomAddUserEvent(group_id));
}
return eventList;

View File

@ -1,6 +1,5 @@
package mops.gruppen2.domain;
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
import mops.gruppen2.domain.event.*;
@ -154,17 +153,4 @@ class GroupTest {
assertThat(group.getDescription()).isEqualTo("Tolle Beschreibung");
}
@Test
void deleteGroup() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(44, 1, "loescher78");
group.applyEvent(deleteGroupEvent);
assertThat(group.id).isEqualTo(-1L);
}
}

View File

@ -10,18 +10,23 @@ import mops.gruppen2.domain.event.Event;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.configuration.IMockitoConfiguration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
class GroupServiceTest {
GroupService groupService = new GroupService();
GroupService groupService;
@BeforeEach
public void setUp() {
groupService = new GroupService(mock(EventService.class));
}
@Test
@ -36,7 +41,7 @@ class GroupServiceTest {
Assertions.assertThrows(GroupDoesNotExistException.class, () -> {
groupService.buildGroupFromEvents(eventList);
groupService.projectEventList(eventList);
});
}
@ -48,30 +53,20 @@ class GroupServiceTest {
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
void firstEventNotCreateGroup() 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 {
void rightClassForSucsessfulGroup() throws Exception {
List<Event> eventList = new ArrayList<>();
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
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);
}
}