AppMapper { public Schedule toSchedule(@NonNull List<Session> sessions) { Collections.sort(sessions, (lhs, rhs) -> lhs.getFromTime().compareTo(rhs.getFromTime())); List<ScheduleSlot> scheduleSlots = mapToScheduleSlots(sessions); return mapToScheduleDays(scheduleSlots); } @Inject  AppMapper(); Map<Integer, Speaker> speakersToMap(@NonNull List<Speaker> from); List<Speaker> toSpeakersList(@Nullable List<Integer> speakerIds, @NonNull Map<Integer, Speaker> speakersMap); List<Integer> toSpeakersIds(@Nullable List<Speaker> speakers); Schedule toSchedule(@NonNull List<Session> sessions);  }
@Test public void should_convert_sessions_list_into_schedule() { LocalDateTime slot1 = LocalDateTime.of(2016, 3, 15, 8, 10); LocalDateTime slot2 = slot1.plusHours(1); LocalDateTime slot3 = slot2.plusHours(1); LocalDateTime slot4 = slot1.plusDays(1); Session session1 = new Session(1, "room1", singletonList(speaker1), "title1", "desc1", slot1, slot1.plusHours(1)); Session session2 = new Session(2, "room2", singletonList(speaker2), "title2", "desc2", slot1, slot1.plusHours(1)); Session session3 = new Session(3, "room1", singletonList(speaker3), "title3", "desc3", slot2, slot2.plusHours(1)); Session session4 = new Session(4, "room1", singletonList(speaker4), "title4", "desc4", slot3, slot3.plusHours(1)); Session session5 = new Session(5, "room1", singletonList(speaker5), "title5", "desc5", slot4, slot4.plusHours(1)); Schedule result = appMapper.toSchedule(Arrays.asList(session1, session2, session3, session4, session5)); assertThat(result).hasSize(2); assertThat(result.get(0).getDay()).isEqualTo(slot1.toLocalDate()); assertThat(result.get(0).getSlots()).hasSize(3); assertThat(result.get(0).getSlots().get(0).getSessions()).containsAllOf(session1, session2); assertThat(result.get(0).getSlots().get(0).getTime()).isEqualTo(slot1); assertThat(result.get(0).getSlots().get(1).getSessions()).containsExactly(session3); assertThat(result.get(1).getSlots()).hasSize(1); assertThat(result.get(1).getSlots().get(0).getSessions()).containsExactly(session5); }