Add test for storing IDs on known posts
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 24 Feb 2019 09:49:56 +0000 (10:49 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 24 Feb 2019 09:49:56 +0000 (10:49 +0100)
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.kt
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

index 725a644..962357e 100644 (file)
@@ -287,6 +287,7 @@ class MemoryDatabase @Inject constructor(private val configuration: Configuratio
                                        knownPosts.add(post.id)
                                else
                                        knownPosts.remove(post.id)
+                               saveKnownPosts()
                        }
 
        protected fun isPostReplyKnown(postReply: PostReply) = readLock.withLock { postReply.id in knownPostReplies }
@@ -312,7 +313,7 @@ class MemoryDatabase @Inject constructor(private val configuration: Configuratio
                        try {
                                readLock.withLock {
                                        knownPosts.forEachIndexed { index, knownPostId ->
-                                               configuration.getStringValue("KnowsPosts/$index/ID").value = knownPostId
+                                               configuration.getStringValue("KnownPosts/$index/ID").value = knownPostId
                                        }
                                        configuration.getStringValue("KnownPosts/${knownPosts.size}/ID").value = null
                                }
index 848c0a7..0d20aad 100644 (file)
@@ -456,4 +456,14 @@ public class MemoryDatabaseTest {
                assertThat(configuration.getLongValue("SoneFollowingTimes/0/Time").getValue(), equalTo(1000L));
        }
 
+       @Test
+       public void markingAPostAsKnownSavesConfiguration() throws ConfigurationException {
+               prepareConfigurationValues();
+               Post post = mock(Post.class);
+               when(post.getId()).thenReturn("post-id");
+               memoryDatabase.setPostKnown(post, true);
+               assertThat(configuration.getStringValue("KnownPosts/0/ID").getValue(), equalTo("post-id"));
+               assertThat(configuration.getStringValue("KnownPosts/1/ID").getValue(), equalTo(null));
+       }
+
 }