From a20bc89fc6c1101b565b9b13499787f7b3a08c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Fri, 16 Oct 2020 16:13:40 +0200 Subject: [PATCH] Added GetCourseGroupsResponse(-Test) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .../models/GetCourseGroupsResponse.java | 32 +++++++++++++++++++ .../models/GetCourseGroupResponseTest.java | 24 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 restservice/src/main/java/com/plannaplan/responses/models/GetCourseGroupsResponse.java create mode 100644 restservice/src/test/java/com/plannaplan/responses/models/GetCourseGroupResponseTest.java diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GetCourseGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GetCourseGroupsResponse.java new file mode 100644 index 0000000..41387e0 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/GetCourseGroupsResponse.java @@ -0,0 +1,32 @@ +package com.plannaplan.responses.models; + +import java.util.ArrayList; +import java.util.List; + +import com.plannaplan.entities.Groups; +import com.plannaplan.types.GroupType; + +public class GetCourseGroupsResponse { + + private List lectures = new ArrayList<>(); + private List classes = new ArrayList<>(); + + public GetCourseGroupsResponse(List groups ){ + groups.stream().forEach(group -> { + if (group.getType() == GroupType.CLASS) { + this.classes.add(new DefaultGroupResponse(group)); + } else { + this.lectures.add(new DefaultGroupResponse(group)); + } + }); + } + + public List getClasses() { + return this.classes; + } + + public List getLectures() { + return this.lectures; + } + +} \ No newline at end of file diff --git a/restservice/src/test/java/com/plannaplan/responses/models/GetCourseGroupResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/GetCourseGroupResponseTest.java new file mode 100644 index 0000000..06bf282 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/responses/models/GetCourseGroupResponseTest.java @@ -0,0 +1,24 @@ +package com.plannaplan.responses.models; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import com.plannaplan.entities.Groups; +import com.plannaplan.types.WeekDay; + +import org.junit.Test; + +public class GetCourseGroupResponseTest { + + @Test + public void shouldMapListGroupsToResponse() { + final List groups = Arrays.asList(new Groups(32,"A1-1", null, 480, WeekDay.MONDAY, null), new Groups(150,"A1-2", null, 500, WeekDay.THURSDAY, null)); + + final GetCourseGroupsResponse response = new GetCourseGroupsResponse(groups); + assertTrue(response.getClasses().size() == 1); + assertTrue(response.getLectures().size() == 1); + } + +}