### Question:
SubjectMapperDecorator implements SubjectMapper { @Override public List<SubjectDto> questionsToSubjectsDto(List<Question> questions) { Assert.notNull(questions, "Cannot map a null list of questions to a list of subject dtos"); Multimap<Subject, Question> multimap = Multimaps.index(questions, Question::getSubject); return multimap.keySet().stream().map(subject -> { SubjectDto subjectDto = delegate.toDto(subject); List<QuestionDto> questionsDtos = multimap.get(subject).stream() .map(question -> questionMapper.questionToQuestionDto(question)).collect(Collectors.toList()); subjectDto.addQuestions(questionsDtos); return subjectDto; }).collect(Collectors.toList()); }  @Override List<SubjectDto> questionsToSubjectsDto(List<Question> questions);  }### Answer:
@Test public void questionsToSubjectsDto() throws Exception { Question q1 = new Question().id(1L).label("question1").subject(new Subject().id(1L)); Question q2 = new Question().id(2L).label("question2").subject(new Subject().id(1L)); Question q3 = new Question().id(3L).label("question3").subject(new Subject().id(2L)); List<SubjectDto> subjects = subjectMapper.questionsToSubjectsDto(Arrays.asList(q1, q2, q3)); Assert.assertNotNull(subjects); Assert.assertEquals(subjects.size(), 2); subjects.forEach((this::assertSubjectDtoAndItsQuestionsNotNull)); }