Expose following times from FriendProvider
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 7 Feb 2018 05:58:09 +0000 (06:58 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 7 Feb 2018 05:58:09 +0000 (06:58 +0100)
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java
src/main/kotlin/net/pterodactylus/sone/database/FriendProvider.kt
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

index 07bcf2f..571f9a3 100644 (file)
@@ -320,6 +320,12 @@ public class MemoryDatabase extends AbstractService implements Database {
                memoryFriendDatabase.removeFriend(localSone.getId(), friendSoneId);
        }
 
+       @Nullable
+       @Override
+       public Long getFollowingTime(@Nonnull String friendSoneId) {
+               return memoryFriendDatabase.getFollowingTime(friendSoneId);
+       }
+
        //
        // POSTPROVIDER METHODS
        //
index 5ab1b28..a2d51a3 100644 (file)
@@ -4,6 +4,9 @@ import java.util.Collection;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
 
@@ -69,6 +72,11 @@ class MemoryFriendDatabase {
                }
        }
 
+       @Nullable
+       Long getFollowingTime(@Nonnull String soneId) {
+               return configurationLoader.getSoneFollowingTime(soneId);
+       }
+
        private void loadFriends(String localSoneId) {
                lock.writeLock().lock();
                try {
index f56f2f7..90b4f5e 100644 (file)
@@ -9,5 +9,6 @@ interface FriendProvider {
 
        fun getFriends(localSone: Sone): Collection<String>
        fun isFriend(localSone: Sone, friendSoneId: String): Boolean
+       fun getFollowingTime(friendSoneId: String): Long?
 
 }
index 47c2c4c..31532e2 100644 (file)
@@ -392,6 +392,22 @@ public class MemoryDatabaseTest {
        }
 
        @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);