Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

MessageHandlerTest.kt 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.dmdirc.ktirc.io
  2. import com.dmdirc.ktirc.messages.MessageProcessor
  3. import com.nhaarman.mockitokotlin2.doReturn
  4. import com.nhaarman.mockitokotlin2.inOrder
  5. import com.nhaarman.mockitokotlin2.mock
  6. import com.nhaarman.mockitokotlin2.verify
  7. import kotlinx.coroutines.channels.Channel
  8. import kotlinx.coroutines.runBlocking
  9. import org.junit.jupiter.api.Test
  10. internal class MessageHandlerTest {
  11. private val nickProcessor = mock<MessageProcessor> {
  12. on { commands } doReturn arrayOf("FOO", "NICK")
  13. }
  14. private val joinProcessor = mock<MessageProcessor> {
  15. on { commands } doReturn arrayOf("BAR", "JOIN")
  16. }
  17. @Test
  18. fun `MessageHandler passes message on to correct processor`() = runBlocking {
  19. val handler = MessageHandler(listOf(joinProcessor, nickProcessor))
  20. val message = IrcMessage(null, null, "JOIN", emptyList())
  21. with(Channel<IrcMessage>(1)) {
  22. send(message)
  23. close()
  24. handler.processMessages(this)
  25. }
  26. verify(joinProcessor).process(message)
  27. }
  28. @Test
  29. fun `MessageHandler reads multiple messages`() = runBlocking {
  30. val handler = MessageHandler(listOf(joinProcessor, nickProcessor))
  31. val joinMessage = IrcMessage(null, null, "JOIN", emptyList())
  32. val nickMessage = IrcMessage(null, null, "NICK", emptyList())
  33. val otherMessage = IrcMessage(null, null, "OTHER", emptyList())
  34. with(Channel<IrcMessage>(3)) {
  35. send(joinMessage)
  36. send(nickMessage)
  37. send(otherMessage)
  38. close()
  39. handler.processMessages(this)
  40. }
  41. with(inOrder(joinProcessor, nickProcessor)) {
  42. verify(joinProcessor).process(joinMessage)
  43. verify(nickProcessor).process(nickMessage)
  44. }
  45. }
  46. }