From 69d9f0cd50fe26dd878be3d21facd3199c72f445 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 31 May 2020 14:55:49 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20more=20tests=20for=20current?= =?utf8?q?=20behaviour?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../xdcc/ui/stdin/DownloadCommandTest.kt | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) 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)) + } + } -- 2.7.4