Add Request utility methods
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Mar 2017 11:02:37 +0000 (12:02 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 25 Mar 2017 11:02:37 +0000 (12:02 +0100)
src/main/kotlin/net/pterodactylus/sone/utils/Requests.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/utils/RequestsTest.kt [new file with mode: 0644]

diff --git a/src/main/kotlin/net/pterodactylus/sone/utils/Requests.kt b/src/main/kotlin/net/pterodactylus/sone/utils/Requests.kt
new file mode 100644 (file)
index 0000000..50f3957
--- /dev/null
@@ -0,0 +1,8 @@
+package net.pterodactylus.sone.utils
+
+import net.pterodactylus.util.web.Method.GET
+import net.pterodactylus.util.web.Method.POST
+import net.pterodactylus.util.web.Request
+
+val Request.isGET get() = this.method == GET
+val Request.isPOST get() = this.method == POST
diff --git a/src/test/kotlin/net/pterodactylus/sone/utils/RequestsTest.kt b/src/test/kotlin/net/pterodactylus/sone/utils/RequestsTest.kt
new file mode 100644 (file)
index 0000000..eb0bc43
--- /dev/null
@@ -0,0 +1,31 @@
+package net.pterodactylus.sone.utils
+
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.util.web.Method.GET
+import net.pterodactylus.util.web.Method.POST
+import net.pterodactylus.util.web.Request
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+
+/**
+ * Unit test for the [Request] utilities.
+ */
+class RequestsTest {
+
+       @Test
+       fun `GET request is recognized correctly`() {
+               val request = mock<Request>().apply { whenever(method).thenReturn(GET) }
+               assertThat(request.isGET, equalTo(true))
+               assertThat(request.isPOST, equalTo(false))
+       }
+
+       @Test
+       fun `POST request is recognized correctly`() {
+               val request = mock<Request>().apply { whenever(method).thenReturn(POST) }
+               assertThat(request.isGET, equalTo(false))
+               assertThat(request.isPOST, equalTo(true))
+       }
+
+}