X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FConfigurationLoaderTest.kt;h=f653251b6b0e2ae60eb06fcd693727a0306c1a16;hp=f0a1d108cfa6231165b5b49ebaa562db92a4ca97;hb=b91623458a0059ec31e6f57768b5814df97c093a;hpb=050cb5f8b7128ae6a23dba72503ca85f327b91e2 diff --git a/src/test/kotlin/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.kt b/src/test/kotlin/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.kt index f0a1d10..f653251 100644 --- a/src/test/kotlin/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.kt @@ -7,6 +7,7 @@ import net.pterodactylus.util.config.Configuration import net.pterodactylus.util.config.Value import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder +import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.nullValue import org.junit.Test @@ -25,6 +26,11 @@ class ConfigurationLoaderTest { whenever(configuration.getStringValue(attribute)).thenReturn(this) } + private fun setupLongValue(attribute: String, value: Long? = null): Value = + from(value).apply { + whenever(configuration.getLongValue(attribute)).thenReturn(this) + } + @Test fun `loader can load known posts`() { setupStringValue("KnownPosts/0/ID", "Post2") @@ -64,4 +70,55 @@ class ConfigurationLoaderTest { assertThat(post3.value, nullValue()) } + @Test + fun `loader can load Sone following times`() { + setupStringValue("SoneFollowingTimes/0/Sone", "Sone1") + setupLongValue("SoneFollowingTimes/0/Time", 1000L) + setupStringValue("SoneFollowingTimes/1/Sone", "Sone2") + setupLongValue("SoneFollowingTimes/1/Time", 2000L) + setupStringValue("SoneFollowingTimes/2/Sone") + assertThat(configurationLoader.getSoneFollowingTime("Sone1"), equalTo(1000L)) + assertThat(configurationLoader.getSoneFollowingTime("Sone2"), equalTo(2000L)) + assertThat(configurationLoader.getSoneFollowingTime("Sone3"), nullValue()) + } + + @Test + fun `loader can overwrite existing Sone following time`() { + val sone1Id = setupStringValue("SoneFollowingTimes/0/Sone", "Sone1") + val sone1Time = setupLongValue("SoneFollowingTimes/0/Time", 1000L) + val sone2Id = setupStringValue("SoneFollowingTimes/1/Sone", "Sone2") + val sone2Time = setupLongValue("SoneFollowingTimes/1/Time", 2000L) + setupStringValue("SoneFollowingTimes/2/Sone") + configurationLoader.setSoneFollowingTime("Sone1", 3000L) + assertThat(listOf(sone1Id.value to sone1Time.value, sone2Id.value to sone2Time.value), containsInAnyOrder>( + "Sone1" to 3000L, + "Sone2" to 2000L + )) + } + + @Test + fun `loader can remove Sone following time`() { + val sone1Id = setupStringValue("SoneFollowingTimes/0/Sone", "Sone1") + val sone1Time = setupLongValue("SoneFollowingTimes/0/Time", 1000L) + val sone2Id = setupStringValue("SoneFollowingTimes/1/Sone", "Sone2") + val sone2Time = setupLongValue("SoneFollowingTimes/1/Time", 2000L) + setupStringValue("SoneFollowingTimes/2/Sone") + configurationLoader.removeSoneFollowingTime("Sone1") + assertThat(sone1Id.value, equalTo("Sone2")) + assertThat(sone1Time.value, equalTo(2000L)) + 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()) + } + }