X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FMemoryBookmarkDatabaseTest.java;h=188b74019ea484a707695b40672084f6dd81f5a4;hb=a57dae72e505fec934a9516b88fea75c473f7641;hp=c5ce475f8467427f0a79b6c50532bb2ad7485d25;hpb=04fbdc3d76e3b1140d178dc2600141ec92d22637;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java
index c5ce475..188b740 100644
--- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java
+++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java
@@ -1,10 +1,11 @@
package net.pterodactylus.sone.database.memory;
-import static com.google.common.base.Optional.fromNullable;
+import static net.pterodactylus.sone.test.Matchers.isPostWithId;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -17,7 +18,6 @@ import java.util.Set;
import net.pterodactylus.sone.data.Post;
-import com.google.common.base.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
@@ -25,8 +25,6 @@ import org.mockito.stubbing.Answer;
/**
* Unit test for {@link MemoryBookmarkDatabase}.
- *
- * @author David âBombeâ Roden
*/
public class MemoryBookmarkDatabaseTest {
@@ -35,36 +33,41 @@ public class MemoryBookmarkDatabaseTest {
mock(ConfigurationLoader.class);
private final MemoryBookmarkDatabase bookmarkDatabase =
new MemoryBookmarkDatabase(memoryDatabase, configurationLoader);
- private final Map posts = new HashMap();
+ private final Map posts = new HashMap<>();
@Before
public void setupMemoryDatabase() {
when(memoryDatabase.getPost(anyString())).thenAnswer(
- new Answer>() {
+ new Answer() {
@Override
- public Optional answer(
+ public Post answer(
InvocationOnMock invocation) {
- return fromNullable(
- posts.get(invocation.getArguments()[0]));
+ return posts.get(invocation.getArguments()[0]);
}
});
}
@Before
public void setupPosts() {
- createPost("PostId1");
- createPost("PostId2");
+ createAndRegisterPost("PostId1");
+ createAndRegisterPost("PostId2");
}
- private void createPost(String postId) {
+ private Post createAndRegisterPost(String postId) {
+ Post post = createPost(postId);
+ posts.put(postId, post);
+ return post;
+ }
+
+ private Post createPost(String postId) {
Post post = mock(Post.class);
when(post.getId()).thenReturn(postId);
- posts.put(postId, post);
+ return post;
}
@Test
public void bookmarkDatabaseRetainsBookmarkedPosts() {
- Set allPosts = new HashSet(posts.values());
+ Set allPosts = new HashSet<>(posts.values());
for (Post post : allPosts) {
bookmarkDatabase.bookmarkPost(post);
}
@@ -95,7 +98,7 @@ public class MemoryBookmarkDatabaseTest {
@Test
public void removingABookmarkRemovesTheCorrectBookmark() {
- Set allPosts = new HashSet(posts.values());
+ Set allPosts = new HashSet<>(posts.values());
for (Post post : allPosts) {
bookmarkDatabase.bookmarkPost(post);
}
@@ -121,4 +124,14 @@ public class MemoryBookmarkDatabaseTest {
verify(configurationLoader).saveBookmarkedPosts(any(Set.class));
}
+ @Test
+ public void bookmarkedPostsIncludeNotYetLoadedPosts() {
+ bookmarkDatabase.bookmarkPost(posts.get("PostId1"));
+ bookmarkDatabase.bookmarkPost(createPost("PostId3"));
+ final Set bookmarkedPosts =
+ bookmarkDatabase.getBookmarkedPosts();
+ assertThat(bookmarkedPosts,
+ contains(isPostWithId("PostId1"), isPostWithId("PostId3")));
+ }
+
}