mapToGetCourseGroupsDefaultResponse overloaded
This commit is contained in:
parent
25e9571a06
commit
082b30133c
@ -33,9 +33,6 @@ public class GroupsMappers {
|
|||||||
|
|
||||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups,
|
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups,
|
||||||
HashMap<Long, Integer> taken) {
|
HashMap<Long, Integer> taken) {
|
||||||
// return
|
|
||||||
// groups.stream().filter(Objects::nonNull).map(GroupWithCapacityResponse::new)
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupWithCapacityResponse>() {
|
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupWithCapacityResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public GroupWithCapacityResponse apply(Groups p) {
|
public GroupWithCapacityResponse apply(Groups p) {
|
||||||
@ -53,22 +50,35 @@ public class GroupsMappers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||||
List<Groups> groups) {
|
List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||||
|
|
||||||
List<GroupDefaultResponse> lectures = new ArrayList<>();
|
List<GroupDefaultResponse> lectures = new ArrayList<>();
|
||||||
List<GroupDefaultResponse> classes = new ArrayList<>();
|
List<GroupDefaultResponse> classes = new ArrayList<>();
|
||||||
|
|
||||||
groups.stream().forEach(group -> {
|
groups.stream().forEach(group -> {
|
||||||
if (group.getType() == GroupType.CLASS) {
|
if (group.getType() == GroupType.CLASS) {
|
||||||
|
if (taken != null) {
|
||||||
|
classes.add(new GroupDefaultResponse(group, taken.get(group.getId())));
|
||||||
|
} else {
|
||||||
classes.add(new GroupDefaultResponse(group));
|
classes.add(new GroupDefaultResponse(group));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (taken != null) {
|
||||||
|
lectures.add(new GroupDefaultResponse(group, taken.get(group.getId())));
|
||||||
} else {
|
} else {
|
||||||
lectures.add(new GroupDefaultResponse(group));
|
lectures.add(new GroupDefaultResponse(group));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return new CourseWithGroupsResponse<>(classes, lectures);
|
return new CourseWithGroupsResponse<>(classes, lectures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||||
|
List<Groups> groups) {
|
||||||
|
return GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
||||||
List<Groups> groups) {
|
List<Groups> groups) {
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import org.junit.Test;
|
|||||||
public class GroupsMappersTest {
|
public class GroupsMappersTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldMapToResponseIncludingCapacity() {
|
public void shouldMapToResponseIncludingCapacity() {
|
||||||
final List<Groups> gropus = Arrays.asList(
|
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||||
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
|
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
|
||||||
|
|
||||||
assert (response.get(0).getCapacity() == 42);
|
assert (response.get(0).getCapacity() == 42);
|
||||||
@ -30,8 +30,8 @@ public class GroupsMappersTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMapToResponseWiothoutCapacity() {
|
public void shouldMapToResponseWiothoutCapacity() {
|
||||||
final List<Groups> gropus = Arrays.asList(
|
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||||
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
|
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
|
||||||
|
|
||||||
assert (response.get(0) instanceof GroupDefaultResponse);
|
assert (response.get(0) instanceof GroupDefaultResponse);
|
||||||
@ -41,8 +41,10 @@ public class GroupsMappersTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldMapToGetCourseGroupsResponse() {
|
public void shouldMapToGetCourseGroupsResponse() {
|
||||||
final List<Groups> groups = Arrays.asList(
|
final List<Groups> groups = Arrays.asList(
|
||||||
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
||||||
|
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
|
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||||
|
|
||||||
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
||||||
.mapToGetCourseGroupsDefaultResponse(groups);
|
.mapToGetCourseGroupsDefaultResponse(groups);
|
||||||
@ -53,8 +55,35 @@ public class GroupsMappersTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMapToDefaultResponseWithTakenPlace()
|
public void shouldMapToGetCourseGroupsResponseWithTakenPlaces() throws NoSuchFieldException, SecurityException,
|
||||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
IllegalArgumentException, IllegalAccessException {
|
||||||
|
final Field reader = Groups.class.getDeclaredField("id");
|
||||||
|
reader.setAccessible(true);
|
||||||
|
|
||||||
|
final List<Groups> groups = Arrays.asList(
|
||||||
|
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
|
new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
||||||
|
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||||
|
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||||
|
reader.set(groups.get(0), Long.valueOf(0));
|
||||||
|
reader.set(groups.get(1), Long.valueOf(1));
|
||||||
|
|
||||||
|
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||||
|
placeMap.put(Long.valueOf(0), 0);
|
||||||
|
placeMap.put(Long.valueOf(1), 21);
|
||||||
|
|
||||||
|
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
||||||
|
.mapToGetCourseGroupsDefaultResponse(groups, placeMap);
|
||||||
|
|
||||||
|
assertTrue(response.getClasses().size() == 1);
|
||||||
|
assertTrue(response.getLectures().size() == 1);
|
||||||
|
assertTrue(response.getLectures().get(0).getTakenPlaces() == 0);
|
||||||
|
assertTrue(response.getClasses().get(0).getTakenPlaces() == 21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldMapToDefaultResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
|
||||||
|
IllegalArgumentException, IllegalAccessException {
|
||||||
final Field reader = Groups.class.getDeclaredField("id");
|
final Field reader = Groups.class.getDeclaredField("id");
|
||||||
reader.setAccessible(true);
|
reader.setAccessible(true);
|
||||||
|
|
||||||
@ -79,8 +108,8 @@ public class GroupsMappersTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMapToCapacityResponseWithTakenPlace()
|
public void shouldMapToCapacityResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
|
||||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
IllegalArgumentException, IllegalAccessException {
|
||||||
final Field reader = Groups.class.getDeclaredField("id");
|
final Field reader = Groups.class.getDeclaredField("id");
|
||||||
reader.setAccessible(true);
|
reader.setAccessible(true);
|
||||||
|
|
||||||
@ -96,8 +125,8 @@ public class GroupsMappersTest {
|
|||||||
placeMap.put(Long.valueOf(0), 5);
|
placeMap.put(Long.valueOf(0), 5);
|
||||||
placeMap.put(Long.valueOf(1), 56);
|
placeMap.put(Long.valueOf(1), 56);
|
||||||
|
|
||||||
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(List.of(group1, group2),
|
final List<GroupWithCapacityResponse> response = GroupsMappers
|
||||||
placeMap);
|
.mapToCapacityResponse(List.of(group1, group2), placeMap);
|
||||||
|
|
||||||
assertTrue(response.size() == 2);
|
assertTrue(response.size() == 2);
|
||||||
assertTrue(response.get(0).getTakenPlaces() == 5);
|
assertTrue(response.get(0).getTakenPlaces() == 5);
|
||||||
|
Loading…
Reference in New Issue
Block a user