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=4dddbe599198b2c657173a1cbe2da0f398658fb9;hb=c3407a682f9f81b27d0354e59fe9e3d3d6dffcd6;hpb=51b58fad3a00b2d9cae45345ac066e89233ba0b5 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 4dddbe5..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 @@ -52,7 +53,7 @@ abstract class JsonPageTest( protected val preferences = Preferences(eventBus) protected val elementLoader = mock() protected open val page: JsonPage by lazy { pageSupplier(webInterface) } - protected val json by lazy { page.createJsonObject(freenetRequest)!! } + protected val json by lazy { page.createJsonObject(freenetRequest) } protected val toadletContext = mock() protected val freenetRequest = mock() @@ -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]] } @@ -178,8 +183,16 @@ abstract class JsonPageTest( localSones += id to sone } - protected fun addPost(id: String, post: Post) { - posts[id] = post + protected fun addPost(post: Post, id: String? = null) { + 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) = @@ -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) {