import freenet.support.SimpleFieldSet
import net.pterodactylus.sone.core.Core
-import net.pterodactylus.sone.test.asOptional
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.containsInAnyOrder
@Test
fun `command does not require write access`() {
- assertThat(command.requiresWriteAccess(), equalTo(false))
+ assertThat(command.requiresWriteAccess, equalTo(false))
}
@Test
}
private fun setupAllPostsAndReplies() {
- parameters.putSingle("Sone", "ValidSoneId")
+ parameters += "Sone" to "ValidSoneId"
whenever(localSone.id).thenReturn("ValidSoneId")
- whenever(core.getSone("ValidSoneId")).thenReturn(localSone.asOptional())
- whenever(core.getSone("Friend1")).thenReturn(friend1.asOptional())
+ whenever(core.getSone("ValidSoneId")).thenReturn(localSone)
+ whenever(core.getSone("Friend1")).thenReturn(friend1)
whenever(core.getLikes(post1)).thenReturn(setOf(sone3, sone4))
whenever(core.getLikes(post1Reply1)).thenReturn(setOf(sone2, sone3))
whenever(core.getLikes(post1Reply2)).thenReturn(setOf(sone3))
@Test
fun `request with larger start than number of posts returns empty feed`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "20")
+ parameters += "StartPost" to "20"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("0"))
@Test
fun `request with max posts of 2 returns the first two posts`() {
setupAllPostsAndReplies()
- parameters.putSingle("MaxPosts", "2")
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("2"))
@Test
fun `request with max posts of 2 and start post of 1 returns the center two posts`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "1")
- parameters.putSingle("MaxPosts", "2")
+ parameters += "StartPost" to "1"
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("2"))
@Test
fun `request with max posts of 2 and start post of 3 returns the last post`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "3")
- parameters.putSingle("MaxPosts", "2")
+ parameters += "StartPost" to "3"
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("1"))