From: David ‘Bombe’ Roden Date: Sun, 24 Feb 2019 09:49:56 +0000 (+0100) Subject: Add test for storing IDs on known posts X-Git-Tag: v79^2~93 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=081a7b1344574efb641fe925088e4eb975e2e47e;p=Sone.git Add test for storing IDs on known posts --- diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.kt b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.kt index 725a644..962357e 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.kt +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.kt @@ -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 } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index 848c0a7..0d20aad 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -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)); + } + }