From: David ‘Bombe’ Roden Date: Sun, 31 May 2020 13:05:27 +0000 (+0200) Subject: ✨ Add multiple downloads at the same time X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dc255f5f3ac0071e491827f931d518e1d6616359;p=xudocci.git ✨ Add multiple downloads at the same time --- 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)) + } + }