mapToGetCourseGroupsDefaultResponse overloaded

This commit is contained in:
BuildTools
2020-11-30 13:10:40 +01:00
parent 25e9571a06
commit 082b30133c
2 changed files with 114 additions and 75 deletions

View File

@ -17,93 +17,122 @@ import com.plannaplan.types.WeekDay;
import org.junit.Test;
public class GroupsMappersTest {
@Test
public void shouldMapToResponseIncludingCapacity() {
final List<Groups> gropus = Arrays.asList(
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
@Test
public void shouldMapToResponseIncludingCapacity() {
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki")));
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
assert (response.get(0).getCapacity() == 42);
assert (response.get(0) instanceof GroupWithCapacityResponse);
assert (response.size() == 1);
}
assert (response.get(0).getCapacity() == 42);
assert (response.get(0) instanceof GroupWithCapacityResponse);
assert (response.size() == 1);
}
@Test
public void shouldMapToResponseWiothoutCapacity() {
final List<Groups> gropus = Arrays.asList(
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
@Test
public void shouldMapToResponseWiothoutCapacity() {
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki")));
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
assert (response.get(0) instanceof GroupDefaultResponse);
assert (response.size() == 1);
}
assert (response.get(0) instanceof GroupDefaultResponse);
assert (response.size() == 1);
}
@Test
public void shouldMapToGetCourseGroupsResponse() {
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")));
@Test
public void shouldMapToGetCourseGroupsResponse() {
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")));
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
.mapToGetCourseGroupsDefaultResponse(groups);
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
.mapToGetCourseGroupsDefaultResponse(groups);
assertTrue(response.getClasses().size() == 1);
assertTrue(response.getLectures().size() == 1);
assertTrue(response.getClasses().size() == 1);
assertTrue(response.getLectures().size() == 1);
}
}
@Test
public void shouldMapToDefaultResponseWithTakenPlace()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
@Test
public void shouldMapToGetCourseGroupsResponseWithTakenPlaces() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
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));
reader.set(group1, Long.valueOf(0));
reader.set(group2, Long.valueOf(1));
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 0);
placeMap.put(Long.valueOf(1), 21);
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 5);
placeMap.put(Long.valueOf(1), 56);
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
.mapToGetCourseGroupsDefaultResponse(groups, placeMap);
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(List.of(group1, group2),
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);
}
assertTrue(response.size() == 2);
assertTrue(response.get(0).getTakenPlaces() == 5);
assertTrue(response.get(1).getTakenPlaces() == 56);
}
@Test
public void shouldMapToDefaultResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
@Test
public void shouldMapToCapacityResponseWithTakenPlace()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
reader.set(group1, Long.valueOf(0));
reader.set(group2, Long.valueOf(1));
reader.set(group1, Long.valueOf(0));
reader.set(group2, Long.valueOf(1));
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 5);
placeMap.put(Long.valueOf(1), 56);
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 5);
placeMap.put(Long.valueOf(1), 56);
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(List.of(group1, group2),
placeMap);
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(List.of(group1, group2),
placeMap);
assertTrue(response.size() == 2);
assertTrue(response.get(0).getTakenPlaces() == 5);
assertTrue(response.get(1).getTakenPlaces() == 56);
}
assertTrue(response.size() == 2);
assertTrue(response.get(0).getTakenPlaces() == 5);
assertTrue(response.get(0).getCapacity() == 150);
assertTrue(response.get(1).getTakenPlaces() == 56);
assertTrue(response.get(1).getCapacity() == 24);
}
@Test
public void shouldMapToCapacityResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
final Field reader = Groups.class.getDeclaredField("id");
reader.setAccessible(true);
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
new Lecturer("krul.", "Wladyslaw", "Potocki"));
reader.set(group1, Long.valueOf(0));
reader.set(group2, Long.valueOf(1));
final HashMap<Long, Integer> placeMap = new HashMap<>();
placeMap.put(Long.valueOf(0), 5);
placeMap.put(Long.valueOf(1), 56);
final List<GroupWithCapacityResponse> response = GroupsMappers
.mapToCapacityResponse(List.of(group1, group2), placeMap);
assertTrue(response.size() == 2);
assertTrue(response.get(0).getTakenPlaces() == 5);
assertTrue(response.get(0).getCapacity() == 150);
assertTrue(response.get(1).getTakenPlaces() == 56);
assertTrue(response.get(1).getCapacity() == 24);
}
}