Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
holotsvan committed Dec 4, 2024
1 parent f3921c0 commit e4a2511
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ public void dislike(UserVO userVO, Long eventId) {
removeLikeIfExists(event, userVO, getEventAuthor(event));

if (removeDislikeIfExists(event, userVO)) {
eventRepo.save(event);
return;
}

Expand Down
17 changes: 17 additions & 0 deletions service/src/test/java/greencity/service/EventServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,23 @@ void dislikeTest() {
assertEquals(1L, event.getUsersDislikedEvents().size());
}

@Test
void testDislikeIfWasAlreadyPlaced(){
UserVO userVO = getUserVO();
User user = getUser();
Event event = getEvent();
Set<User> usersDisliked = new HashSet<>();
usersDisliked.add(user);
event.setUsersDislikedEvents(usersDisliked);

when(eventRepo.findById(anyLong())).thenReturn(Optional.of(event));
when(userRepo.findById(user.getId())).thenReturn(Optional.of(user));
eventService.dislike(userVO, event.getId());

verify(eventRepo).save(event);
assertEquals(0L, event.getUsersDislikedEvents().size());
}

@Test
void givenEventLikedByUser_whenDislikedByUser_shouldRemoveLikeAndAddDislike() {
UserVO userVO = getUserVO();
Expand Down

0 comments on commit e4a2511

Please sign in to comment.