123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package com.dmdirc.ktirc
-
- import org.junit.jupiter.api.Assertions.*
- import org.junit.jupiter.api.Test
- import org.junit.jupiter.api.assertThrows
-
- internal class IrcClientConfigBuilderTest {
-
- @Test
- fun `throws if server is defined twice`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- server { host = "1" }
- server { host = "2" }
- }
- }
- }
-
- @Test
- fun `throws if no host is provided`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- server {}
- }
- }
- }
-
- @Test
- fun `throws if empty host is provided`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- server("")
- }
- }
- }
-
- @Test
- fun `throws if profile is defined twice`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- profile { nickname = "zeroCool" }
- }
- }
- }
-
- @Test
- fun `throws if no nickname is provided`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- profile {}
- }
- }
- }
-
- @Test
- fun `throws if empty nickname is provided`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- profile("")
- }
- }
- }
-
- @Test
- fun `throws if behaviour is defined twice`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- behaviour {}
- behaviour {}
- }
- }
- }
-
- @Test
- fun `throws if sasl is defined twice`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- sasl {}
- sasl {}
- }
- }
- }
-
- @Test
- fun `throws if server is not defined`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- }.build()
- }
- }
-
- @Test
- fun `throws if profile is not defined`() {
- assertThrows<IllegalStateException> {
- IrcClientConfigBuilder().apply {
- server { host = "thegibson.com" }
- }.build()
- }
- }
-
- @Test
- fun `applies server settings`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server {
- host = "thegibson.com"
- port = 1337
- password = "h4cktheplan3t"
- useTls = true
- }
- }.build()
-
- assertEquals("thegibson.com", config.server.host)
- assertEquals(1337, config.server.port)
- assertEquals("h4cktheplan3t", config.server.password)
- assertTrue(config.server.useTls)
- }
-
- @Test
- fun `applies server settings with convenience function`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server("thegibson.com", 1337, true, "h4cktheplan3t")
- }.build()
-
- assertEquals("thegibson.com", config.server.host)
- assertEquals(1337, config.server.port)
- assertEquals("h4cktheplan3t", config.server.password)
- assertTrue(config.server.useTls)
- }
-
- @Test
- fun `applies server settings with convenience function and block`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server("thegibson.com", 1337) {
- password = "h4cktheplan3t"
- useTls = true
- }
- }.build()
-
- assertEquals("thegibson.com", config.server.host)
- assertEquals(1337, config.server.port)
- assertEquals("h4cktheplan3t", config.server.password)
- assertTrue(config.server.useTls)
- }
-
- @Test
- fun `applies profile settings`() {
- val config = IrcClientConfigBuilder().apply {
- profile {
- nickname = "acidBurn"
- username = "acidB"
- realName = "Kate"
- }
- server { host = "thegibson.com" }
- }.build()
-
- assertEquals("acidBurn", config.profile.nickname)
- assertEquals("acidB", config.profile.username)
- assertEquals("Kate", config.profile.realName)
- }
-
- @Test
- fun `applies profile settings with convenience function`() {
- val config = IrcClientConfigBuilder().apply {
- profile("acidBurn", "acidB", "Kate")
- server { host = "thegibson.com" }
- }.build()
-
- assertEquals("acidBurn", config.profile.nickname)
- assertEquals("acidB", config.profile.username)
- assertEquals("Kate", config.profile.realName)
- }
-
- @Test
- fun `applies profile settings with convenience function and block`() {
- val config = IrcClientConfigBuilder().apply {
- profile("acidBurn", "acidB") {
- realName = "Kate"
- }
- server { host = "thegibson.com" }
- }.build()
-
- assertEquals("acidBurn", config.profile.nickname)
- assertEquals("acidB", config.profile.username)
- assertEquals("Kate", config.profile.realName)
- }
-
- @Test
- fun `applies behaviour settings`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server { host = "thegibson.com" }
- behaviour {
- requestModesOnJoin = true
- }
- }.build()
-
- assertTrue(config.behaviour.requestModesOnJoin)
- }
-
- @Test
- fun `falls back to default behaviour settings`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server { host = "thegibson.com" }
- }.build()
-
- assertFalse(config.behaviour.requestModesOnJoin)
- }
-
- @Test
- fun `applies sasl settings`() {
- val config = IrcClientConfigBuilder().apply {
- profile { nickname = "acidBurn" }
- server { host = "thegibson.com" }
- sasl {
- username = "acidBurn"
- password = "h4ckthepl@net"
- }
- }.build()
-
- assertEquals("acidBurn", config.sasl?.username)
- assertEquals("h4ckthepl@net", config.sasl?.password)
- }
-
- }
-
- internal class SaslConfigTest {
-
- @Test
- fun `mechanisms function clears all existing mechanisms`() {
- val config = SaslConfig().apply {
- mechanisms += "TEST"
- mechanisms("FOO", "BAR")
- }
-
- assertEquals(setOf("FOO", "BAR"), config.mechanisms)
- }
-
- @Test
- fun `defaults to plain and scram mechanisms`() {
- val config = SaslConfig()
- assertEquals(setOf("PLAIN", "SCRAM-SHA-1", "SCRAM-SHA-256"), config.mechanisms)
- }
-
- }
|