From 081a7b1344574efb641fe925088e4eb975e2e47e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 24 Feb 2019 10:49:56 +0100 Subject: [PATCH] Add test for storing IDs on known posts --- .../net/pterodactylus/sone/database/memory/MemoryDatabase.kt | 3 ++- .../pterodactylus/sone/database/memory/MemoryDatabaseTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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)); + } + } -- 2.7.4