🎨 Use equalTo instead of is
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / GetSonesCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
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
8 import org.junit.Test
9
10 /**
11  * Unit test for [GetSonesCommand].
12  */
13 class GetSonesCommandTest : SoneCommandTest() {
14
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)
18
19         override fun createCommand(core: Core) = GetSonesCommand(core)
20
21         @Before
22         fun setupSones() {
23                 whenever(core.sones).thenReturn(setOf(sone2, sone3, sone1))
24         }
25
26         @Test
27         fun `command does not require write access`() {
28                 assertThat(command.requiresWriteAccess, equalTo(false))
29         }
30
31         @Test
32         fun `request without parameters lists all sones`() {
33                 val replyParameters = command.execute(parameters).replyParameters
34
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))
40         }
41
42         @Test
43         fun `skipping the first sone lists the last two sones`() {
44                 parameters += "StartSone" to "1"
45                 val replyParameters = command.execute(parameters).replyParameters
46
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))
51         }
52
53         @Test
54         fun `requesting only two sones lists the first two sones`() {
55                 parameters += "MaxSones" to "2"
56                 val replyParameters = command.execute(parameters).replyParameters
57
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))
62         }
63
64         @Test
65         fun `skipping more sones than there are lists no sones`() {
66                 parameters += "StartSone" to "20"
67                 val replyParameters = command.execute(parameters).replyParameters
68
69                 assertThat(replyParameters["Message"], equalTo("Sones"))
70                 assertThat(replyParameters["Sones.Count"], equalTo("0"))
71         }
72
73 }