✅ Add more tests for current behaviour
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 31 May 2020 12:55:49 +0000 (14:55 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 31 May 2020 14:45:13 +0000 (16:45 +0200)
src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt

index 2d3aa0a..c02d5f9 100644 (file)
@@ -1,10 +1,14 @@
 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
@@ -17,6 +21,16 @@ class DownloadCommandTest {
        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())
@@ -28,4 +42,46 @@ class DownloadCommandTest {
                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))
+       }
+
 }