Add unit test for unknown date filter
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Nov 2016 12:52:26 +0000 (13:52 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Nov 2016 13:47:32 +0000 (14:47 +0100)
src/test/kotlin/net/pterodactylus/sone/template/UnknownDateFilterTest.kt [new file with mode: 0644]

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 (file)
index 0000000..f18033e
--- /dev/null
@@ -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<BaseL10n>()
+       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<Any>(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<Any>("translated"))
+       }
+
+       @Test
+       fun `filter returns original long if non-zero value is given`() {
+               assertThat(filter.format(null, 1L, null), equalTo<Any>(1L))
+       }
+
+}