+ verify(stringValues.get("KnownSones/0/ID")).setValue(SONE_ID);
+ verify(stringValues.get("KnownSones/1/ID")).setValue(null);
+ }
+
+ @Test
+ public void soneFollowingTimesAreLoaded() {
+ stringValues.put("SoneFollowingTimes/0/Sone", TestValue.from(SONE_ID));
+ longValues.put("SoneFollowingTimes/0/Time", TestValue.from(1000L));
+ memoryDatabase.startAndWait();
+ assertThat(memoryDatabase.getSoneFollowingTime(SONE_ID).get(), is(1000L));
+ }
+
+ @Test
+ public void soneFollowingTimeIsSetOnFirstFollowing() {
+ memoryDatabase.startAndWait();
+ memoryDatabase.addFriend(localSone, "Friend1");
+ assertThat(stringValues, hasKey("SoneFollowingTimes/0/Sone"));
+ assertThat(stringValues, hasKey("SoneFollowingTimes/1/Sone"));
+ assertThat(stringValues, not(hasKey("SoneFollowingTimes/2/Sone")));
+ assertThat(longValues, hasKey("SoneFollowingTimes/0/Time"));
+ assertThat(longValues, not(hasKey("SoneFollowingTimes/1/Time")));
+ }
+
+ @Test
+ public void soneFollowingTimeIsNotSetOnSecondFollowing() throws ConfigurationException {
+ memoryDatabase.startAndWait();
+ memoryDatabase.addFriend(localSone, "Friend1");
+ LocalSone secondLocalSone = mock(LocalSone.class);
+ when(secondLocalSone.getId()).thenReturn("LocalSone2");
+ long followingTime = longValues.get("SoneFollowingTimes/0/Time").getValue();
+ memoryDatabase.addFriend(secondLocalSone, "Friend1");
+ while (followingTime == System.currentTimeMillis());
+ assertThat(longValues.get("SoneFollowingTimes/0/Time").getValue(), is(followingTime));
+ }
+
+ @Test
+ public void soneFollowingTimesAreRemovedWhenSoneIsUnfollowedByAll()
+ throws ConfigurationException {
+ stringValues.put("Sone/" + SONE_ID + "/Friends/0/ID", TestValue.from("Friend1"));
+ stringValues.put("SoneFollowingTimes/0/Sone", TestValue.from("Friend1"));
+ longValues.put("SoneFollowingTimes/0/Time", TestValue.from(1000L));
+ memoryDatabase.startAndWait();
+ memoryDatabase.removeFriend(localSone, "Friend1");
+ assertThat(stringValues.get("SoneFollowingTimes/0/Sone").getValue(), nullValue());