+ @Test
+ public void soneFollowingTimeIsReturnedCorrectly() throws ConfigurationException {
+ prepareConfigurationValues();
+ configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("sone");
+ configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L);
+ assertThat(memoryDatabase.getFollowingTime("sone"), equalTo(1000L));
+ }
+
+ @Test
+ public void nullisReturnedWhenSoneIsNotFollowed() throws ConfigurationException {
+ prepareConfigurationValues();
+ configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("otherSone");
+ configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L);
+ assertThat(memoryDatabase.getFollowingTime("sone"), nullValue());
+ }
+
+ @Test
+ public void timeIsStoredInConfigurationWhenASoneIsFollowed() throws ConfigurationException {
+ prepareConfigurationValues();
+ when(sone.isLocal()).thenReturn(true);
+ memoryDatabase.addFriend(sone, "Friend");
+ assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), equalTo("Friend"));
+ assertThat(System.currentTimeMillis() - configuration.getLongValue("SoneFollowingTimes/0/Time").getValue(), lessThan(1000L));
+ assertThat(configuration.getStringValue("SoneFollowingTimes/1/Sone").getValue(), nullValue());
+ }
+
+ @Test
+ public void existingTimeIsNotOverwrittenWhenASoneIsFollowed() throws ConfigurationException {
+ prepareConfigurationValues();
+ configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("Friend");
+ configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L);
+ when(sone.isLocal()).thenReturn(true);
+ memoryDatabase.addFriend(sone, "Friend");
+ assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), equalTo("Friend"));
+ assertThat(configuration.getLongValue("SoneFollowingTimes/0/Time").getValue(), equalTo(1000L));
+ assertThat(configuration.getStringValue("SoneFollowingTimes/1/Sone").getValue(), nullValue());
+ }
+
+ @Test
+ public void unfollowingASoneRemovesTheFollowingTime() throws ConfigurationException {
+ prepareConfigurationValues();
+ configuration.getStringValue("Sone/sone/Friends/0/ID").setValue("Friend");
+ configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("Friend");
+ configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L);
+ when(sone.isLocal()).thenReturn(true);
+ memoryDatabase.removeFriend(sone, "Friend");
+ assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), nullValue());
+ }
+
+ @Test
+ public void unfollowingASoneDoesNotRemoveTheFollowingTimeIfAnotherLocalSoneFollowsIt() throws ConfigurationException {
+ prepareConfigurationValues();
+ configuration.getStringValue("Sone/sone/Friends/0/ID").setValue("Friend");
+ configuration.getStringValue("Sone/other-sone/Friends/0/ID").setValue("Friend");
+ configuration.getStringValue("SoneFollowingTimes/0/Sone").setValue("Friend");
+ configuration.getLongValue("SoneFollowingTimes/0/Time").setValue(1000L);
+ Sone otherSone = mock(Sone.class);
+ when(otherSone.isLocal()).thenReturn(true);
+ when(otherSone.getId()).thenReturn("other-sone");
+ memoryDatabase.getFriends(otherSone);
+ when(sone.isLocal()).thenReturn(true);
+ memoryDatabase.removeFriend(sone, "Friend");
+ assertThat(configuration.getStringValue("SoneFollowingTimes/0/Sone").getValue(), equalTo("Friend"));
+ 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));
+ }
+