Add test for storing IDs on known post replies
[Sone.git] / src / test / java / net / pterodactylus / sone / database / memory / MemoryDatabaseTest.java
index bbf1477..60c8c53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - MemoryDatabaseTest.java - Copyright © 2013–2016 David Roden
+ * Sone - MemoryDatabaseTest.java - Copyright © 2013–2019 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -70,8 +70,6 @@ import org.mockito.stubbing.Answer;
 
 /**
  * Tests for {@link MemoryDatabase}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class MemoryDatabaseTest {
 
@@ -122,7 +120,7 @@ public class MemoryDatabaseTest {
                                                .withTime(4000L)
                                                .withText("reply2")
                                                .build();
-               Set<PostReply> postReplies = new HashSet<PostReply>(
+               Set<PostReply> postReplies = new HashSet<>(
                                asList(firstPostFirstReply, firstPostSecondReply,
                                                secondPostReply));
                when(sone.getReplies()).thenReturn(postReplies);
@@ -141,6 +139,7 @@ public class MemoryDatabaseTest {
                                "album-description3").update();
                firstAlbum.addAlbum(thirdAlbum);
                Album rootAlbum = mock(Album.class);
+               when(rootAlbum.getId()).thenReturn("root");
                when(rootAlbum.getAlbums()).thenReturn(
                                asList(firstAlbum, secondAlbum));
                when(sone.getRootAlbum()).thenReturn(rootAlbum);
@@ -215,7 +214,7 @@ public class MemoryDatabaseTest {
 
        @Test
        public void storedAndRemovedSoneIsNotAvailable() {
-           storedSoneIsMadeAvailable();
+               storedSoneIsMadeAvailable();
                memoryDatabase.removeSone(sone);
                assertThat(memoryDatabase.getSones(), empty());
        }
@@ -457,4 +456,24 @@ 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));
+       }
+
+       @Test
+       public void markingAPostReplyAsKnownSavesConfiguration() throws ConfigurationException {
+               prepareConfigurationValues();
+               PostReply postReply = mock(PostReply.class);
+               when(postReply.getId()).thenReturn("post-reply-id");
+               memoryDatabase.setPostReplyKnown(postReply, true);
+               assertThat(configuration.getStringValue("KnownReplies/0/ID").getValue(), equalTo("post-reply-id"));
+               assertThat(configuration.getStringValue("KnownReplies/1/ID").getValue(), equalTo(null));
+       }
+
 }