From dc255f5f3ac0071e491827f931d518e1d6616359 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 31 May 2020 15:05:27 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Add=20multiple=20downloads=20at=20th?= =?utf8?q?e=20same=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/xdcc/ui/stdin/DownloadCommand.kt | 9 +++---- .../xdcc/ui/stdin/DownloadCommandTest.kt | 28 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.kt b/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.kt index 7915472..8636e06 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.kt +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommand.kt @@ -34,10 +34,11 @@ class DownloadCommand(private val core: Core) : Command { if (parameters.isEmpty()) { return state } - val index = Ints.tryParse(parameters[0]) - if (index != null && index < state.lastResults.size) { - core.fetch(state.lastResults[index].bot(), state.lastResults[index].pack()) - } + parameters + .mapNotNull { Ints.tryParse(it) } + .filter { it < state.lastResults.size } + .map { state.lastResults[it] } + .forEach { core.fetch(it.bot(), it.pack()) } return state } 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 c02d5f9..cc4469d 100644 --- a/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt +++ b/src/test/java/net/pterodactylus/xdcc/ui/stdin/DownloadCommandTest.kt @@ -84,4 +84,32 @@ class DownloadCommandTest { assertThat(newState, equalTo(state)) } + @Test + fun `executing command with multiple mixed parameters and last results will fetch correct packs from correct bots`() { + val bot1 = mock(Bot::class.java) + val bot2 = mock(Bot::class.java) + val bot3 = mock(Bot::class.java) + val pack1 = Pack("1", "2", "3") + val pack2 = Pack("1", "2", "3") + val pack3 = Pack("1", "2", "3") + val state = state.setLastResults(listOf(Result(core, bot1, pack1), Result(core, bot2, pack2), Result(core, bot3, pack3))) + command.execute(state, listOf("0", "a", "7", "3", "1", "2"), StringWriter()) + verify(core).fetch(bot1, pack1) + verify(core).fetch(bot2, pack2) + verify(core).fetch(bot3, pack3) + } + + @Test + fun `executing command with multiple mixed parameters and last results will return old state`() { + val bot1 = mock(Bot::class.java) + val bot2 = mock(Bot::class.java) + val bot3 = mock(Bot::class.java) + val pack1 = Pack("1", "2", "3") + val pack2 = Pack("1", "2", "3") + val pack3 = Pack("1", "2", "3") + val state = state.setLastResults(listOf(Result(core, bot1, pack1), Result(core, bot2, pack2), Result(core, bot3, pack3))) + val newState = command.execute(state, listOf("0", "a", "7", "3", "1", "2"), StringWriter()) + assertThat(newState, equalTo(state)) + } + } -- 2.7.4