You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DslTest.kt 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.dmdirc.ktirc
  2. import org.junit.jupiter.api.Assertions.assertEquals
  3. import org.junit.jupiter.api.Assertions.assertTrue
  4. import org.junit.jupiter.api.Test
  5. import org.junit.jupiter.api.assertThrows
  6. internal class IrcClientConfigBuilderTest {
  7. @Test
  8. fun `throws if server is defined twice`() {
  9. assertThrows<IllegalStateException> {
  10. IrcClientConfigBuilder().apply {
  11. server { host = "1" }
  12. server { host = "2" }
  13. }
  14. }
  15. }
  16. @Test
  17. fun `throws if no host is provided`() {
  18. assertThrows<IllegalStateException> {
  19. IrcClientConfigBuilder().apply {
  20. server {}
  21. }
  22. }
  23. }
  24. @Test
  25. fun `throws if profile is defined twice`() {
  26. assertThrows<IllegalStateException> {
  27. IrcClientConfigBuilder().apply {
  28. profile { nickname = "acidBurn" }
  29. profile { nickname = "zeroCool" }
  30. }
  31. }
  32. }
  33. @Test
  34. fun `throws if no nickname is provided`() {
  35. assertThrows<IllegalStateException> {
  36. IrcClientConfigBuilder().apply {
  37. profile {}
  38. }
  39. }
  40. }
  41. @Test
  42. fun `throws if sasl is defined twice`() {
  43. assertThrows<IllegalStateException> {
  44. IrcClientConfigBuilder().apply {
  45. sasl {}
  46. sasl {}
  47. }
  48. }
  49. }
  50. @Test
  51. fun `throws if server is not defined`() {
  52. assertThrows<IllegalStateException> {
  53. IrcClientConfigBuilder().apply {
  54. profile { nickname = "acidBurn" }
  55. }.build()
  56. }
  57. }
  58. @Test
  59. fun `throws if profile is not defined`() {
  60. assertThrows<IllegalStateException> {
  61. IrcClientConfigBuilder().apply {
  62. server { host = "thegibson.com" }
  63. }.build()
  64. }
  65. }
  66. @Test
  67. fun `applies server settings`() {
  68. val config = IrcClientConfigBuilder().apply {
  69. profile { nickname = "acidBurn" }
  70. server {
  71. host = "thegibson.com"
  72. port = 1337
  73. password = "h4cktheplan3t"
  74. useTls = true
  75. }
  76. }.build()
  77. assertEquals("thegibson.com", config.server.host)
  78. assertEquals(1337, config.server.port)
  79. assertEquals("h4cktheplan3t", config.server.password)
  80. assertTrue(config.server.useTls)
  81. }
  82. @Test
  83. fun `applies profile settings`() {
  84. val config = IrcClientConfigBuilder().apply {
  85. profile {
  86. nickname = "acidBurn"
  87. username = "acidB"
  88. realName = "Kate"
  89. }
  90. server { host = "thegibson.com" }
  91. }.build()
  92. assertEquals("acidBurn", config.profile.nickname)
  93. assertEquals("acidB", config.profile.username)
  94. assertEquals("Kate", config.profile.realName)
  95. }
  96. @Test
  97. fun `applies sasl settings`() {
  98. val config = IrcClientConfigBuilder().apply {
  99. profile { nickname = "acidBurn" }
  100. server { host = "thegibson.com" }
  101. sasl {
  102. username = "acidBurn"
  103. password = "h4ckthepl@net"
  104. }
  105. }.build()
  106. assertEquals("acidBurn", config.sasl?.username)
  107. assertEquals("h4ckthepl@net", config.sasl?.password)
  108. }
  109. }
  110. internal class SaslConfigTest {
  111. @Test
  112. fun `mechanisms function clears all existing mechanisms`() {
  113. val config = SaslConfig().apply {
  114. mechanisms += "TEST"
  115. mechanisms("FOO", "BAR")
  116. }
  117. assertEquals(setOf("FOO", "BAR"), config.mechanisms)
  118. }
  119. @Test
  120. fun `defaults to plain mechanism`() {
  121. val config = SaslConfig()
  122. assertEquals(setOf("PLAIN"), config.mechanisms)
  123. }
  124. }