Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
boal committed Feb 26, 2025
1 parent e41cd1e commit 9c198ff
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,43 @@ void loadUnauffaelligeTageForEachMessstelleWithoutDataInDatabase() {
.findByDatum(LocalDate.of(2025, 2, 3));
}

@Test
void loadUnauffaelligeTageForEachMessstelleNoKaledertagForDatumFound() {
Mockito.when(unauffaelligeTageRepository.findTopByOrderByKalendertagDatumDesc()).thenReturn(Optional.empty());

final var unauffaelligeTage = new ArrayList<UnauffaelligerTagDto>();
var unauffaelligerTagDto = new UnauffaelligerTagDto();
unauffaelligerTagDto.setMstId(1234);
unauffaelligerTagDto.setDatum(LocalDate.of(2025, 2, 2));
unauffaelligeTage.add(unauffaelligerTagDto);
unauffaelligerTagDto = new UnauffaelligerTagDto();
unauffaelligerTagDto.setMstId(1234);
unauffaelligerTagDto.setDatum(LocalDate.of(2025, 2, 3));
unauffaelligeTage.add(unauffaelligerTagDto);
unauffaelligerTagDto = new UnauffaelligerTagDto();
unauffaelligerTagDto.setMstId(4321);
unauffaelligerTagDto.setDatum(LocalDate.of(2025, 2, 3));
unauffaelligeTage.add(unauffaelligerTagDto);
final var mobidamResponseEntity = ResponseEntity.of(Optional.of((List<UnauffaelligerTagDto>) unauffaelligeTage));
final var mono = Mono.just(mobidamResponseEntity);
Mockito.when(messstelleApi.getUnauffaelligeTageForEachMessstelleWithHttpInfo(LocalDate.of(2006, 1, 1), LocalDate.now().minusDays(1))).thenReturn(mono);

Mockito.when(kalendertagRepository.findByDatum(LocalDate.of(2025, 2, 2))).thenReturn(Optional.empty());

Mockito.when(kalendertagRepository.findByDatum(LocalDate.of(2025, 2, 3))).thenReturn(Optional.empty());

Assertions.assertThrows(EntityNotFoundException.class, () -> unauffaelligeTageReceiver.loadUnauffaelligeTageForEachMessstelle());

Mockito.verify(messstelleApi, Mockito.times(1))
.getUnauffaelligeTageForEachMessstelleWithHttpInfo(LocalDate.of(2006, 1, 1), LocalDate.now().minusDays(1));

Mockito.verify(kalendertagRepository, Mockito.times(1))
.findByDatum(LocalDate.of(2025, 2, 2));

Mockito.verify(kalendertagRepository, Mockito.times(0))
.findByDatum(LocalDate.of(2025, 2, 3));
}

@Test
void mapDto2Entity() {
final var unauffaelligerTagDto = new UnauffaelligerTagDto();
Expand Down

0 comments on commit 9c198ff

Please sign in to comment.