projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow adding replies without specific ID
[Sone.git]
/
src
/
test
/
kotlin
/
net
/
pterodactylus
/
sone
/
web
/
ajax
/
JsonPageTest.kt
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
cb5ee5a
..
60b2627
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt
@@
-8,6
+8,8
@@
import net.pterodactylus.sone.core.Core
import net.pterodactylus.sone.core.ElementLoader
import net.pterodactylus.sone.core.LinkedElement
import net.pterodactylus.sone.core.Preferences
import net.pterodactylus.sone.core.ElementLoader
import net.pterodactylus.sone.core.LinkedElement
import net.pterodactylus.sone.core.Preferences
+import net.pterodactylus.sone.data.Album
+import net.pterodactylus.sone.data.Image
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
import net.pterodactylus.sone.data.Profile
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
import net.pterodactylus.sone.data.Profile
@@
-50,7
+52,7
@@
abstract class JsonPageTest(
protected val preferences = Preferences(eventBus)
protected val elementLoader = mock<ElementLoader>()
protected open val page: JsonPage by lazy { pageSupplier(webInterface) }
protected val preferences = Preferences(eventBus)
protected val elementLoader = mock<ElementLoader>()
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<ToadletContext>()
protected val freenetRequest = mock<FreenetRequest>()
protected val toadletContext = mock<ToadletContext>()
protected val freenetRequest = mock<FreenetRequest>()
@@
-69,6
+71,8
@@
abstract class JsonPageTest(
private val newReplies = mutableMapOf<String, PostReply>()
private val linkedElements = mutableMapOf<String, LinkedElement>()
private val notifications = mutableMapOf<String, Notification>()
private val newReplies = mutableMapOf<String, PostReply>()
private val linkedElements = mutableMapOf<String, LinkedElement>()
private val notifications = mutableMapOf<String, Notification>()
+ private val albums = mutableMapOf<String, Album>()
+ private val images = mutableMapOf<String, Image>()
@Before
fun setupWebInterface() {
@Before
fun setupWebInterface() {
@@
-89,6
+93,9
@@
abstract class JsonPageTest(
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() }
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() }
+ whenever(core.getAlbum(anyString())).then { albums[it[0]] }
+ whenever(core.getImage(anyString())).then { images[it[0]] }
+ whenever(core.getImage(anyString(), anyBoolean())).then { images[it[0]] }
}
@Before
}
@Before
@@
-171,8
+178,8
@@
abstract class JsonPageTest(
localSones += id to sone
}
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 addNewPost(id: String, soneId: String, time: Long, recipientId: String? = null) =
}
protected fun addNewPost(id: String, soneId: String, time: Long, recipientId: String? = null) =
@@
-184,8
+191,8
@@
abstract class JsonPageTest(
whenever(this.recipientId).thenReturn(recipientId.asOptional())
}.also { newPosts[id] = it }
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) {
}
protected fun addNewReply(id: String, soneId: String, postId: String, postSoneId: String) {
@@
-206,6
+213,14
@@
abstract class JsonPageTest(
linkedElements[link] = LinkedElement(link, failed, loading)
}
linkedElements[link] = LinkedElement(link, failed, loading)
}
+ protected fun addAlbum(album: Album, albumId: String? = null) {
+ albums[albumId ?: album.id] = album
+ }
+
+ protected fun addImage(image: Image, imageId: String? = null) {
+ images[imageId ?: image.id] = image
+ }
+
@Test
fun `page returns correct path`() {
assertThat(page.path, equalTo(expectedPath))
@Test
fun `page returns correct path`() {
assertThat(page.path, equalTo(expectedPath))