package net.pterodactylus.xdcc.ui.stdin
import net.pterodactylus.xdcc.core.Core
+import net.pterodactylus.xdcc.data.Bot
+import net.pterodactylus.xdcc.data.Pack
import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.containsInAnyOrder
import org.hamcrest.Matchers.equalTo
import org.mockito.Matchers.any
import org.mockito.Mockito
+import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import java.io.StringWriter
private val state = State()
@Test
+ fun `command has correct name`() {
+ assertThat(command.name, equalTo("download"))
+ }
+
+ @Test
+ fun `command has correct aliases`() {
+ assertThat(command.aliases, containsInAnyOrder("get"))
+ }
+
+ @Test
fun `executing command without parameters will not fetch anything`() {
command.execute(state, emptyList(), StringWriter())
verify(core, never()).fetch(any(), any())
assertThat(newState, equalTo(state))
}
+ @Test
+ fun `executing command with single non-numeric parameter will not fetch anything`() {
+ command.execute(state, listOf("a"), StringWriter())
+ verify(core, never()).fetch(any(), any())
+ }
+
+ @Test
+ fun `executing command with single non-numeric parameter will return old state`() {
+ val newState = command.execute(state, listOf("a"), StringWriter())
+ assertThat(newState, equalTo(state))
+ }
+
+ @Test
+ fun `executing command with single numeric parameter but no last results will not fetch anything`() {
+ command.execute(state, listOf("0"), StringWriter())
+ verify(core, never()).fetch(any(), any())
+ }
+
+ @Test
+ fun `executing command with single numeric parameter but no last results will return old state`() {
+ val newState = command.execute(state, listOf("0"), StringWriter())
+ assertThat(newState, equalTo(state))
+ }
+
+ @Test
+ fun `executing command with single numeric parameter and last results will fetch correct pack from correct bot`() {
+ val bot = mock(Bot::class.java)
+ val pack = Pack("1", "2", "3")
+ val state = state.setLastResults(listOf(Result(core, bot, pack)))
+ command.execute(state, listOf("0"), StringWriter())
+ verify(core).fetch(bot, pack)
+ }
+
+ @Test
+ fun `executing command with single numeric parameter and last results will return old state`() {
+ val bot = mock(Bot::class.java)
+ val pack = Pack("1", "2", "3")
+ val state = state.setLastResults(listOf(Result(core, bot, pack)))
+ val newState = command.execute(state, listOf("1"), StringWriter())
+ assertThat(newState, equalTo(state))
+ }
+
}