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 `command does not require write access`() {
28 assertThat(command.requiresWriteAccess, equalTo(false))
32 fun `request without parameters lists all sones`() {
33 val replyParameters = command.execute(parameters).replyParameters
35 assertThat(replyParameters["Message"], equalTo("Sones"))
36 assertThat(replyParameters["Sones.Count"], equalTo("3"))
37 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone1))
38 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone2))
39 assertThat(replyParameters.parseSone("Sones.2."), matchesSone(sone3))
43 fun `skipping the first sone lists the last two sones`() {
44 parameters += "StartSone" to "1"
45 val replyParameters = command.execute(parameters).replyParameters
47 assertThat(replyParameters["Message"], equalTo("Sones"))
48 assertThat(replyParameters["Sones.Count"], equalTo("2"))
49 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone2))
50 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone3))
54 fun `requesting only two sones lists the first two sones`() {
55 parameters += "MaxSones" to "2"
56 val replyParameters = command.execute(parameters).replyParameters
58 assertThat(replyParameters["Message"], equalTo("Sones"))
59 assertThat(replyParameters["Sones.Count"], equalTo("2"))
60 assertThat(replyParameters.parseSone("Sones.0."), matchesSone(sone1))
61 assertThat(replyParameters.parseSone("Sones.1."), matchesSone(sone2))
65 fun `skipping more sones than there are lists no sones`() {
66 parameters += "StartSone" to "20"
67 val replyParameters = command.execute(parameters).replyParameters
69 assertThat(replyParameters["Message"], equalTo("Sones"))
70 assertThat(replyParameters["Sones.Count"], equalTo("0"))