1 package net.pterodactylus.sone.fcp
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.test.whenever
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.junit.Before
11 * Unit test for [GetSonesCommand].
13 class GetSonesCommandTest : SoneCommandTest() {
15 private val sone1 = createSone("SoneId1", "Sone1", "Sone", "#1", 1000)
16 private val sone2 = createSone("SoneId2", "Sone2", "Sone", "#2", 2000)
17 private val sone3 = createSone("SoneId3", "Sone3", "Sone", "#3", 3000)
19 override fun createCommand(core: Core) = GetSonesCommand(core)
23 whenever(core.sones).thenReturn(setOf(sone2, sone3, sone1))
27 fun `request without parameters lists all sones`() {
28 val replyParameters = command.execute(parameters).replyParameters
30 assertThat(replyParameters["Message"], equalTo("Sones"))
31 assertThat(replyParameters["Sones.Count"], equalTo("3"))
32 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone1))
33 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone2))
34 assertThat(replyParameters.parseSone("Sones.2."), matchesSone(sone3))
38 fun `skipping the first sone lists the last two sones`() {
39 parameters += "StartSone" to "1"
40 val replyParameters = command.execute(parameters).replyParameters
42 assertThat(replyParameters["Message"], equalTo("Sones"))
43 assertThat(replyParameters["Sones.Count"], equalTo("2"))
44 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone2))
45 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone3))
49 fun `requesting only two sones lists the first two sones`() {
50 parameters += "MaxSones" to "2"
51 val replyParameters = command.execute(parameters).replyParameters
53 assertThat(replyParameters["Message"], equalTo("Sones"))
54 assertThat(replyParameters["Sones.Count"], equalTo("2"))
55 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone1))
56 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone2))
60 fun `skipping more sones than there are lists no sones`() {
61 parameters += "StartSone" to "20"
62 val replyParameters = command.execute(parameters).replyParameters
64 assertThat(replyParameters["Message"], equalTo("Sones"))
65 assertThat(replyParameters["Sones.Count"], equalTo("0"))