From 406700bbe3d320c88f275aec62a50cfec9bd2223 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 22 Jan 2018 07:06:47 +0100 Subject: [PATCH] Add test for DI constructability of CreatePostAjaxPage --- .../kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt | 3 ++- .../net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt index 868e990..47535c0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt @@ -9,11 +9,12 @@ import net.pterodactylus.sone.utils.let import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest +import javax.inject.Inject /** * AJAX handler that creates a new post. */ -class CreatePostAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("createPost.ajax", webInterface) { +class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("createPost.ajax", webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["text"].emptyToNull diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt index 8449453..821198f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt @@ -3,11 +3,14 @@ package net.pterodactylus.sone.web.ajax import com.google.common.base.Optional import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.getInstance import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.asOptional +import net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue import org.hamcrest.Matchers.nullValue import org.junit.Test @@ -89,4 +92,9 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = :: whenever(this.recipientId).thenReturn(recipientId.asOptional()) } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + } -- 2.7.4