Replace Sone provider interface with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / template / RenderFilterTest.kt
index af74531..0920280 100644 (file)
@@ -1,6 +1,5 @@
 package net.pterodactylus.sone.template
 
-import com.google.common.base.Optional
 import net.pterodactylus.sone.core.Core
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.Profile
@@ -10,7 +9,6 @@ import net.pterodactylus.sone.text.FreemailPart
 import net.pterodactylus.sone.text.FreenetLinkPart
 import net.pterodactylus.sone.text.LinkPart
 import net.pterodactylus.sone.text.Part
-import net.pterodactylus.sone.text.PartContainer
 import net.pterodactylus.sone.text.PlainTextPart
 import net.pterodactylus.sone.text.PostPart
 import net.pterodactylus.sone.text.SonePart
@@ -23,7 +21,6 @@ import org.hamcrest.Matchers.containsInAnyOrder
 import org.jsoup.Jsoup
 import org.jsoup.nodes.Attribute
 import org.jsoup.nodes.Element
-import org.jsoup.nodes.TextNode
 import org.junit.Test
 import org.mockito.Mockito.`when`
 import java.net.URLEncoder
@@ -61,70 +58,6 @@ class RenderFilterTest {
        private fun renderParts(vararg part: Part) = filter.format(templateContext, listOf(*part), parameters) as String
 
        @Test
-       fun `plain text part is shortened if length exceeds maxl ength`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This is a long text.")), `is`("This is a …"))
-       }
-
-       @Test
-       fun `plain text part is not shortened if length does not exceed max length`() {
-               setLengthAndCutOffLength(20, 10)
-               assertThat(renderParts(PlainTextPart("This is a long text.")), `is`("This is a …"))
-       }
-
-       @Test
-       fun `short parts are not shortened`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This.")), `is`("This."))
-       }
-
-       @Test
-       fun `multiple plain text parts are shortened`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This "), PlainTextPart("is a long text.")), `is`("This is a …"))
-       }
-
-       @Test
-       fun `parts after length has been reached are ignored`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This is a long text."), PlainTextPart(" And even more.")), `is`("This is a …"))
-       }
-
-       @Test
-       fun `link parts are not shortened`() {
-               setLengthAndCutOffLength(15, 10)
-               val linkNode = Jsoup.parseBodyFragment(renderParts(FreenetLinkPart("KSK@gpl.txt", "This is a long text.", false))).body().child(0)
-               verifyLink(linkNode, "/KSK@gpl.txt", "freenet", "KSK@gpl.txt", "This is a long text.")
-       }
-
-       @Test
-       fun `additional link parts are ignored`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This is a long text."), FreenetLinkPart("KSK@gpl.txt", "This is a long text.", false)), `is`("This is a …"))
-       }
-
-       private fun setLengthAndCutOffLength(length: Int, cutOffLength: Int) {
-               parameters.put("length", length)
-               parameters.put("cut-off-length", cutOffLength)
-       }
-
-       @Test
-       fun `sone parts are added but their length is ignored`() {
-               setLengthAndCutOffLength(15, 10)
-               val body = Jsoup.parseBodyFragment(renderParts(SonePart(sone), PlainTextPart("This is a long text."))).body()
-               val linkNode = body.childNode(0) as Element
-               println(linkNode)
-               verifyLink(linkNode, "viewSone.html?sone=$SONE_IDENTITY", "in-sone", "First", "First")
-               assertThat((body.childNode(1) as TextNode).text(), `is`("This is a …"))
-       }
-
-       @Test
-       fun `additional sone parts are ignored`() {
-               setLengthAndCutOffLength(15, 10)
-               assertThat(renderParts(PlainTextPart("This is a long text."), SonePart(sone)), `is`("This is a …"))
-       }
-
-       @Test
        fun `freenet link is rendered correctly`() {
                val linkNode = renderParts(FreenetLinkPart("KSK@gpl.txt", "gpl.txt", false)).toLinkNode()
                verifyLink(linkNode, "/KSK@gpl.txt", "freenet", "KSK@gpl.txt", "gpl.txt")
@@ -167,7 +100,7 @@ class RenderFilterTest {
                `when`(sone.profile).thenReturn(Profile(sone))
                `when`(sone.name).thenReturn(name)
                sone.profile.firstName = firstName
-               `when`(core.getSone(identity)).thenReturn(Optional.of<Sone>(sone))
+               `when`(core.getSone(identity)).thenReturn(sone)
                return sone
        }
 
@@ -209,10 +142,8 @@ class RenderFilterTest {
 
        @Test
        fun `multiple parts are rendered correctly`() {
-               val parts = PartContainer()
-               parts.add(PlainTextPart("te"))
-               parts.add(PlainTextPart("xt"))
-               assertThat(renderParts(parts), `is`("text"))
+               val parts = arrayOf(PlainTextPart("te"), PlainTextPart("xt"))
+               assertThat(renderParts(*parts), `is`("text"))
        }
 
        @Test