您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AwayProcessorTest.kt 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.dmdirc.ktirc.messages.processors
  2. import com.dmdirc.ktirc.TestConstants
  3. import com.dmdirc.ktirc.model.IrcMessage
  4. import com.dmdirc.ktirc.model.User
  5. import com.dmdirc.ktirc.params
  6. import com.dmdirc.ktirc.util.currentTimeProvider
  7. import org.junit.jupiter.api.Assertions
  8. import org.junit.jupiter.api.Assertions.assertEquals
  9. import org.junit.jupiter.api.Assertions.assertNull
  10. import org.junit.jupiter.api.BeforeEach
  11. import org.junit.jupiter.api.Test
  12. internal class AwayProcessorTest {
  13. @BeforeEach
  14. fun setUp() {
  15. currentTimeProvider = { TestConstants.time }
  16. }
  17. @Test
  18. fun `raises away changed event with reason`() {
  19. val events = AwayProcessor().process(
  20. IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "AWAY", params("Hacking the planet")))
  21. assertEquals(1, events.size)
  22. val event = events[0]
  23. assertEquals(TestConstants.time, event.metadata.time)
  24. assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
  25. assertEquals("Hacking the planet", event.message)
  26. }
  27. @Test
  28. fun `raises away changed event with no reason`() {
  29. val events = AwayProcessor().process(
  30. IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "AWAY", emptyList()))
  31. assertEquals(1, events.size)
  32. val event = events[0]
  33. assertEquals(TestConstants.time, event.metadata.time)
  34. assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
  35. assertNull(event.message)
  36. }
  37. @Test
  38. fun `raises away changed event for local user on NOWAWAY`() {
  39. val events = AwayProcessor().process(
  40. IrcMessage(emptyMap(), ":the.server".toByteArray(), "306", params("acidBurn", "You have been marked as being away")))
  41. assertEquals(1, events.size)
  42. val event = events[0]
  43. assertEquals(TestConstants.time, event.metadata.time)
  44. assertEquals(User("acidBurn"), event.user)
  45. assertEquals("", event.message)
  46. }
  47. @Test
  48. fun `raises away changed event for local user on UNAWAY`() {
  49. val events = AwayProcessor().process(
  50. IrcMessage(emptyMap(), ":the.server".toByteArray(), "305", params("acidBurn", "You are no longer marked as being away")))
  51. assertEquals(1, events.size)
  52. val event = events[0]
  53. assertEquals(TestConstants.time, event.metadata.time)
  54. assertEquals(User("acidBurn"), event.user)
  55. assertNull(event.message)
  56. }
  57. @Test
  58. fun `does nothing on away if prefix missing`() {
  59. val events = AwayProcessor().process(IrcMessage(emptyMap(), null, "AWAY", params("*")))
  60. Assertions.assertEquals(0, events.size)
  61. }
  62. }