Convert dismiss notification page test to use new web page test base
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 21:45:32 +0000 (23:45 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 21:45:32 +0000 (23:45 +0200)
src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt

index 5ce0dcb..acb3d0a 100644 (file)
@@ -13,13 +13,10 @@ import org.mockito.Mockito.verify
 /**
  * Unit test for [DismissNotificationPage].
  */
-class DismissNotificationPageTest: WebPageTest() {
+class DismissNotificationPageTest: WebPageTest2(::DismissNotificationPage) {
 
-       private val page = DismissNotificationPage(template, webInterface)
        private val notification = mock<Notification>()
 
-       override fun getPage() = page
-
        @Test
        fun `page returns correct path`() {
                assertThat(page.path, equalTo("dismissNotification.html"))
index 69ac20a..5682b11 100644 (file)
@@ -20,6 +20,7 @@ import net.pterodactylus.sone.utils.asOptional
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException
+import net.pterodactylus.util.notify.Notification
 import net.pterodactylus.util.template.Template
 import net.pterodactylus.util.template.TemplateContext
 import net.pterodactylus.util.web.Method
@@ -69,6 +70,7 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa
        private val perPostReplies = mutableMapOf<String, PostReply>()
        private val allAlbums = mutableMapOf<String, Album>()
        private val allImages = mutableMapOf<String, Image>()
+       private val notifications = mutableMapOf<String, Notification>()
        private val translations = mutableMapOf<String, String>()
 
        init {
@@ -99,7 +101,8 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)
-               whenever(webInterface.getNotifications(currentSone)).thenReturn(emptyList())
+               whenever(webInterface.getNotifications(currentSone)).then { notifications.values }
+               whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() }
        }
 
        private fun setupHttpRequest() {
@@ -192,6 +195,10 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa
                translations[key] = value
        }
 
+       fun addNotification(id: String, notification: Notification) {
+               notifications[id] = notification
+       }
+
        fun addTemporaryImage(id: String, temporaryImage: TemporaryImage) {
                whenever(core.getTemporaryImage(id)).thenReturn(temporaryImage)
        }