*/
public interface BookmarkDatabase {
- void bookmarkPost(String postId); // FIXME – remove me
void bookmarkPost(Post post);
void unbookmarkPost(Post post);
boolean isPostBookmarked(Post post);
}
@Override
- public void bookmarkPost(String postId) {
- lock.writeLock().lock();
- try {
- bookmarkedPosts.add(postId);
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- @Override
public void bookmarkPost(Post post) {
lock.writeLock().lock();
try {
}
@Override
- public void bookmarkPost(String postId) {
- memoryBookmarkDatabase.bookmarkPost(postId);
- }
-
- @Override
public void bookmarkPost(Post post) {
memoryBookmarkDatabase.bookmarkPost(post);
}
}
}
- @Test
- public void addingABookmarkByIdBookmarksTheCorrectPost() {
- Post randomPost = posts.values().iterator().next();
- bookmarkDatabase.bookmarkPost(randomPost.getId());
- assertThat(bookmarkDatabase.getBookmarkedPosts(),
- contains(randomPost));
- }
-
}