Попытка тестирования методов обслуживания. Это метод, что я хочу, чтобы тест:тестирование службы с mockito и весной
@Override
public ReportListDto retrieveAllReportsList() {
List<ReportDto> reportDtos = reportMapper.toDtos(reportRepository.findAll());
return new ReportListDtoBuilder().reportsDto(reportDtos).build();
}
Это мой метод испытания (я получил его от какого-то учебника):
@Test
public void testRetrieveAllReportList() throws Exception {
List<Report> expected = new ArrayList<>();
when(reportRepositoryMock.findAll()).thenReturn(expected);
ReportListDto actual = reportService.retrieveAllReportsList();
verify(reportRepositoryMock, times(1)).findAll();
verifyNoMoreInteractions(reportRepositoryMock);
assertEquals(expected, actual);
}
Но учебник не используют модели DTO. Так что последний асетт ожидал List<Report>
объект и фактический ReportListDto
объект.
Это мой ReportListDto
:
public class ReportListDto implements Serializable {
private List<ReportDto> reports = new ArrayList<>();
public List<ReportDto> getReports() {
return reports;
}
public void setReports(List<ReportDto> reports) {
this.reports = reports;
}
}
Как я могу проверить, что сервис использование DTO картографа?
сделать макет возвращение DAO более 0 Report. И на основе списка отчетов, возвращаемых DAO, убедитесь, что возвращаемый службой ReportListDto содержит правильное количество ReportDtos в правильном порядке и содержит правильные значения. –