🚚 Move new elements mock to test objects
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / TestObjects.kt
index f902533..e8e660d 100644 (file)
@@ -25,6 +25,7 @@ import net.pterodactylus.sone.test.get
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
 import net.pterodactylus.sone.utils.asOptional
+import net.pterodactylus.sone.web.NewElements
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.notify.Notification
@@ -49,6 +50,7 @@ open class TestObjects {
        val preferences = Preferences(eventBus)
        val updateChecker = mock<UpdateChecker>()
        val elementLoader = mock<ElementLoader>()
+       val newElements = mock<NewElements>()
 
        val toadletContext = mock<ToadletContext>()
        val freenetRequest = mock<FreenetRequest>()
@@ -80,15 +82,11 @@ open class TestObjects {
 
        init {
                whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
-               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(currentSone)
-               whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone)
-               whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone)
+               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.core).thenReturn(core)
                whenever(webInterface.formPassword).then { formPassword }
                whenever(webInterface.getNotifications(currentSone)).thenAnswer { notifications.values }
                whenever(webInterface.getNotification(ArgumentMatchers.anyString())).then { notifications[it[0]].asOptional() }
-               whenever(webInterface.getNewPosts(currentSone)).thenAnswer { newPosts.values }
-               whenever(webInterface.getNewReplies(currentSone)).thenAnswer { newReplies.values }
                whenever(webInterface.translation).thenReturn(translation)
 
                whenever(core.preferences).thenReturn(preferences)
@@ -107,6 +105,9 @@ open class TestObjects {
                        linkedElements[it.getArgument(0)] ?: LinkedElement(it.getArgument(0), loading = true)
                }
 
+               whenever(newElements.newPosts).then { newPosts.values }
+               whenever(newElements.newReplies).then { newReplies.values }
+
                whenever(currentSone.options).thenReturn(DefaultSoneOptions())
                currentSone.mock("soneId", "Sone_Id", true, 1000, idle)
 
@@ -139,9 +140,7 @@ open class TestObjects {
        }
 
        protected fun unsetCurrentSone() {
-               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext), ArgumentMatchers.anyBoolean())).thenReturn(null)
-               whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(null)
-               whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(null)
+               whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(null)
        }
 
        protected fun postRequest() {