X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPageTest.kt;h=f3558fa94fe229eedef53000be34205916bbf7f5;hb=e5224bcc64cbbe5b0396984554d76dc3a5960e80;hp=afa9b17039e24df775301ff3d92e5e6952bfedf1;hpb=4588d890e2d7eae8f9ca727a4435ad388c172615;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index afa9b17..f3558fa 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -61,9 +61,10 @@ abstract class JsonPageTest( private val remoteSones = mutableMapOf() private val posts = mutableMapOf() private val newPosts = mutableMapOf() + private val replies = mutableMapOf() private val newReplies = mutableMapOf() private val linkedElements = mutableMapOf() - private val notifications = mutableListOf() + private val notifications = mutableMapOf() @Before fun setupWebInterface() { @@ -71,7 +72,8 @@ abstract class JsonPageTest( whenever(webInterface.getCurrentSoneCreatingSession(toadletContext)).thenReturn(currentSone) whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(currentSone) whenever(webInterface.core).thenReturn(core) - whenever(webInterface.getNotifications(currentSone)).thenAnswer { notifications } + whenever(webInterface.getNotifications(currentSone)).thenAnswer { notifications.values } + whenever(webInterface.getNotification(anyString())).then { notifications[it[0]].asOptional() } whenever(webInterface.getNewPosts(currentSone)).thenAnswer { newPosts.values } whenever(webInterface.getNewReplies(currentSone)).thenAnswer { newReplies.values } } @@ -81,6 +83,7 @@ abstract class JsonPageTest( whenever(core.getSone(anyString())).thenAnswer { (localSones + remoteSones)[it.getArgument(0)].asOptional() } whenever(core.getLocalSone(anyString())).thenAnswer { localSones[it[0]] } whenever(core.getPost(anyString())).thenAnswer { (posts + newPosts)[it[0]].asOptional() } + whenever(core.getPostReply(anyString())).then { replies[it[0]].asOptional() } } @Before @@ -151,8 +154,8 @@ abstract class JsonPageTest( requestParts += key to value } - protected fun addNotification(vararg notifications: Notification) { - this.notifications += notifications + protected fun addNotification(notification: Notification, notificationId: String? = null) { + notifications[notificationId ?: notification.id] = notification } protected fun addSone(sone: Sone) { @@ -176,6 +179,10 @@ abstract class JsonPageTest( whenever(this.recipientId).thenReturn(recipientId.asOptional()) }.also { newPosts[id] = it } + protected fun addReply(id: String, reply: PostReply) { + replies[id] = reply + } + protected fun addNewReply(id: String, soneId: String, postId: String, postSoneId: String) { newReplies[id] = mock().apply { whenever(this.id).thenReturn(id)