Add test for DI constructability of EditImageAjaxPage
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 23 Jan 2018 20:54:41 +0000 (21:54 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 23 Jan 2018 20:54:41 +0000 (21:54 +0100)
src/main/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPageTest.kt

index dbeb2d2..b0ce048 100644 (file)
@@ -10,11 +10,12 @@ import net.pterodactylus.sone.utils.parameters
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.template.TemplateContext
+import javax.inject.Inject
 
 /**
  * Page that stores a user’s image modifications.
  */
-class EditImageAjaxPage(webInterface: WebInterface,
+class EditImageAjaxPage @Inject constructor(webInterface: WebInterface,
                private val parserFilter: ParserFilter,
                private val shortenFilter: ShortenFilter,
                private val renderFilter: RenderFilter) : JsonPage("editImage.ajax", webInterface) {
index dad6c02..26436a3 100644 (file)
@@ -8,10 +8,14 @@ import net.pterodactylus.sone.template.ParserFilter
 import net.pterodactylus.sone.template.RenderFilter
 import net.pterodactylus.sone.template.ShortenFilter
 import net.pterodactylus.sone.test.argumentCaptor
+import net.pterodactylus.sone.test.getInstance
+import net.pterodactylus.sone.test.isProvidedByMock
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.web.baseInjector
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Test
 import org.mockito.ArgumentMatchers.any
 import org.mockito.ArgumentMatchers.eq
@@ -113,4 +117,13 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                assertThat(parameterCaptor.value["sone"], equalTo<Any>(sone))
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+               assertThat(baseInjector.createChildInjector(
+                               ParserFilter::class.isProvidedByMock(),
+                               ShortenFilter::class.isProvidedByMock(),
+                               RenderFilter::class.isProvidedByMock()
+               ).getInstance<EditImageAjaxPage>(), notNullValue())
+       }
+
 }