From: David ‘Bombe’ Roden Date: Sat, 25 Mar 2017 11:02:37 +0000 (+0100) Subject: Add Request utility methods X-Git-Tag: 0.9.7^2~276 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e3eabbebfe2b3fafe182769d0e3cc19d92979b04;p=Sone.git Add Request utility methods --- 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 index 0000000..50f3957 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/utils/Requests.kt @@ -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 index 0000000..eb0bc43 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/utils/RequestsTest.kt @@ -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().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().apply { whenever(method).thenReturn(POST) } + assertThat(request.isGET, equalTo(false)) + assertThat(request.isPOST, equalTo(true)) + } + +}