Add test for DI constructability of CreatePostAjaxPage
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 22 Jan 2018 06:06:47 +0000 (07:06 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 22 Jan 2018 06:06:47 +0000 (07:06 +0100)
src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt

index 868e990..47535c0 100644 (file)
@@ -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
index 8449453..821198f 100644 (file)
@@ -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<CreatePostAjaxPage>(), notNullValue())
+       }
+
 }