Add unit test for trust accessor
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Nov 2016 12:13:17 +0000 (13:13 +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/TrustAccessorTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/template/TrustAccessorTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/TrustAccessorTest.kt
new file mode 100644 (file)
index 0000000..9f2213a
--- /dev/null
@@ -0,0 +1,30 @@
+package net.pterodactylus.sone.template
+
+import net.pterodactylus.sone.freenet.wot.Trust
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+
+/**
+ * Unit test for [TrustAccessor].
+ */
+class TrustAccessorTest {
+
+       private val accessor = TrustAccessor()
+
+       @Test
+       fun `accessor returns false if there is no explicit trust assigned`() {
+               assertThat(accessor.get(null, Trust(null, null, null), "assigned"), equalTo<Any>(false))
+       }
+
+       @Test
+       fun `accessor returns true if there is explicit trust assigned`() {
+               assertThat(accessor.get(null, Trust(0, null, null), "assigned"), equalTo<Any>(true))
+       }
+
+       @Test
+       fun `reflection accessor is used for other members`() {
+               assertThat(accessor.get(null, Trust(0, 0, 0), "hashCode"), equalTo<Any>(Trust(0, 0, 0).hashCode()))
+       }
+
+}