X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSoneAccessorTest.kt;h=87cfce0db594efa62167720e52f0a420fc998aed;hp=2f03deec3344c823e94616321a1a23111b3d744e;hb=03c29a3838e23ed0b9731ca4d84cf58038c30dfe;hpb=1a2e2a402b62923a68b09eea463ca3952c5505b0 diff --git a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt index 2f03dee..87cfce0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt @@ -10,11 +10,14 @@ import net.pterodactylus.sone.data.Sone.SoneStatus.downloading import net.pterodactylus.sone.data.Sone.SoneStatus.idle import net.pterodactylus.sone.data.Sone.SoneStatus.inserting import net.pterodactylus.sone.data.Sone.SoneStatus.unknown +import net.pterodactylus.sone.freenet.L10nText import net.pterodactylus.sone.freenet.wot.Identity import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.freenet.wot.Trust import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.text.TimeText +import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.util.template.TemplateContext import org.hamcrest.Matcher import org.hamcrest.MatcherAssert.assertThat @@ -29,7 +32,8 @@ import org.junit.Test class SoneAccessorTest { private val core = mock() - private val accessor = SoneAccessor(core) + private val timeTextConverter = mock() + private val accessor = SoneAccessor(core, timeTextConverter) private val templateContext = mock() private val currentSone = mock() private val currentIdentity = mock() @@ -54,6 +58,7 @@ class SoneAccessorTest { assertThat(accessor.get(templateContext, sone, member), equalTo(expected)) } + @Suppress("UNCHECKED_CAST") private fun assertAccessorReturnValueMatches(member: String, matcher: Matcher) { assertThat(accessor.get(templateContext, sone, member) as T, matcher) } @@ -123,7 +128,7 @@ class SoneAccessorTest { @Test fun `accessor returns that the sone’s status is not unknown if it is not unknown`() { - whenever(sone.status).thenReturn(mock()) + whenever(sone.status).thenReturn(mock()) assertAccessorReturnValue("unknown", false) } @@ -135,7 +140,7 @@ class SoneAccessorTest { @Test fun `accessor returns that the sone’s status is not idle if it is not idle`() { - whenever(sone.status).thenReturn(mock()) + whenever(sone.status).thenReturn(mock()) assertAccessorReturnValue("idle", false) } @@ -147,7 +152,7 @@ class SoneAccessorTest { @Test fun `accessor returns that the sone’s status is not inserting if it is not inserting`() { - whenever(sone.status).thenReturn(mock()) + whenever(sone.status).thenReturn(mock()) assertAccessorReturnValue("inserting", false) } @@ -159,7 +164,7 @@ class SoneAccessorTest { @Test fun `accessor returns that the sone’s status is not downloading if it is not downloading`() { - whenever(sone.status).thenReturn(mock()) + whenever(sone.status).thenReturn(mock()) assertAccessorReturnValue("downloading", false) } @@ -186,6 +191,13 @@ class SoneAccessorTest { } @Test + fun `accessor returns l10n text for last update time`() { + whenever(sone.time).thenReturn(12345) + whenever(timeTextConverter.getTimeText(12345L)).thenReturn(TimeText(L10nText("l10n.key", listOf(3L)), 23456)) + assertAccessorReturnValue("lastUpdatedText", L10nText("l10n.key", listOf(3L))) + } + + @Test fun `accessor returns null trust if there is no current sone`() { whenever(templateContext["currentSone"]).thenReturn(null) assertAccessorReturnValue("trust", null) @@ -205,7 +217,7 @@ class SoneAccessorTest { @Test fun `accessor returns all images in the correct order`() { - val images = listOf(mock(), mock(), mock(), mock(), mock()) + val images = listOf(mock(), mock(), mock(), mock(), mock()) val firstAlbum = createAlbum(listOf(), listOf(images[0], images[3])) val secondAlbum = createAlbum(listOf(), listOf(images[1], images[4], images[2])) val rootAlbum = createAlbum(listOf(firstAlbum, secondAlbum), listOf()) @@ -221,7 +233,7 @@ class SoneAccessorTest { @Test fun `accessor returns all albums in the correct order`() { - val albums = listOf(mock(), mock(), mock(), mock(), mock()) + val albums = listOf(mock(), mock(), mock(), mock(), mock()) val rootAlbum = createAlbum(albums, listOf()) whenever(sone.rootAlbum).thenReturn(rootAlbum) assertAccessorReturnValueMatches("albums", contains(*albums.toTypedArray()))