Convert dismiss notification page test to use new web page test base
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / WebPageTest2.kt
index 5ec3ead..5682b11 100644 (file)
@@ -9,6 +9,7 @@ import net.pterodactylus.sone.data.Image
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.PostReply
 import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.data.TemporaryImage
 import net.pterodactylus.sone.freenet.wot.OwnIdentity
 import net.pterodactylus.sone.test.deepMock
 import net.pterodactylus.sone.test.get
@@ -19,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
@@ -68,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 {
@@ -91,13 +94,15 @@ open class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTemplatePa
                whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] }
                whenever(core.getImage(anyString())).then { allImages[it[0]]}
                whenever(core.getImage(anyString(), anyBoolean())).then { allImages[it[0]]}
+               whenever(core.getTemporaryImage(anyString())).thenReturn(null)
        }
 
        private fun setupWebInterface() {
                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() {
@@ -190,6 +195,14 @@ 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)
+       }
+
        fun verifyNoRedirect(assertions: () -> Unit) {
                var caughtException: Exception? = null
                try {