✅ Add more tests for current behaviour
[xudocci.git] / src / test / java / net / pterodactylus / xdcc / ui / stdin / DownloadCommandTest.kt
1 package net.pterodactylus.xdcc.ui.stdin
2
3 import net.pterodactylus.xdcc.core.Core
4 import net.pterodactylus.xdcc.data.Bot
5 import net.pterodactylus.xdcc.data.Pack
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.containsInAnyOrder
8 import org.hamcrest.Matchers.equalTo
9 import org.mockito.Matchers.any
10 import org.mockito.Mockito
11 import org.mockito.Mockito.mock
12 import org.mockito.Mockito.never
13 import org.mockito.Mockito.verify
14 import java.io.StringWriter
15 import kotlin.test.Test
16
17 class DownloadCommandTest {
18
19         private val core = Mockito.mock(Core::class.java)
20         private val command = DownloadCommand(core)
21         private val state = State()
22
23         @Test
24         fun `command has correct name`() {
25                 assertThat(command.name, equalTo("download"))
26         }
27
28         @Test
29         fun `command has correct aliases`() {
30                 assertThat(command.aliases, containsInAnyOrder("get"))
31         }
32
33         @Test
34         fun `executing command without parameters will not fetch anything`() {
35                 command.execute(state, emptyList(), StringWriter())
36                 verify(core, never()).fetch(any(), any())
37         }
38
39         @Test
40         fun `executing command without parameters will return old state`() {
41                 val newState = command.execute(state, emptyList(), StringWriter())
42                 assertThat(newState, equalTo(state))
43         }
44
45         @Test
46         fun `executing command with single non-numeric parameter will not fetch anything`() {
47                 command.execute(state, listOf("a"), StringWriter())
48                 verify(core, never()).fetch(any(), any())
49         }
50
51         @Test
52         fun `executing command with single non-numeric parameter will return old state`() {
53                 val newState = command.execute(state, listOf("a"), StringWriter())
54                 assertThat(newState, equalTo(state))
55         }
56
57         @Test
58         fun `executing command with single numeric parameter but no last results will not fetch anything`() {
59                 command.execute(state, listOf("0"), StringWriter())
60                 verify(core, never()).fetch(any(), any())
61         }
62
63         @Test
64         fun `executing command with single numeric parameter but no last results will return old state`() {
65                 val newState = command.execute(state, listOf("0"), StringWriter())
66                 assertThat(newState, equalTo(state))
67         }
68
69         @Test
70         fun `executing command with single numeric parameter and last results will fetch correct pack from correct bot`() {
71                 val bot = mock(Bot::class.java)
72                 val pack = Pack("1", "2", "3")
73                 val state = state.setLastResults(listOf(Result(core, bot, pack)))
74                 command.execute(state, listOf("0"), StringWriter())
75                 verify(core).fetch(bot, pack)
76         }
77
78         @Test
79         fun `executing command with single numeric parameter and last results will return old state`() {
80                 val bot = mock(Bot::class.java)
81                 val pack = Pack("1", "2", "3")
82                 val state = state.setLastResults(listOf(Result(core, bot, pack)))
83                 val newState = command.execute(state, listOf("1"), StringWriter())
84                 assertThat(newState, equalTo(state))
85         }
86
87 }