From: David ‘Bombe’ Roden Date: Sun, 18 Jun 2017 13:42:10 +0000 (+0200) Subject: Convert view Sone page test to new web page test base X-Git-Tag: 0.9.7^2~159 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c73c1bc9d249ec18b5e7b6d938cdfeead68efec2;p=Sone.git Convert view Sone page test to new web page test base --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt index 8776af7..e3259f5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt @@ -12,13 +12,10 @@ import org.junit.Test /** * Unit test for [ViewPostPage]. */ -class ViewPostPageTest: WebPageTest() { +class ViewPostPageTest: WebPageTest2(::ViewPostPage) { - private val page = ViewPostPage(template, webInterface) private val post = mock() - override fun getPage() = page - @Test fun `page returns correct path`() { assertThat(page.path, equalTo("viewPost.html")) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt index 6981f9f..40910fe 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt @@ -4,6 +4,7 @@ import com.google.common.eventbus.EventBus import freenet.clients.http.ToadletContext import freenet.support.api.HTTPRequest import net.pterodactylus.sone.core.Preferences +import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.deepMock import net.pterodactylus.sone.test.get @@ -41,6 +42,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla private val toadletContext = deepMock() private val getRequestParameters = mutableMapOf>() private val allSones = mutableMapOf() + private val allPosts = mutableMapOf() private val translations = mutableMapOf() @Before @@ -48,6 +50,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla whenever(core.preferences).thenReturn(preferences) whenever(core.sones).then { allSones.values } whenever(core.getSone(anyString())).then { allSones[it[0]].asOptional() } + whenever(core.getPost(anyString())).then { allPosts[it[0]].asOptional() } } @Before @@ -85,6 +88,10 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla allSones[id] = sone } + fun addPost(id: String, post: Post) { + allPosts[id] = post + } + fun addTranslation(key: String, value: String) { translations[key] = value }