Don’t load missing following times as Long.MAX_VALUE
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 6 Feb 2018 18:36:41 +0000 (19:36 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 7 Feb 2018 05:46:46 +0000 (06:46 +0100)
src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java
src/test/kotlin/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.kt

index bb82ee2..e471f0d 100644 (file)
@@ -75,7 +75,7 @@ public class ConfigurationLoader {
                        if (soneId == null) {
                                break;
                        }
-                       soneFollowingTimes.put(soneId, configuration.getLongValue("SoneFollowingTimes/" + soneCounter++ + "/Time").getValue(Long.MAX_VALUE));
+                       soneFollowingTimes.put(soneId, configuration.getLongValue("SoneFollowingTimes/" + soneCounter++ + "/Time").getValue(null));
                }
                return soneFollowingTimes;
        }
index b2da512..f653251 100644 (file)
@@ -109,4 +109,16 @@ class ConfigurationLoaderTest {
                assertThat(sone2Id.value, nullValue())
        }
 
+       @Test
+       fun `sone with missing following time is not loaded`() {
+               setupStringValue("SoneFollowingTimes/0/Sone", "Sone1")
+               setupLongValue("SoneFollowingTimes/0/Time", 1000L)
+               setupStringValue("SoneFollowingTimes/1/Sone", "Sone2")
+               setupLongValue("SoneFollowingTimes/1/Time")
+               setupStringValue("SoneFollowingTimes/2/Sone")
+               assertThat(configurationLoader.getSoneFollowingTime("Sone1"), equalTo(1000L))
+               assertThat(configurationLoader.getSoneFollowingTime("Sone2"), nullValue())
+               assertThat(configurationLoader.getSoneFollowingTime("Sone3"), nullValue())
+       }
+
 }