From: David ‘Bombe’ Roden Date: Sun, 20 Nov 2016 12:52:26 +0000 (+0100) Subject: Add unit test for unknown date filter X-Git-Tag: 0.9.7^2~407 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=176b8f0e11d72feaa9d3ebbe1438f0f94c4ceb49;p=Sone.git Add unit test for unknown date filter --- diff --git a/src/test/kotlin/net/pterodactylus/sone/template/UnknownDateFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/UnknownDateFilterTest.kt new file mode 100644 index 0000000..f18033e --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/template/UnknownDateFilterTest.kt @@ -0,0 +1,36 @@ +package net.pterodactylus.sone.template + +import freenet.l10n.BaseL10n +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test + +/** + * Unit test for [UnknownDateFilter]. + */ +class UnknownDateFilterTest { + + private val baseL10n = mock() + private val unknownKey = "unknown.key" + private val filter = UnknownDateFilter(baseL10n, unknownKey) + + @Test + fun `filter returns given object for non-longs`() { + val someObject = Any() + assertThat(filter.format(null, someObject, null), equalTo(someObject)) + } + + @Test + fun `filter returns translated value of unknown key if zero is given`() { + whenever(baseL10n.getString(unknownKey)).thenReturn("translated") + assertThat(filter.format(null, 0L, null), equalTo("translated")) + } + + @Test + fun `filter returns original long if non-zero value is given`() { + assertThat(filter.format(null, 1L, null), equalTo(1L)) + } + +}