Add method to save bookmarked posts to configuration loader.
[Sone.git] / src / test / java / net / pterodactylus / sone / database / memory / ConfigurationLoaderTest.java
index de357e9..55b66ee 100644 (file)
@@ -1,14 +1,18 @@
 package net.pterodactylus.sone.database.memory;
 
+import static java.util.Arrays.asList;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.nullValue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.HashSet;
 import java.util.Set;
 
 import net.pterodactylus.sone.TestValue;
 import net.pterodactylus.util.config.Configuration;
+import net.pterodactylus.util.config.ConfigurationException;
 
 import org.junit.Test;
 
@@ -60,4 +64,24 @@ public class ConfigurationLoaderTest {
                assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
        }
 
+       @Test
+       public void loaderCanSaveBookmarkedPosts() throws ConfigurationException {
+               final TestValue<String> post1 = new TestValue<String>(null);
+               final TestValue<String> post2 = new TestValue<String>(null);
+               final TestValue<String> post3 = new TestValue<String>(null);
+               when(configuration.getStringValue("Bookmarks/Post/0/ID"))
+                               .thenReturn(post1);
+               when(configuration.getStringValue("Bookmarks/Post/1/ID"))
+                               .thenReturn(post2);
+               when(configuration.getStringValue("Bookmarks/Post/2/ID"))
+                               .thenReturn(post3);
+               HashSet<String> originalPosts =
+                               new HashSet<String>(asList("Post1", "Post2"));
+               configurationLoader.saveBookmarkedPosts(originalPosts);
+               HashSet<String> extractedPosts = new HashSet<String>(
+                               asList(post1.getValue(), post2.getValue()));
+               assertThat(extractedPosts, containsInAnyOrder("Post1", "Post2"));
+               assertThat(post3.getValue(), nullValue());
+       }
+
 }