From: David ‘Bombe’ Roden Date: Sun, 31 May 2020 12:55:49 +0000 (+0200) Subject: ✅ Add more tests for current behaviour X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=69d9f0cd50fe26dd878be3d21facd3199c72f445;p=xudocci.git ✅ Add more tests for current behaviour --- diff --git a/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt b/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt index 2d3aa0a..c02d5f9 100644 --- a/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt +++ b/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt @@ -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)) + } + }