Skip to content

Commit

Permalink
Update tests, add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bennavapbc committed Nov 19, 2024
1 parent 6073972 commit f8b30b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ public CoveragePagingResult pageCoverage(Job job, ContractDTO contract) {
}

ZonedDateTime startDateTime = getStartDateTime(contract);
// Additional details to log in the event of exception
Optional<String> additionalDetails = Optional.empty();
try {
// Check that all coverage periods necessary are present before beginning to page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ void pageRequestWhenSinceDateAfterNow() {
assertNotNull(result);
}

@DisplayName("Paging coverage fails when all coverage periods are present but CoverageService#pageCoverage throws exception")
@Test
void failPagingWhenCoveragePeriodsPresentButUnderlyingMethodThrowsException(CapturedOutput output) {
when(coverageService.getCoveragePeriod(any(ContractForCoverageDTO.class), anyInt(), anyInt())).thenAnswer((invocationOnMock) -> {
CoveragePeriod period = new CoveragePeriod();
period.setContractNumber((invocationOnMock.getArgument(0).toString()));
period.setMonth(invocationOnMock.getArgument(1));
period.setYear(invocationOnMock.getArgument(2));
return period;
});

when(coverageService.pageCoverage(any())).thenThrow(RuntimeException.class);

Job job = new Job();
ContractDTO contract = new ContractDTO(null, "Contract-0", null, AB2D_EPOCH.toOffsetDateTime(), null, 0, 0);
when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO("Contract-0", contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));

assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - CoveragePagingRequest(jobStartTime=null, contract=ContractForCoverageDTO(contractNumber=Contract-0, attestedOn=2020-01-01T00:00-05:00, contractType=NORMAL), pageSize=10000, cursor=Optional.empty)"));
}

@DisplayName("Paging coverage fails when coverage periods are missing")
@Test
void failPagingWhenCoveragePeriodMissing(CapturedOutput output) {
Expand All @@ -244,7 +265,6 @@ void failPagingWhenCoveragePeriodMissing(CapturedOutput output) {
CoverageDriverException startDateInFuture = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
assertEquals(EntityNotFoundException.class, startDateInFuture.getCause().getClass());
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - contract='null' month='1', year='2020'"));

}

@DisplayName("Paging coverage periods")
Expand Down Expand Up @@ -367,10 +387,10 @@ void failureToPageCausesExceptions(CapturedOutput output) {
ContractForCoverageDTO contract = new ContractForCoverageDTO();
contract.setContractNumber("contractNum");

val coveragePagingRequest = new CoveragePagingRequest( 1000, null, contract, OffsetDateTime.now());
val coveragePagingRequest = new CoveragePagingRequest( 1000, null, contract, AB2D_EPOCH.toOffsetDateTime());
CoverageDriverException exception = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(coveragePagingRequest));
assertTrue(exception.getMessage().contains("coverage driver failing preconditions"));
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - " + coveragePagingRequest.toString()));
assertTrue(output.getOut().contains("coverage period missing or year,month query incorrect, driver should have resolved earlier - CoveragePagingRequest(jobStartTime=2020-01-01T00:00-05:00, contract=ContractForCoverageDTO(contractNumber=contractNum, attestedOn=null, contractType=null), pageSize=1000, cursor=Optional.empty"));
}

@DisplayName("When loading a mapping job exit early if conditions not met")
Expand Down

0 comments on commit f8b30b8

Please sign in to comment.