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
}
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))
+ }
+
}