Make linked element render filter injectable
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 7 Apr 2017 20:39:51 +0000 (22:39 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 8 Apr 2017 13:22:56 +0000 (15:22 +0200)
src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt
src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt

index 5de5dfe..8d328be 100644 (file)
@@ -7,11 +7,12 @@ import net.pterodactylus.util.template.TemplateContextFactory
 import net.pterodactylus.util.template.TemplateParser
 import java.io.StringReader
 import java.io.StringWriter
+import javax.inject.Inject
 
 /**
  * Renders all kinds of [LinkedElement]s.
  */
-class LinkedElementRenderFilter(private val templateContextFactory: TemplateContextFactory) : Filter {
+class LinkedElementRenderFilter @Inject constructor(private val templateContextFactory: TemplateContextFactory): Filter {
 
        companion object {
                private val loadedImageTemplate = """<%include linked/image.html>""".parse()
index 9127f58..e8e7fc3 100644 (file)
@@ -1,11 +1,15 @@
 package net.pterodactylus.sone.template
 
+import com.google.inject.Guice
 import net.pterodactylus.sone.core.LinkedElement
+import net.pterodactylus.sone.test.getInstance
+import net.pterodactylus.sone.test.isProvidedByMock
 import net.pterodactylus.util.template.ClassPathTemplateProvider
 import net.pterodactylus.util.template.HtmlFilter
 import net.pterodactylus.util.template.TemplateContextFactory
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.`is`
+import org.hamcrest.Matchers.notNullValue
 import org.hamcrest.Matchers.nullValue
 import org.jsoup.Jsoup
 import org.junit.Test
@@ -52,4 +56,10 @@ class LinkedElementRenderFilterTest {
                assertThat(spanNode.attr("style"), `is`("background-image: url('/KSK@gpl.png')"))
        }
 
+       @Test
+       fun `render filter can be created by guice`() {
+           val injector = Guice.createInjector(TemplateContextFactory::class.isProvidedByMock())
+               assertThat(injector.getInstance<LinkedElementRenderFilter>(), notNullValue())
+       }
+
 }