From 8f3dfaa25a9ae48ed5bc836684d8dce7a4bf452b 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:40:54 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20first=20test=20for=20download?= =?utf8?q?=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../xdcc/ui/stdin/DownloadCommand.java | 3 +++ .../xdcc/ui/stdin/DownloadCommandTest.kt | 31 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.java index 2fdec0d..75e92ca 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.java @@ -65,6 +65,9 @@ public class DownloadCommand implements Command { @Override public State execute(State state, List parameters, Writer outputWriter) throws IOException { + if (parameters.isEmpty()) { + return state; + } Integer index = Ints.tryParse(parameters.get(0)); if ((index != null) && (index < state.getLastResults().size())) { core.fetch(state.getLastResults().get(index).bot(), state.getLastResults().get(index).pack()); diff --git a/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt b/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt new file mode 100644 index 0000000..2d3aa0a --- /dev/null +++ b/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt @@ -0,0 +1,31 @@ +package net.pterodactylus.xdcc.ui.stdin + +import net.pterodactylus.xdcc.core.Core +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.mockito.Matchers.any +import org.mockito.Mockito +import org.mockito.Mockito.never +import org.mockito.Mockito.verify +import java.io.StringWriter +import kotlin.test.Test + +class DownloadCommandTest { + + private val core = Mockito.mock(Core::class.java) + private val command = DownloadCommand(core) + private val state = State() + + @Test + fun `executing command without parameters will not fetch anything`() { + command.execute(state, emptyList(), StringWriter()) + verify(core, never()).fetch(any(), any()) + } + + @Test + fun `executing command without parameters will return old state`() { + val newState = command.execute(state, emptyList(), StringWriter()) + assertThat(newState, equalTo(state)) + } + +} -- 2.7.4