RepositoryBookmarkService implements BookmarkService { @Override @Transactional(readOnly = true) public boolean userHasBookmark(User user, Project project) { return userRepo.existsByIdAndBookmarksContaining(user.getId(), project); } @Autowired  RepositoryBookmarkService(UserRepository userRepo); @Override Project addBookmarkToUser(User user, Project project); @Override void removeBookmarkOfUser(User user, Project project); @Override @Transactional(readOnly = true) List<Project> getBookmarksOfUser(User user); @Override @Transactional(readOnly = true) boolean userHasBookmark(User user, Project project); @Override void removeAllBookmarksOfUser(User user);  }
@Test public void userHasBookmarkReturnsTrueWhenBookmarkExists() { given(userMock.getId()).willReturn(USER_ID); given(userRepository.existsByIdAndBookmarksContaining(USER_ID, projectMock)).willReturn(true); boolean actualHasBookmarked = bookmarkService.userHasBookmark(userMock, projectMock); assertThat(actualHasBookmarked).isTrue(); }
@Test public void userHasBookmarkReturnsFalseWhenBookmarkDoesNotExists() { given(userMock.getId()).willReturn(USER_ID); given(userRepository.existsByIdAndBookmarksContaining(USER_ID, projectMock)).willReturn(false); boolean actualHasBookmarked = bookmarkService.userHasBookmark(userMock, projectMock); assertThat(actualHasBookmarked).isFalse(); }