X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPageTest.kt;h=d5314c5ae27862b9992ffea8a9fb45711a8f33bd;hp=56568747e2ce4048023ba764b41336256dd623cf;hb=c3407a682f9f81b27d0354e59fe9e3d3d6dffcd6;hpb=0e8c877c57ccdd7d8d7f7f3c80d373ac0b5c3714 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 5656874..d5314c5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -29,6 +29,7 @@ import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Before import org.junit.Test +import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyString @@ -66,8 +67,10 @@ abstract class JsonPageTest( private val localSones = mutableMapOf() private val remoteSones = mutableMapOf() private val posts = mutableMapOf() + private val postLikes = mutableMapOf>() private val newPosts = mutableMapOf() private val replies = mutableMapOf() + private val replyLikes = mutableMapOf>() private val newReplies = mutableMapOf() private val linkedElements = mutableMapOf() private val notifications = mutableMapOf() @@ -92,6 +95,8 @@ 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.getLikes(any())).then { postLikes[it[0]] ?: emptySet() } + whenever(core.getLikes(any())).then { replyLikes[it[0]] ?: emptySet() } whenever(core.getPostReply(anyString())).then { replies[it[0]].asOptional() } whenever(core.getAlbum(anyString())).then { albums[it[0]] } whenever(core.getImage(anyString())).then { images[it[0]] } @@ -182,6 +187,14 @@ abstract class JsonPageTest( posts[id ?: post.id] = post } + protected fun addLikes(post: Post, vararg sones: Sone) { + postLikes[post] = setOf(*sones) + } + + protected fun addLikes(reply: PostReply, vararg sones: Sone) { + replyLikes[reply] = setOf(*sones) + } + protected fun addNewPost(id: String, soneId: String, time: Long, recipientId: String? = null) = mock().apply { whenever(this.id).thenReturn(id) @@ -191,8 +204,8 @@ 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 addReply(reply: PostReply, id: String? = null) { + replies[id ?: reply.id] = reply } protected fun addNewReply(id: String, soneId: String, postId: String, postSoneId: String) {