Skip to content

Commit

Permalink
Refactor test to avoid multiple potential exceptions in lambda expres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
Cr1stal423 committed Dec 3, 2024
1 parent 499a317 commit 837a9a9
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,12 @@ void saveEventWithoutAddress() {
User user = ModelUtils.getUser();
AddEventDtoRequest addEventDtoWithoutCoordinates = ModelUtils.addEventDtoWithoutAddressRequest;
Event eventWithoutCoordinates = ModelUtils.getEventWithoutAddress();

String email = user.getEmail();
when(modelMapper.map(addEventDtoWithoutCoordinates, Event.class)).thenReturn(eventWithoutCoordinates);
when(eventRepo.save(any(Event.class))).thenReturn(eventWithoutCoordinates);

BadRequestException exception = assertThrows(
BadRequestException.class,
() -> eventService.save(addEventDtoWithoutCoordinates, user.getEmail(), null));

() -> eventService.save(addEventDtoWithoutCoordinates, email, null));
assertEquals(ErrorMessage.INVALID_COORDINATES, exception.getMessage());
verify(eventRepo, times(0)).save(eventWithoutCoordinates);
}
Expand Down

0 comments on commit 837a9a9

Please sign in to comment.