From 550309db774fb837ba2172571b04c24ee417e4e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 7 Apr 2017 22:39:51 +0200 Subject: [PATCH] Make linked element render filter injectable --- .../pterodactylus/sone/template/LinkedElementRenderFilter.kt | 3 ++- .../sone/template/LinkedElementRenderFilterTest.kt | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt index 5de5dfe..8d328be 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt @@ -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() diff --git a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt index 9127f58..e8e7fc3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt @@ -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(), notNullValue()) + } + } -- 2.7.4