1 package net.pterodactylus.xdcc.ui.stdin
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
17 class DownloadCommandTest {
19 private val core = Mockito.mock(Core::class.java)
20 private val command = DownloadCommand(core)
21 private val state = State()
24 fun `command has correct name`() {
25 assertThat(command.name, equalTo("download"))
29 fun `command has correct aliases`() {
30 assertThat(command.aliases, containsInAnyOrder("get"))
34 fun `executing command without parameters will not fetch anything`() {
35 command.execute(state, emptyList(), StringWriter())
36 verify(core, never()).fetch(any(), any())
40 fun `executing command without parameters will return old state`() {
41 val newState = command.execute(state, emptyList(), StringWriter())
42 assertThat(newState, equalTo(state))
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())
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))
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())
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))
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)
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))