From cbd6de75a2a96966a2381100c5b643feea702458 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 7 Feb 2018 06:58:09 +0100 Subject: [PATCH] Expose following times from FriendProvider --- .../sone/database/memory/MemoryDatabase.java | 6 ++++++ .../sone/database/memory/MemoryFriendDatabase.java | 8 ++++++++ .../net/pterodactylus/sone/database/FriendProvider.kt | 1 + .../sone/database/memory/MemoryDatabaseTest.java | 16 ++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 07bcf2f..571f9a3 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -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 // diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java index 5ab1b28..a2d51a3 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryFriendDatabase.java @@ -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 { diff --git a/src/main/kotlin/net/pterodactylus/sone/database/FriendProvider.kt b/src/main/kotlin/net/pterodactylus/sone/database/FriendProvider.kt index f56f2f7..90b4f5e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/database/FriendProvider.kt +++ b/src/main/kotlin/net/pterodactylus/sone/database/FriendProvider.kt @@ -9,5 +9,6 @@ interface FriendProvider { fun getFriends(localSone: Sone): Collection fun isFriend(localSone: Sone, friendSoneId: String): Boolean + fun getFollowingTime(friendSoneId: String): Long? } 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 47c2c4c..31532e2 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -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); -- 2.7.4