import net.pterodactylus.sone.test.Matchers.*
import net.pterodactylus.util.config.*
import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers
import org.hamcrest.Matchers.*
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.*
@Test
fun `post replies are managed correctly`() {
val firstPost = createPost(absent())
- val firstPostFirstReply = createPostReply(firstPost, 1000L)
+ val firstPostFirstReply = createPostReply(id = "p1r1", post = firstPost, time = 1000L)
val secondPost = createPost(absent())
- val secondPostFirstReply = createPostReply(secondPost, 1000L)
- val secondPostSecondReply = createPostReply(secondPost, 2000L)
+ val secondPostFirstReply = createPostReply(id = "p2r1", post = secondPost, time = 1000L)
+ val secondPostSecondReply = createPostReply(id = "p2r2", post = secondPost, time = 2000L)
memoryDatabase.storePost(firstPost)
memoryDatabase.storePost(secondPost)
memoryDatabase.storePostReply(firstPostFirstReply)
memoryDatabase.storePostReply(secondPostFirstReply)
memoryDatabase.storePostReply(secondPostSecondReply)
- assertThat(memoryDatabase.getReplies(firstPost.id), contains(firstPostFirstReply))
- assertThat(memoryDatabase.getReplies(secondPost.id), contains(secondPostFirstReply, secondPostSecondReply))
- }
-
- private fun createPostReply(post: Post, time: Long): PostReply {
- val postReply = mock<PostReply>()
- whenever(postReply.id).thenReturn(randomUUID().toString())
- whenever(postReply.time).thenReturn(time)
- whenever(postReply.post).thenReturn(of(post))
- val postId = post.id
- whenever(postReply.postId).thenReturn(postId)
- return postReply
+ assertThat(memoryDatabase.getReplies(firstPost.id).map(PostReply::id), Matchers.contains("p1r1"))
+ assertThat(memoryDatabase.getReplies(secondPost.id).map(PostReply::id), contains("p2r1", "p2r2"))
}
@Test
prepareConfigurationValues()
val postReply = mock<PostReply>()
whenever(postReply.id).thenReturn("post-reply-id")
- memoryDatabase.setPostReplyKnown(postReply, true)
+ memoryDatabase.setPostReplyKnown(postReply)
assertThat(configuration.getStringValue("KnownReplies/0/ID").value, equalTo("post-reply-id"))
assertThat(configuration.getStringValue("KnownReplies/1/ID").value, equalTo<Any>(null))
}
prepareConfigurationValues()
val postReply = mock<PostReply>()
whenever(postReply.id).thenReturn("post-reply-id")
- memoryDatabase.setPostReplyKnown(postReply, true)
- memoryDatabase.setPostReplyKnown(postReply, true)
+ memoryDatabase.setPostReplyKnown(postReply)
+ memoryDatabase.setPostReplyKnown(postReply)
verify(configuration, times(1)).getStringValue("KnownReplies/1/ID")
}