Skip to content

Commit

Permalink
ADM-794:[backend]fix: refactor for report service test
Browse files Browse the repository at this point in the history
  • Loading branch information
yulongcai committed Feb 1, 2024
1 parent 387df3b commit 5cb1dfc
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ void exportCsvShouldThrowNotFoundExceptionWhenTimestampIsValid() {
void generateBoardReportByTypeShouldCallGenerateBoardReport() throws InterruptedException {
GenerateReportRequest request = GenerateReportRequest.builder().metrics(new ArrayList<>()).build();
doAnswer(invocation -> null).when(generateReporterService).generateBoardReport(request);

reportService.generateReportByType(request, MetricType.BOARD);
Thread.sleep(100);

verify(generateReporterService).generateBoardReport(request);
verify(generateReporterService, never()).generateDoraReport(request);
}
Expand All @@ -86,8 +88,10 @@ void generateBoardReportByTypeShouldCallGenerateBoardReport() throws Interrupted
void generateDoraReportByTypeShouldCallGenerateDoraReport() throws InterruptedException {
GenerateReportRequest request = GenerateReportRequest.builder().metrics(new ArrayList<>()).build();
doAnswer(invocation -> null).when(generateReporterService).generateDoraReport(request);

reportService.generateReportByType(request, MetricType.DORA);
Thread.sleep(100);

verify(generateReporterService).generateDoraReport(request);
verify(generateReporterService, never()).generateBoardReport(request);
}
Expand All @@ -97,14 +101,21 @@ void ShouldInitializeMetricsDataCompletedInHandlerWithPreOneWhenPreOneExisted()
GenerateReportRequest request = GenerateReportRequest.builder().metrics(new ArrayList<>()).build();
when(asyncMetricsDataHandler.getMetricsDataCompleted(any())).thenReturn(MetricsDataCompleted.builder().build());
doAnswer(invocation -> null).when(generateReporterService).generateBoardReport(request);

reportService.generateReportByType(request, MetricType.BOARD);
Thread.sleep(100);

verify(generateReporterService).generateBoardReport(request);
verify(generateReporterService, never()).generateDoraReport(request);
}

@Test
void ShouldInitializeMetricsDataCompletedInHandlerWhenRequestMetricsExist() {
MetricsDataCompleted expectMetricsDataResult = MetricsDataCompleted.builder()
.boardMetricsCompleted(false)
.pipelineMetricsCompleted(true)
.sourceControlMetricsCompleted(false)
.build();
GenerateReportRequest request = GenerateReportRequest.builder()
.csvTimeStamp("csvTimeStamp")
.metrics(List.of(VELOCITY.getValue(), LEAD_TIME_FOR_CHANGES.getValue()))
Expand All @@ -114,11 +125,7 @@ void ShouldInitializeMetricsDataCompletedInHandlerWhenRequestMetricsExist() {
doAnswer(invocation -> null).when(generateReporterService).generateBoardReport(request);

reportService.generateReportByType(request, MetricType.BOARD);
MetricsDataCompleted expectMetricsDataResult = MetricsDataCompleted.builder()
.boardMetricsCompleted(false)
.pipelineMetricsCompleted(true)
.sourceControlMetricsCompleted(false)
.build();

verify(asyncMetricsDataHandler).putMetricsDataCompleted("csvTimeStamp", expectMetricsDataResult);
verify(generateReporterService).generateBoardReport(request);
verify(generateReporterService, never()).generateDoraReport(request);
Expand Down

0 comments on commit 5cb1dfc

Please sign in to comment.