Browse Source

Convert event tests to use mockk

tags/v0.10.0
Chris Smith 5 years ago
parent
commit
a1aad4dbc7

+ 35
- 19
src/test/kotlin/com/dmdirc/ktirc/events/EventUtilsTest.kt View File

5
 import com.dmdirc.ktirc.io.CaseMapping
5
 import com.dmdirc.ktirc.io.CaseMapping
6
 import com.dmdirc.ktirc.messages.tagMap
6
 import com.dmdirc.ktirc.messages.tagMap
7
 import com.dmdirc.ktirc.model.*
7
 import com.dmdirc.ktirc.model.*
8
-import com.nhaarman.mockitokotlin2.doReturn
9
-import com.nhaarman.mockitokotlin2.mock
10
-import com.nhaarman.mockitokotlin2.verify
8
+import io.mockk.every
9
+import io.mockk.mockk
10
+import io.mockk.verify
11
 import org.junit.jupiter.api.Assertions.assertEquals
11
 import org.junit.jupiter.api.Assertions.assertEquals
12
 import org.junit.jupiter.api.BeforeEach
12
 import org.junit.jupiter.api.BeforeEach
13
 import org.junit.jupiter.api.Test
13
 import org.junit.jupiter.api.Test
14
 
14
 
15
 internal class EventUtilsTest {
15
 internal class EventUtilsTest {
16
 
16
 
17
-    private val serverState = ServerState("", "")
18
-    private val ircClient = mock<IrcClient> {
19
-        on { serverState } doReturn serverState
20
-        on { caseMapping } doReturn CaseMapping.Ascii
17
+    private val fakeServerState = ServerState("", "")
18
+    private val ircClient = mockk<IrcClient> {
19
+        every { serverState } returns fakeServerState
20
+        every { caseMapping } returns CaseMapping.Ascii
21
     }
21
     }
22
 
22
 
23
     @BeforeEach
23
     @BeforeEach
24
     fun setUp() {
24
     fun setUp() {
25
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
25
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
26
     }
26
     }
27
 
27
 
28
     @Test
28
     @Test
66
 
66
 
67
     @Test
67
     @Test
68
     fun `reply sends response to user when message is private`() {
68
     fun `reply sends response to user when message is private`() {
69
-        serverState.localNickname = "zeroCool"
69
+        fakeServerState.localNickname = "zeroCool"
70
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "Zerocool", "Hack the planet!")
70
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "Zerocool", "Hack the planet!")
71
 
71
 
72
         ircClient.reply(message, "OK")
72
         ircClient.reply(message, "OK")
73
-        verify(ircClient).send(tagMap(), "PRIVMSG", "acidBurn", "OK")
73
+        verify {
74
+            ircClient.send(tagMap(), "PRIVMSG", "acidBurn", "OK")
75
+        }
74
     }
76
     }
75
 
77
 
76
     @Test
78
     @Test
78
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
80
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
79
 
81
 
80
         ircClient.reply(message, "OK")
82
         ircClient.reply(message, "OK")
81
-        verify(ircClient).send(tagMap(), "PRIVMSG", "#TheGibson", "OK")
83
+        verify {
84
+            ircClient.send(tagMap(), "PRIVMSG", "#TheGibson", "OK")
85
+        }
82
     }
86
     }
83
 
87
 
84
     @Test
88
     @Test
86
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
90
         val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
87
 
91
 
88
         ircClient.reply(message, "OK", prefixWithNickname = true)
92
         ircClient.reply(message, "OK", prefixWithNickname = true)
89
-        verify(ircClient).send(tagMap(), "PRIVMSG", "#TheGibson", "acidBurn: OK")
93
+        verify {
94
+            ircClient.send(tagMap(), "PRIVMSG", "#TheGibson", "acidBurn: OK")
95
+        }
90
     }
96
     }
91
 
97
 
92
     @Test
98
     @Test
93
     fun `reply sends response with message ID to user when message is private`() {
99
     fun `reply sends response with message ID to user when message is private`() {
94
-        serverState.localNickname = "zeroCool"
100
+        fakeServerState.localNickname = "zeroCool"
95
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "Zerocool", "Hack the planet!")
101
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "Zerocool", "Hack the planet!")
96
 
102
 
97
         ircClient.reply(message, "OK")
103
         ircClient.reply(message, "OK")
98
-        verify(ircClient).send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "acidBurn", "OK")
104
+        verify {
105
+            ircClient.send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "acidBurn", "OK")
106
+        }
99
     }
107
     }
100
 
108
 
101
     @Test
109
     @Test
103
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "#TheGibson", "Hack the planet!")
111
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "#TheGibson", "Hack the planet!")
104
 
112
 
105
         ircClient.reply(message, "OK")
113
         ircClient.reply(message, "OK")
106
-        verify(ircClient).send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "#TheGibson", "OK")
114
+        verify {
115
+            ircClient.send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "#TheGibson", "OK")
116
+        }
107
     }
117
     }
108
 
118
 
109
     @Test
119
     @Test
111
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "#TheGibson", "Hack the planet!")
121
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "abc123"), User("acidBurn"), "#TheGibson", "Hack the planet!")
112
 
122
 
113
         ircClient.reply(message, "OK", prefixWithNickname = true)
123
         ircClient.reply(message, "OK", prefixWithNickname = true)
114
-        verify(ircClient).send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "#TheGibson", "acidBurn: OK")
124
+        verify {
125
+            ircClient.send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "#TheGibson", "acidBurn: OK")
126
+        }
115
     }
127
     }
116
 
128
 
117
 
129
 
118
     @Test
130
     @Test
119
     fun `react sends response to user when message is private`() {
131
     fun `react sends response to user when message is private`() {
120
-        serverState.localNickname = "zeroCool"
132
+        fakeServerState.localNickname = "zeroCool"
121
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "msgId"), User("acidBurn"), "Zerocool", "Hack the planet!")
133
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "msgId"), User("acidBurn"), "Zerocool", "Hack the planet!")
122
 
134
 
123
         ircClient.react(message, ":P")
135
         ircClient.react(message, ":P")
124
-        verify(ircClient).send(tagMap(MessageTag.React to ":P", MessageTag.Reply to "msgId"), "TAGMSG", "acidBurn")
136
+        verify {
137
+            ircClient.send(tagMap(MessageTag.React to ":P", MessageTag.Reply to "msgId"), "TAGMSG", "acidBurn")
138
+        }
125
     }
139
     }
126
 
140
 
127
     @Test
141
     @Test
129
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "msgId"), User("acidBurn"), "#TheGibson", "Hack the planet!")
143
         val message = MessageReceived(EventMetadata(TestConstants.time, messageId = "msgId"), User("acidBurn"), "#TheGibson", "Hack the planet!")
130
 
144
 
131
         ircClient.react(message, ":P")
145
         ircClient.react(message, ":P")
132
-        verify(ircClient).send(tagMap(MessageTag.React to ":P", MessageTag.Reply to "msgId"), "TAGMSG", "#TheGibson")
146
+        verify {
147
+            ircClient.send(tagMap(MessageTag.React to ":P", MessageTag.Reply to "msgId"), "TAGMSG", "#TheGibson")
148
+        }
133
     }
149
     }
134
 
150
 
135
 }
151
 }

+ 107
- 79
src/test/kotlin/com/dmdirc/ktirc/events/handlers/CapabilitiesHandlerTest.kt View File

9
 import com.dmdirc.ktirc.sasl.SaslMechanism
9
 import com.dmdirc.ktirc.sasl.SaslMechanism
10
 import com.dmdirc.ktirc.sasl.fromBase64
10
 import com.dmdirc.ktirc.sasl.fromBase64
11
 import com.dmdirc.ktirc.sasl.toBase64
11
 import com.dmdirc.ktirc.sasl.toBase64
12
-import com.nhaarman.mockitokotlin2.*
12
+import io.mockk.*
13
 import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.Assertions.*
14
 import org.junit.jupiter.api.Test
14
 import org.junit.jupiter.api.Test
15
 
15
 
16
 internal class CapabilitiesHandlerTest {
16
 internal class CapabilitiesHandlerTest {
17
 
17
 
18
-    private val saslMech1 = mock<SaslMechanism> {
19
-        on { priority } doReturn 1
20
-        on { ircName } doReturn "mech1"
18
+    private val saslMech1 = mockk<SaslMechanism> {
19
+        every { priority } returns 1
20
+        every { ircName } returns "mech1"
21
     }
21
     }
22
 
22
 
23
-    private val saslMech2 = mock<SaslMechanism> {
24
-        on { priority } doReturn 2
25
-        on { ircName } doReturn "mech2"
23
+    private val saslMech2 = mockk<SaslMechanism> {
24
+        every { priority } returns 2
25
+        every { ircName } returns "mech2"
26
     }
26
     }
27
 
27
 
28
-    private val saslMech3 = mock<SaslMechanism> {
29
-        on { priority } doReturn 3
30
-        on { ircName } doReturn "mech3"
28
+    private val saslMech3 = mockk<SaslMechanism> {
29
+        every { priority } returns 3
30
+        every { ircName } returns "mech3"
31
     }
31
     }
32
 
32
 
33
     private val handler = CapabilitiesHandler()
33
     private val handler = CapabilitiesHandler()
34
-    private val serverState = ServerState("", "", null)
35
-    private val ircClient = mock<IrcClient> {
36
-        on { serverState } doReturn serverState
34
+    private val fakeServerState = ServerState("", "", null)
35
+    private val ircClient = mockk<IrcClient> {
36
+        every { serverState } returns fakeServerState
37
     }
37
     }
38
 
38
 
39
     @Test
39
     @Test
43
                 Capability.HostsInNamesReply.names[0] to "123"
43
                 Capability.HostsInNamesReply.names[0] to "123"
44
         )))
44
         )))
45
 
45
 
46
-        assertEquals(2, serverState.capabilities.advertisedCapabilities.size)
47
-        assertEquals("", serverState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]])
48
-        assertEquals("123", serverState.capabilities.advertisedCapabilities[Capability.HostsInNamesReply.names[0]])
46
+        assertEquals(2, fakeServerState.capabilities.advertisedCapabilities.size)
47
+        assertEquals("", fakeServerState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]])
48
+        assertEquals("123", fakeServerState.capabilities.advertisedCapabilities[Capability.HostsInNamesReply.names[0]])
49
     }
49
     }
50
 
50
 
51
     @Test
51
     @Test
52
     fun `updates negotiation state when capabilities finished`() {
52
     fun `updates negotiation state when capabilities finished`() {
53
-        serverState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]] = ""
53
+        fakeServerState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]] = ""
54
 
54
 
55
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
55
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
56
 
56
 
57
-        assertEquals(CapabilitiesNegotiationState.AWAITING_ACK, serverState.capabilities.negotiationState)
57
+        assertEquals(CapabilitiesNegotiationState.AWAITING_ACK, fakeServerState.capabilities.negotiationState)
58
     }
58
     }
59
 
59
 
60
     @Test
60
     @Test
61
     fun `sends REQ when capabilities received`() {
61
     fun `sends REQ when capabilities received`() {
62
-        serverState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]] = ""
63
-        serverState.capabilities.advertisedCapabilities[Capability.AccountChangeMessages.names[0]] = ""
62
+        fakeServerState.capabilities.advertisedCapabilities[Capability.EchoMessages.names[0]] = ""
63
+        fakeServerState.capabilities.advertisedCapabilities[Capability.AccountChangeMessages.names[0]] = ""
64
 
64
 
65
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
65
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
66
 
66
 
67
-        verify(ircClient).send(eq("CAP"), eq("REQ"), argThat { equals("echo-message account-notify") || equals("account-notify echo-message") })
67
+        verify {
68
+            ircClient.send(eq("CAP"), eq("REQ"), or(eq("echo-message account-notify"), eq("account-notify echo-message")))
69
+        }
68
     }
70
     }
69
 
71
 
70
     @Test
72
     @Test
71
     fun `sends END when blank capabilities received`() {
73
     fun `sends END when blank capabilities received`() {
72
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
74
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
73
 
75
 
74
-        verify(ircClient).send("CAP", "END")
76
+        verify {
77
+            ircClient.send("CAP", "END")
78
+        }
75
     }
79
     }
76
 
80
 
77
     @Test
81
     @Test
78
     fun `updates negotiation when blank capabilities received`() {
82
     fun `updates negotiation when blank capabilities received`() {
79
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
83
         handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
80
 
84
 
81
-        assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
85
+        assertEquals(CapabilitiesNegotiationState.FINISHED, fakeServerState.capabilities.negotiationState)
82
     }
86
     }
83
 
87
 
84
     @Test
88
     @Test
88
                 Capability.HostsInNamesReply.names[0] to ""
92
                 Capability.HostsInNamesReply.names[0] to ""
89
         )))
93
         )))
90
 
94
 
91
-        verify(ircClient).send("CAP", "END")
95
+        verify {
96
+            ircClient.send("CAP", "END")
97
+        }
92
     }
98
     }
93
 
99
 
94
     @Test
100
     @Test
95
     fun `sends END when capabilities acknowledged and no sasl state`() {
101
     fun `sends END when capabilities acknowledged and no sasl state`() {
96
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
102
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
97
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
103
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
98
                 Capability.EchoMessages.names[0] to "",
104
                 Capability.EchoMessages.names[0] to "",
99
                 Capability.HostsInNamesReply.names[0] to ""
105
                 Capability.HostsInNamesReply.names[0] to ""
100
         )))
106
         )))
101
 
107
 
102
-        verify(ircClient).send("CAP", "END")
108
+        verify {
109
+            ircClient.send("CAP", "END")
110
+        }
103
     }
111
     }
104
 
112
 
105
     @Test
113
     @Test
106
     fun `sends END when capabilities acknowledged and no shared mechanism`() {
114
     fun `sends END when capabilities acknowledged and no shared mechanism`() {
107
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
108
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "fake1,fake2"
115
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
116
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "fake1,fake2"
109
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
117
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
110
                 Capability.SaslAuthentication.names[0] to "",
118
                 Capability.SaslAuthentication.names[0] to "",
111
                 Capability.HostsInNamesReply.names[0] to ""
119
                 Capability.HostsInNamesReply.names[0] to ""
112
         )))
120
         )))
113
 
121
 
114
-        verify(ircClient).send("CAP", "END")
122
+        verify {
123
+            ircClient.send("CAP", "END")
124
+        }
115
     }
125
     }
116
 
126
 
117
     @Test
127
     @Test
118
     fun `sets current SASL mechanism when capabilities acknowledged with shared mechanism`() {
128
     fun `sets current SASL mechanism when capabilities acknowledged with shared mechanism`() {
119
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
120
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
129
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
130
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
121
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
131
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
122
                 Capability.SaslAuthentication.names[0] to "",
132
                 Capability.SaslAuthentication.names[0] to "",
123
                 Capability.HostsInNamesReply.names[0] to ""
133
                 Capability.HostsInNamesReply.names[0] to ""
124
         )))
134
         )))
125
 
135
 
126
-        assertSame(saslMech1, serverState.sasl.currentMechanism)
136
+        assertSame(saslMech1, fakeServerState.sasl.currentMechanism)
127
     }
137
     }
128
 
138
 
129
     @Test
139
     @Test
130
     fun `sets current SASL mechanism when capabilities acknowledged with no declared mechanisms`() {
140
     fun `sets current SASL mechanism when capabilities acknowledged with no declared mechanisms`() {
131
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
132
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = ""
141
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
142
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = ""
133
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
143
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
134
                 Capability.SaslAuthentication.names[0] to "",
144
                 Capability.SaslAuthentication.names[0] to "",
135
                 Capability.HostsInNamesReply.names[0] to ""
145
                 Capability.HostsInNamesReply.names[0] to ""
136
         )))
146
         )))
137
 
147
 
138
-        assertSame(saslMech3, serverState.sasl.currentMechanism)
148
+        assertSame(saslMech3, fakeServerState.sasl.currentMechanism)
139
     }
149
     }
140
 
150
 
141
     @Test
151
     @Test
142
     fun `sends authenticate when capabilities acknowledged with shared mechanism`() {
152
     fun `sends authenticate when capabilities acknowledged with shared mechanism`() {
143
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
144
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
153
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
154
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
145
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
155
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
146
                 Capability.SaslAuthentication.names[0] to "",
156
                 Capability.SaslAuthentication.names[0] to "",
147
                 Capability.HostsInNamesReply.names[0] to ""
157
                 Capability.HostsInNamesReply.names[0] to ""
148
         )))
158
         )))
149
 
159
 
150
-        verify(ircClient).send("AUTHENTICATE", "mech1")
160
+        verify {
161
+            ircClient.send("AUTHENTICATE", "mech1")
162
+        }
151
     }
163
     }
152
 
164
 
153
     @Test
165
     @Test
154
     fun `sends authenticate when capabilities acknowledged with no declared mechanisms`() {
166
     fun `sends authenticate when capabilities acknowledged with no declared mechanisms`() {
155
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
156
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = ""
167
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
168
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = ""
157
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
169
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
158
                 Capability.SaslAuthentication.names[0] to "",
170
                 Capability.SaslAuthentication.names[0] to "",
159
                 Capability.HostsInNamesReply.names[0] to ""
171
                 Capability.HostsInNamesReply.names[0] to ""
160
         )))
172
         )))
161
 
173
 
162
-        verify(ircClient).send("AUTHENTICATE", "mech3")
174
+        verify {
175
+            ircClient.send("AUTHENTICATE", "mech3")
176
+        }
163
     }
177
     }
164
 
178
 
165
     @Test
179
     @Test
166
     fun `updates negotiation state when capabilities acknowledged with shared mechanism`() {
180
     fun `updates negotiation state when capabilities acknowledged with shared mechanism`() {
167
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
168
-        serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
181
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
182
+        fakeServerState.capabilities.advertisedCapabilities[Capability.SaslAuthentication.names[0]] = "mech1,fake2"
169
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
183
         handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
170
                 Capability.SaslAuthentication.names[0] to "",
184
                 Capability.SaslAuthentication.names[0] to "",
171
                 Capability.HostsInNamesReply.names[0] to ""
185
                 Capability.HostsInNamesReply.names[0] to ""
172
         )))
186
         )))
173
 
187
 
174
-        assertEquals(CapabilitiesNegotiationState.AUTHENTICATING, serverState.capabilities.negotiationState)
188
+        assertEquals(CapabilitiesNegotiationState.AUTHENTICATING, fakeServerState.capabilities.negotiationState)
175
     }
189
     }
176
 
190
 
177
     @Test
191
     @Test
181
                 Capability.HostsInNamesReply.names[0] to "123"
195
                 Capability.HostsInNamesReply.names[0] to "123"
182
         )))
196
         )))
183
 
197
 
184
-        assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
198
+        assertEquals(CapabilitiesNegotiationState.FINISHED, fakeServerState.capabilities.negotiationState)
185
     }
199
     }
186
 
200
 
187
     @Test
201
     @Test
191
                 Capability.HostsInNamesReply.names[0] to "123"
205
                 Capability.HostsInNamesReply.names[0] to "123"
192
         )))
206
         )))
193
 
207
 
194
-        assertEquals(2, serverState.capabilities.enabledCapabilities.size)
195
-        assertEquals("", serverState.capabilities.enabledCapabilities[Capability.EchoMessages])
196
-        assertEquals("123", serverState.capabilities.enabledCapabilities[Capability.HostsInNamesReply])
208
+        assertEquals(2, fakeServerState.capabilities.enabledCapabilities.size)
209
+        assertEquals("", fakeServerState.capabilities.enabledCapabilities[Capability.EchoMessages])
210
+        assertEquals("123", fakeServerState.capabilities.enabledCapabilities[Capability.HostsInNamesReply])
197
     }
211
     }
198
 
212
 
199
     @Test
213
     @Test
200
     fun `aborts authentication attempt if not expecting one`() {
214
     fun `aborts authentication attempt if not expecting one`() {
201
-        serverState.sasl.currentMechanism = null
215
+        fakeServerState.sasl.currentMechanism = null
202
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "+"))
216
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "+"))
203
 
217
 
204
-        verify(ircClient).send("AUTHENTICATE", "*")
218
+        verify {
219
+            ircClient.send("AUTHENTICATE", "*")
220
+        }
205
     }
221
     }
206
 
222
 
207
     @Test
223
     @Test
208
     fun `passes authentication message to mechanism if in auth process`() {
224
     fun `passes authentication message to mechanism if in auth process`() {
209
-        serverState.sasl.currentMechanism = saslMech1
225
+        fakeServerState.sasl.currentMechanism = saslMech1
210
 
226
 
211
         val argument = "ABC"
227
         val argument = "ABC"
212
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
228
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
213
 
229
 
214
-        verify(saslMech1).handleAuthenticationEvent(ircClient, argument.fromBase64())
230
+        verify {
231
+            saslMech1.handleAuthenticationEvent(ircClient, argument.fromBase64())
232
+        }
215
     }
233
     }
216
 
234
 
217
     @Test
235
     @Test
218
     fun `stores partial authentication message if it's 400 bytes long`() {
236
     fun `stores partial authentication message if it's 400 bytes long`() {
219
-        serverState.sasl.currentMechanism = saslMech1
237
+        fakeServerState.sasl.currentMechanism = saslMech1
220
 
238
 
221
         val argument = "A".repeat(400)
239
         val argument = "A".repeat(400)
222
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
240
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
223
 
241
 
224
-        assertEquals(argument, serverState.sasl.saslBuffer)
225
-        verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
242
+        assertEquals(argument, fakeServerState.sasl.saslBuffer)
243
+        verify(inverse = true) {
244
+            saslMech1.handleAuthenticationEvent(any(), any())
245
+        }
226
     }
246
     }
227
 
247
 
228
     @Test
248
     @Test
229
     fun `appends authentication messages if it's 400 bytes long and data already exists`() {
249
     fun `appends authentication messages if it's 400 bytes long and data already exists`() {
230
-        serverState.sasl.currentMechanism = saslMech1
250
+        fakeServerState.sasl.currentMechanism = saslMech1
231
 
251
 
232
-        serverState.sasl.saslBuffer = "A".repeat(400)
252
+        fakeServerState.sasl.saslBuffer = "A".repeat(400)
233
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "B".repeat(400)))
253
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "B".repeat(400)))
234
 
254
 
235
-        assertEquals("A".repeat(400) + "B".repeat(400), serverState.sasl.saslBuffer)
236
-        verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
255
+        assertEquals("A".repeat(400) + "B".repeat(400), fakeServerState.sasl.saslBuffer)
256
+        verify(inverse = true) {
257
+            saslMech1.handleAuthenticationEvent(any(), any())
258
+        }
237
     }
259
     }
238
 
260
 
239
     @Test
261
     @Test
240
     fun `reconstructs partial authentication message to mechanism if data stored and partial received`() {
262
     fun `reconstructs partial authentication message to mechanism if data stored and partial received`() {
241
-        serverState.sasl.currentMechanism = saslMech1
263
+        fakeServerState.sasl.currentMechanism = saslMech1
264
+        fakeServerState.sasl.saslBuffer = "A".repeat(400)
242
 
265
 
243
-        serverState.sasl.saslBuffer = "A".repeat(400)
266
+        val slot = slot<ByteArray>()
267
+        every { saslMech1.handleAuthenticationEvent(eq(ircClient), capture(slot)) } just Runs
244
 
268
 
245
         val argument = "ABCD"
269
         val argument = "ABCD"
246
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
270
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
247
 
271
 
248
-        val captor = argumentCaptor<ByteArray>()
249
-        verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
250
-        assertEquals("A".repeat(400) + "ABCD", captor.firstValue.toBase64())
272
+        assertEquals("A".repeat(400) + "ABCD", slot.captured.toBase64())
251
     }
273
     }
252
 
274
 
253
     @Test
275
     @Test
254
     fun `reconstructs partial authentication message to mechanism if data stored and null received`() {
276
     fun `reconstructs partial authentication message to mechanism if data stored and null received`() {
255
-        serverState.sasl.currentMechanism = saslMech1
277
+        fakeServerState.sasl.currentMechanism = saslMech1
278
+        fakeServerState.sasl.saslBuffer = "A".repeat(400)
256
 
279
 
257
-        serverState.sasl.saslBuffer = "A".repeat(400)
280
+        val slot = slot<ByteArray>()
281
+        every { saslMech1.handleAuthenticationEvent(eq(ircClient), capture(slot)) } just Runs
258
 
282
 
259
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), null))
283
         handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), null))
260
 
284
 
261
-        val captor = argumentCaptor<ByteArray>()
262
-        verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
263
-        assertEquals("A".repeat(400), captor.firstValue.toBase64())
285
+        assertEquals("A".repeat(400), slot.captured.toBase64())
264
     }
286
     }
265
 
287
 
266
     @Test
288
     @Test
267
     fun `sends END when SASL auth finished`() {
289
     fun `sends END when SASL auth finished`() {
268
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
290
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
269
 
291
 
270
-        verify(ircClient).send("CAP", "END")
292
+        verify {
293
+            ircClient.send("CAP", "END")
294
+        }
271
     }
295
     }
272
 
296
 
273
     @Test
297
     @Test
274
     fun `sets negotiation state when SASL auth finished`() {
298
     fun `sets negotiation state when SASL auth finished`() {
275
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
299
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
276
 
300
 
277
-        assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
301
+        assertEquals(CapabilitiesNegotiationState.FINISHED, fakeServerState.capabilities.negotiationState)
278
     }
302
     }
279
 
303
 
280
     @Test
304
     @Test
281
     fun `resets SASL state when SASL auth finished`() {
305
     fun `resets SASL state when SASL auth finished`() {
282
-        with (serverState.sasl) {
306
+        with (fakeServerState.sasl) {
283
             currentMechanism = saslMech1
307
             currentMechanism = saslMech1
284
             saslBuffer = "HackThePlanet"
308
             saslBuffer = "HackThePlanet"
285
             mechanismState = "root@thegibson"
309
             mechanismState = "root@thegibson"
287
 
311
 
288
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
312
         handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
289
 
313
 
290
-        with (serverState.sasl) {
314
+        with (fakeServerState.sasl) {
291
             assertNull(currentMechanism)
315
             assertNull(currentMechanism)
292
             assertEquals("", saslBuffer)
316
             assertEquals("", saslBuffer)
293
             assertNull(mechanismState)
317
             assertNull(mechanismState)
296
 
320
 
297
     @Test
321
     @Test
298
     fun `sends a new authenticate request when sasl mechanism rejected and new one is acceptable`() {
322
     fun `sends a new authenticate request when sasl mechanism rejected and new one is acceptable`() {
299
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
323
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
300
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("mech1", "fake2")))
324
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("mech1", "fake2")))
301
 
325
 
302
-        verify(ircClient).send("AUTHENTICATE", "mech1")
326
+        verify {
327
+            ircClient.send("AUTHENTICATE", "mech1")
328
+        }
303
     }
329
     }
304
 
330
 
305
     @Test
331
     @Test
306
     fun `sends cap end when sasl mechanism rejected and no new one is acceptable`() {
332
     fun `sends cap end when sasl mechanism rejected and no new one is acceptable`() {
307
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
333
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
308
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
334
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
309
 
335
 
310
-        verify(ircClient).send("CAP", "END")
336
+        verify {
337
+            ircClient.send("CAP", "END")
338
+        }
311
     }
339
     }
312
 
340
 
313
     @Test
341
     @Test
314
     fun `sets negotiation state when sasl mechanism rejected and no new one is acceptable`() {
342
     fun `sets negotiation state when sasl mechanism rejected and no new one is acceptable`() {
315
-        serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
343
+        fakeServerState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
316
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
344
         handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
317
 
345
 
318
-        assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
346
+        assertEquals(CapabilitiesNegotiationState.FINISHED, fakeServerState.capabilities.negotiationState)
319
     }
347
     }
320
 
348
 
321
 }
349
 }

+ 84
- 79
src/test/kotlin/com/dmdirc/ktirc/events/handlers/ChannelStateHandlerTest.kt View File

6
 import com.dmdirc.ktirc.events.*
6
 import com.dmdirc.ktirc.events.*
7
 import com.dmdirc.ktirc.io.CaseMapping
7
 import com.dmdirc.ktirc.io.CaseMapping
8
 import com.dmdirc.ktirc.model.*
8
 import com.dmdirc.ktirc.model.*
9
-import com.nhaarman.mockitokotlin2.doReturn
10
-import com.nhaarman.mockitokotlin2.mock
11
-import com.nhaarman.mockitokotlin2.never
12
-import com.nhaarman.mockitokotlin2.verify
9
+import io.mockk.every
10
+import io.mockk.mockk
11
+import io.mockk.verify
13
 import org.junit.jupiter.api.Assertions.*
12
 import org.junit.jupiter.api.Assertions.*
14
 import org.junit.jupiter.api.Test
13
 import org.junit.jupiter.api.Test
15
 
14
 
16
 internal class ChannelStateHandlerTest {
15
 internal class ChannelStateHandlerTest {
17
 
16
 
18
     private val handler = ChannelStateHandler()
17
     private val handler = ChannelStateHandler()
19
-    private val channelStateMap = ChannelStateMap { CaseMapping.Rfc }
20
-    private val serverState = ServerState("", "")
21
-    private val behaviour = BehaviourConfig()
22
-    private val ircClient = mock<IrcClient> {
23
-        on { serverState } doReturn serverState
24
-        on { channelState } doReturn channelStateMap
25
-        on { behaviour } doReturn behaviour
26
-        on { isLocalUser(User("acidburn", "libby", "root.localhost")) } doReturn true
27
-        on { isLocalUser("acidburn") } doReturn  true
18
+    private val fakeChannelState = ChannelStateMap { CaseMapping.Rfc }
19
+    private val fakeServerState = ServerState("", "")
20
+    private val behaviourConfig = BehaviourConfig()
21
+    private val ircClient = mockk<IrcClient> {
22
+        every { serverState } returns fakeServerState
23
+        every { channelState } returns fakeChannelState
24
+        every { behaviour } returns behaviourConfig
25
+        every { isLocalUser(any<User>()) } answers { arg<User>(0) == User("acidburn", "libby", "root.localhost") }
26
+        every { isLocalUser(any<String>()) } answers { arg<String>(0) == "acidburn" }
28
     }
27
     }
29
 
28
 
30
     @Test
29
     @Test
31
     fun `creates new state object for local joins`() {
30
     fun `creates new state object for local joins`() {
32
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
31
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
33
-        assertTrue("#thegibson" in channelStateMap)
32
+        assertTrue("#thegibson" in fakeChannelState)
34
     }
33
     }
35
 
34
 
36
     @Test
35
     @Test
37
     fun `does not create new state object for remote joins`() {
36
     fun `does not create new state object for remote joins`() {
38
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
37
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
39
-        assertFalse("#thegibson" in channelStateMap)
38
+        assertFalse("#thegibson" in fakeChannelState)
40
     }
39
     }
41
 
40
 
42
     @Test
41
     @Test
43
     fun `adds joiners to channel state`() {
42
     fun `adds joiners to channel state`() {
44
-        channelStateMap += ChannelState("#thegibson") { CaseMapping.Rfc }
43
+        fakeChannelState += ChannelState("#thegibson") { CaseMapping.Rfc }
45
 
44
 
46
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
45
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
47
 
46
 
48
-        assertTrue("zerocool" in channelStateMap["#thegibson"]?.users!!)
47
+        assertTrue("zerocool" in fakeChannelState["#thegibson"]?.users!!)
49
     }
48
     }
50
 
49
 
51
     @Test
50
     @Test
53
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
52
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
54
         channel.users += ChannelUser("acidBurn")
53
         channel.users += ChannelUser("acidBurn")
55
         channel.users += ChannelUser("thePlague")
54
         channel.users += ChannelUser("thePlague")
56
-        channelStateMap += channel
55
+        fakeChannelState += channel
57
 
56
 
58
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
57
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
59
 
58
 
64
     @Test
63
     @Test
65
     fun `adds users from multiple name received events`() {
64
     fun `adds users from multiple name received events`() {
66
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
65
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
67
-        channelStateMap += channel
66
+        fakeChannelState += channel
68
 
67
 
69
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
68
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
70
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("acidBurn")))
69
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("acidBurn")))
79
     @Test
78
     @Test
80
     fun `clears and readds users on additional names received`() {
79
     fun `clears and readds users on additional names received`() {
81
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
80
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
82
-        channelStateMap += channel
81
+        fakeChannelState += channel
83
 
82
 
84
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
83
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
85
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
84
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
94
     @Test
93
     @Test
95
     fun `adds users with mode prefixes`() {
94
     fun `adds users with mode prefixes`() {
96
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
95
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
97
-        channelStateMap += channel
98
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
96
+        fakeChannelState += channel
97
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
99
 
98
 
100
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool", "@+acidBurn", "+thePlague", "cerealKiller")))
99
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool", "@+acidBurn", "+thePlague", "cerealKiller")))
101
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
100
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
110
     @Test
109
     @Test
111
     fun `adds users with full hosts`() {
110
     fun `adds users with full hosts`() {
112
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
111
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
113
-        channelStateMap += channel
114
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
112
+        fakeChannelState += channel
113
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
115
 
114
 
116
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
115
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
117
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
116
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
124
     @Test
123
     @Test
125
     fun `updates receiving user list state`() {
124
     fun `updates receiving user list state`() {
126
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
125
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
127
-        channelStateMap += channel
128
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
126
+        fakeChannelState += channel
127
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
129
 
128
 
130
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
129
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
131
 
130
 
139
     @Test
138
     @Test
140
     fun `requests modes on end of names if configured and undiscovered`() {
139
     fun `requests modes on end of names if configured and undiscovered`() {
141
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
140
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
142
-        channelStateMap += channel
143
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
144
-        behaviour.requestModesOnJoin = true
141
+        fakeChannelState += channel
142
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
143
+        behaviourConfig.requestModesOnJoin = true
145
 
144
 
146
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
145
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
147
 
146
 
148
-        verify(ircClient).send("MODE", "#thegibson")
147
+        verify {
148
+            ircClient.send("MODE", "#thegibson")
149
+        }
149
     }
150
     }
150
 
151
 
151
     @Test
152
     @Test
152
     fun `does not request modes on end of names if already discovered`() {
153
     fun `does not request modes on end of names if already discovered`() {
153
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
154
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
154
-        channelStateMap += channel
155
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
156
-        behaviour.requestModesOnJoin = true
155
+        fakeChannelState += channel
156
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
157
+        behaviourConfig.requestModesOnJoin = true
157
         channel.modesDiscovered = true
158
         channel.modesDiscovered = true
158
 
159
 
159
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
160
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
160
 
161
 
161
-        verify(ircClient, never()).send("MODE", "#thegibson")
162
+        verify(inverse = true) {
163
+            ircClient.send("MODE", "#thegibson")
164
+        }
162
     }
165
     }
163
 
166
 
164
     @Test
167
     @Test
165
     fun `does not request modes on end of names if not configured`() {
168
     fun `does not request modes on end of names if not configured`() {
166
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
169
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
167
-        channelStateMap += channel
168
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
169
-        behaviour.requestModesOnJoin = false
170
+        fakeChannelState += channel
171
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
172
+        behaviourConfig.requestModesOnJoin = false
170
 
173
 
171
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
174
         handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
172
 
175
 
173
-        verify(ircClient, never()).send("MODE", "#thegibson")
176
+        verify(inverse = true) {
177
+            ircClient.send("MODE", "#thegibson")
178
+        }
174
     }
179
     }
175
 
180
 
176
     @Test
181
     @Test
177
     fun `removes state object for local parts`() {
182
     fun `removes state object for local parts`() {
178
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
183
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
179
-        channelStateMap += channel
184
+        fakeChannelState += channel
180
 
185
 
181
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
186
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
182
 
187
 
183
-        assertFalse("#thegibson" in channelStateMap)
188
+        assertFalse("#thegibson" in fakeChannelState)
184
     }
189
     }
185
 
190
 
186
     @Test
191
     @Test
187
     fun `removes user from channel member list for remote parts`() {
192
     fun `removes user from channel member list for remote parts`() {
188
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
193
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
189
         channel.users += ChannelUser("ZeroCool")
194
         channel.users += ChannelUser("ZeroCool")
190
-        channelStateMap += channel
195
+        fakeChannelState += channel
191
 
196
 
192
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
197
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
193
 
198
 
197
     @Test
202
     @Test
198
     fun `removes state object for local kicks`() {
203
     fun `removes state object for local kicks`() {
199
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
204
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
200
-        channelStateMap += channel
205
+        fakeChannelState += channel
201
 
206
 
202
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson", "acidburn", "Bye!"))
207
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson", "acidburn", "Bye!"))
203
 
208
 
204
-        assertFalse("#thegibson" in channelStateMap)
209
+        assertFalse("#thegibson" in fakeChannelState)
205
     }
210
     }
206
 
211
 
207
     @Test
212
     @Test
208
     fun `removes user from channel member list for remote kicks`() {
213
     fun `removes user from channel member list for remote kicks`() {
209
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
214
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
210
         channel.users += ChannelUser("ZeroCool")
215
         channel.users += ChannelUser("ZeroCool")
211
-        channelStateMap += channel
216
+        fakeChannelState += channel
212
 
217
 
213
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "zerocool", "Bye!"))
218
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "zerocool", "Bye!"))
214
 
219
 
219
     fun `removes user from channel member lists for quits`() {
224
     fun `removes user from channel member lists for quits`() {
220
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
225
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
221
             users += ChannelUser("ZeroCool")
226
             users += ChannelUser("ZeroCool")
222
-            channelStateMap += this
227
+            fakeChannelState += this
223
         }
228
         }
224
 
229
 
225
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
230
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
226
             users += ChannelUser("ZeroCool")
231
             users += ChannelUser("ZeroCool")
227
-            channelStateMap += this
232
+            fakeChannelState += this
228
         }
233
         }
229
 
234
 
230
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
235
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
231
             users += ChannelUser("AcidBurn")
236
             users += ChannelUser("AcidBurn")
232
-            channelStateMap += this
237
+            fakeChannelState += this
233
         }
238
         }
234
 
239
 
235
         handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
240
         handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
236
         handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#dumpsterdiving"))
241
         handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#dumpsterdiving"))
237
 
242
 
238
-        assertFalse("zerocool" in channelStateMap["#thegibson"]!!.users)
239
-        assertFalse("zerocool" in channelStateMap["#dumpsterdiving"]!!.users)
240
-        assertFalse("zerocool" in channelStateMap["#chat"]!!.users)
241
-        assertTrue("acidburn" in channelStateMap["#chat"]!!.users)
243
+        assertFalse("zerocool" in fakeChannelState["#thegibson"]!!.users)
244
+        assertFalse("zerocool" in fakeChannelState["#dumpsterdiving"]!!.users)
245
+        assertFalse("zerocool" in fakeChannelState["#chat"]!!.users)
246
+        assertTrue("acidburn" in fakeChannelState["#chat"]!!.users)
242
     }
247
     }
243
 
248
 
244
     @Test
249
     @Test
245
     fun `renames user in channel member list for nick changes`() {
250
     fun `renames user in channel member list for nick changes`() {
246
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
251
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
247
         channel.users += ChannelUser("acidBurn")
252
         channel.users += ChannelUser("acidBurn")
248
-        channelStateMap += channel
253
+        fakeChannelState += channel
249
 
254
 
250
         handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "acidB"))
255
         handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "acidB"))
251
         handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#dumpsterdiving", "acidB"))
256
         handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#dumpsterdiving", "acidB"))
258
     @Test
263
     @Test
259
     fun `sets mode discovered flag when discovered mode event received`() {
264
     fun `sets mode discovered flag when discovered mode event received`() {
260
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
265
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
261
-        channelStateMap += channel
262
-        serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
266
+        fakeChannelState += channel
267
+        fakeServerState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
263
 
268
 
264
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+", emptyArray(), true))
269
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+", emptyArray(), true))
265
 
270
 
269
     @Test
274
     @Test
270
     fun `adds modes when discovered mode event received`() {
275
     fun `adds modes when discovered mode event received`() {
271
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
276
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
272
-        channelStateMap += channel
273
-        serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
277
+        fakeChannelState += channel
278
+        fakeServerState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
274
 
279
 
275
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+ceg", arrayOf("CCC", "EEE"), true))
280
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+ceg", arrayOf("CCC", "EEE"), true))
276
 
281
 
285
         channel.modes['c'] = "CCC"
290
         channel.modes['c'] = "CCC"
286
         channel.modes['e'] = "EEE"
291
         channel.modes['e'] = "EEE"
287
         channel.modes['h'] = ""
292
         channel.modes['h'] = ""
288
-        channelStateMap += channel
289
-        serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
293
+        fakeChannelState += channel
294
+        fakeServerState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
290
 
295
 
291
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-c+d-eh+fg", arrayOf("CCC", "DDD", "FFF"), true))
296
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-c+d-eh+fg", arrayOf("CCC", "DDD", "FFF"), true))
292
 
297
 
302
     fun `handles unprivileged user gaining new mode`() {
307
     fun `handles unprivileged user gaining new mode`() {
303
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
308
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
304
             users += ChannelUser("ZeroCool")
309
             users += ChannelUser("ZeroCool")
305
-            channelStateMap += this
310
+            fakeChannelState += this
306
         }
311
         }
307
 
312
 
308
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
313
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
309
 
314
 
310
-        assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
315
+        assertEquals("o", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
311
     }
316
     }
312
 
317
 
313
     @Test
318
     @Test
314
     fun `handles privileged user gaining lesser mode`() {
319
     fun `handles privileged user gaining lesser mode`() {
315
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
320
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
316
             users += ChannelUser("ZeroCool", "o")
321
             users += ChannelUser("ZeroCool", "o")
317
-            channelStateMap += this
322
+            fakeChannelState += this
318
         }
323
         }
319
 
324
 
320
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+v", arrayOf("zeroCool")))
325
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+v", arrayOf("zeroCool")))
321
 
326
 
322
-        assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
327
+        assertEquals("ov", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
323
     }
328
     }
324
 
329
 
325
     @Test
330
     @Test
326
     fun `handles privileged user gaining greater mode`() {
331
     fun `handles privileged user gaining greater mode`() {
327
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
332
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
328
             users += ChannelUser("ZeroCool", "v")
333
             users += ChannelUser("ZeroCool", "v")
329
-            channelStateMap += this
334
+            fakeChannelState += this
330
         }
335
         }
331
 
336
 
332
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
337
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
333
 
338
 
334
-        assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
339
+        assertEquals("ov", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
335
     }
340
     }
336
 
341
 
337
     @Test
342
     @Test
338
     fun `handles user gaining multiple modes`() {
343
     fun `handles user gaining multiple modes`() {
339
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
344
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
340
             users += ChannelUser("ZeroCool")
345
             users += ChannelUser("ZeroCool")
341
-            channelStateMap += this
346
+            fakeChannelState += this
342
         }
347
         }
343
 
348
 
344
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+vo", arrayOf("zeroCool", "zeroCool")))
349
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+vo", arrayOf("zeroCool", "zeroCool")))
345
 
350
 
346
-        assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
351
+        assertEquals("ov", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
347
     }
352
     }
348
 
353
 
349
     @Test
354
     @Test
350
     fun `handles user losing multiple modes`() {
355
     fun `handles user losing multiple modes`() {
351
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
356
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
352
             users += ChannelUser("ZeroCool", "ov")
357
             users += ChannelUser("ZeroCool", "ov")
353
-            channelStateMap += this
358
+            fakeChannelState += this
354
         }
359
         }
355
 
360
 
356
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-vo", arrayOf("zeroCool", "zeroCool")))
361
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-vo", arrayOf("zeroCool", "zeroCool")))
357
 
362
 
358
-        assertEquals("", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
363
+        assertEquals("", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
359
     }
364
     }
360
 
365
 
361
     @Test
366
     @Test
362
     fun `handles mixture of user modes and normal modes`() {
367
     fun `handles mixture of user modes and normal modes`() {
363
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
368
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
364
             users += ChannelUser("ZeroCool", "v")
369
             users += ChannelUser("ZeroCool", "v")
365
-            channelStateMap += this
370
+            fakeChannelState += this
366
         }
371
         }
367
-        serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
372
+        fakeServerState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
368
 
373
 
369
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "oa-v+b", arrayOf("zeroCool", "aaa", "zeroCool", "bbb")))
374
         handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "oa-v+b", arrayOf("zeroCool", "aaa", "zeroCool", "bbb")))
370
 
375
 
371
-        assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
372
-        assertEquals("aaa", channelStateMap["#thegibson"]?.modes?.get('a'))
373
-        assertEquals("bbb", channelStateMap["#thegibson"]?.modes?.get('b'))
376
+        assertEquals("o", fakeChannelState["#thegibson"]?.users?.get("zeroCool")?.modes)
377
+        assertEquals("aaa", fakeChannelState["#thegibson"]?.modes?.get('a'))
378
+        assertEquals("bbb", fakeChannelState["#thegibson"]?.modes?.get('b'))
374
     }
379
     }
375
 
380
 
376
     @Test
381
     @Test
377
     fun `updates topic state when it's discovered for the first time`() {
382
     fun `updates topic state when it's discovered for the first time`() {
378
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
383
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
379
-        channelStateMap += state
384
+        fakeChannelState += state
380
 
385
 
381
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet!"))
386
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet!"))
382
         handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("acidBurn"), TestConstants.otherTime))
387
         handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("acidBurn"), TestConstants.otherTime))
388
     @Test
393
     @Test
389
     fun `updates topic state when no topic is discovered for the first time`() {
394
     fun `updates topic state when no topic is discovered for the first time`() {
390
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
395
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
391
-        channelStateMap += state
396
+        fakeChannelState += state
392
 
397
 
393
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", null))
398
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", null))
394
 
399
 
401
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
406
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
402
         state.topic = ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime)
407
         state.topic = ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime)
403
         state.topicDiscovered = true
408
         state.topicDiscovered = true
404
-        channelStateMap += state
409
+        fakeChannelState += state
405
 
410
 
406
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet"))
411
         handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet"))
407
         handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("zeroCool"), TestConstants.time))
412
         handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("zeroCool"), TestConstants.time))
413
     @Test
418
     @Test
414
     fun `updates topic state when the topic is changed`() {
419
     fun `updates topic state when the topic is changed`() {
415
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
420
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
416
-        channelStateMap += state
421
+        fakeChannelState += state
417
 
422
 
418
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", "Hack the planet!"))
423
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", "Hack the planet!"))
419
 
424
 
423
     @Test
428
     @Test
424
     fun `updates topic state when the topic is unset`() {
429
     fun `updates topic state when the topic is unset`() {
425
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
430
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
426
-        channelStateMap += state
431
+        fakeChannelState += state
427
 
432
 
428
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", null))
433
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", null))
429
 
434
 
433
     @Test
438
     @Test
434
     fun `ignores topic change when channel doesn't exist`() {
439
     fun `ignores topic change when channel doesn't exist`() {
435
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
440
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
436
-        channelStateMap += state
441
+        fakeChannelState += state
437
 
442
 
438
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#dumpsterdiving", "Hack the planet!"))
443
         handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#dumpsterdiving", "Hack the planet!"))
439
 
444
 

+ 7
- 6
src/test/kotlin/com/dmdirc/ktirc/events/handlers/PingHandlerTest.kt View File

4
 import com.dmdirc.ktirc.TestConstants
4
 import com.dmdirc.ktirc.TestConstants
5
 import com.dmdirc.ktirc.events.EventMetadata
5
 import com.dmdirc.ktirc.events.EventMetadata
6
 import com.dmdirc.ktirc.events.PingReceived
6
 import com.dmdirc.ktirc.events.PingReceived
7
-import com.nhaarman.mockitokotlin2.mock
8
-import com.nhaarman.mockitokotlin2.verify
9
-import kotlinx.coroutines.runBlocking
7
+import io.mockk.mockk
8
+import io.mockk.verify
10
 import org.junit.jupiter.api.Test
9
 import org.junit.jupiter.api.Test
11
 
10
 
12
 internal class PingHandlerTest {
11
 internal class PingHandlerTest {
13
 
12
 
14
-    private val ircClient = mock<IrcClient>()
13
+    private val ircClient = mockk<IrcClient>()
15
 
14
 
16
     private val handler = PingHandler()
15
     private val handler = PingHandler()
17
 
16
 
18
     @Test
17
     @Test
19
-    fun `PingHandler responses to pings with a pong`() = runBlocking {
18
+    fun `responses to pings with a pong`() {
20
         handler.processEvent(ircClient, PingReceived(EventMetadata(TestConstants.time), "the_plague".toByteArray()))
19
         handler.processEvent(ircClient, PingReceived(EventMetadata(TestConstants.time), "the_plague".toByteArray()))
21
-        verify(ircClient).send("PONG", "the_plague")
20
+        verify {
21
+            ircClient.send("PONG", "the_plague")
22
+        }
22
     }
23
     }
23
 
24
 
24
 }
25
 }

+ 15
- 15
src/test/kotlin/com/dmdirc/ktirc/events/handlers/ServerStateHandlerTest.kt View File

7
 import com.dmdirc.ktirc.model.ServerFeatureMap
7
 import com.dmdirc.ktirc.model.ServerFeatureMap
8
 import com.dmdirc.ktirc.model.ServerState
8
 import com.dmdirc.ktirc.model.ServerState
9
 import com.dmdirc.ktirc.model.ServerStatus
9
 import com.dmdirc.ktirc.model.ServerStatus
10
-import com.nhaarman.mockitokotlin2.doReturn
11
-import com.nhaarman.mockitokotlin2.mock
10
+import io.mockk.every
11
+import io.mockk.mockk
12
 import org.junit.jupiter.api.Assertions.*
12
 import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.Test
13
 import org.junit.jupiter.api.Test
14
 
14
 
15
 internal class ServerStateHandlerTest {
15
 internal class ServerStateHandlerTest {
16
 
16
 
17
-    private val serverState = ServerState("", "")
18
-    private val ircClient = mock<IrcClient> {
19
-        on { serverState } doReturn serverState
17
+    private val fakeServerState = ServerState("", "")
18
+    private val ircClient = mockk<IrcClient> {
19
+        every { serverState } returns fakeServerState
20
     }
20
     }
21
 
21
 
22
     private val handler = ServerStateHandler()
22
     private val handler = ServerStateHandler()
24
     @Test
24
     @Test
25
     fun `sets local nickname on welcome event`() {
25
     fun `sets local nickname on welcome event`() {
26
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
26
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
27
-        assertEquals("acidBurn", serverState.localNickname)
27
+        assertEquals("acidBurn", fakeServerState.localNickname)
28
     }
28
     }
29
 
29
 
30
     @Test
30
     @Test
31
     fun `sets server name on welcome event`() {
31
     fun `sets server name on welcome event`() {
32
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
32
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
33
-        assertEquals("the.gibson", serverState.serverName)
33
+        assertEquals("the.gibson", fakeServerState.serverName)
34
     }
34
     }
35
 
35
 
36
     @Test
36
     @Test
37
     fun `sets receivedWelcome on welcome event`() {
37
     fun `sets receivedWelcome on welcome event`() {
38
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
38
         handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
39
-        assertTrue(serverState.receivedWelcome)
39
+        assertTrue(fakeServerState.receivedWelcome)
40
     }
40
     }
41
 
41
 
42
     @Test
42
     @Test
43
     fun `sets state to connecting on event`() {
43
     fun `sets state to connecting on event`() {
44
         handler.processEvent(ircClient, ServerConnecting(EventMetadata(TestConstants.time)))
44
         handler.processEvent(ircClient, ServerConnecting(EventMetadata(TestConstants.time)))
45
-        assertEquals(ServerStatus.Connecting, serverState.status)
45
+        assertEquals(ServerStatus.Connecting, fakeServerState.status)
46
     }
46
     }
47
 
47
 
48
     @Test
48
     @Test
49
     fun `sets state to disconnected on event`() {
49
     fun `sets state to disconnected on event`() {
50
-        serverState.status = ServerStatus.Ready
50
+        fakeServerState.status = ServerStatus.Ready
51
         handler.processEvent(ircClient, ServerDisconnected(EventMetadata(TestConstants.time)))
51
         handler.processEvent(ircClient, ServerDisconnected(EventMetadata(TestConstants.time)))
52
-        assertEquals(ServerStatus.Disconnected, serverState.status)
52
+        assertEquals(ServerStatus.Disconnected, fakeServerState.status)
53
     }
53
     }
54
 
54
 
55
     @Test
55
     @Test
56
     fun `sets state to negotiating on connected`() {
56
     fun `sets state to negotiating on connected`() {
57
         handler.processEvent(ircClient, ServerConnected(EventMetadata(TestConstants.time)))
57
         handler.processEvent(ircClient, ServerConnected(EventMetadata(TestConstants.time)))
58
-        assertEquals(ServerStatus.Negotiating, serverState.status)
58
+        assertEquals(ServerStatus.Negotiating, fakeServerState.status)
59
     }
59
     }
60
 
60
 
61
     @Test
61
     @Test
62
     fun `sets state to ready on ServerReady`() {
62
     fun `sets state to ready on ServerReady`() {
63
         handler.processEvent(ircClient, ServerReady(EventMetadata(TestConstants.time)))
63
         handler.processEvent(ircClient, ServerReady(EventMetadata(TestConstants.time)))
64
-        assertEquals(ServerStatus.Ready, serverState.status)
64
+        assertEquals(ServerStatus.Ready, fakeServerState.status)
65
     }
65
     }
66
 
66
 
67
     @Test
67
     @Test
72
 
72
 
73
         handler.processEvent(ircClient, ServerFeaturesUpdated(EventMetadata(TestConstants.time), features))
73
         handler.processEvent(ircClient, ServerFeaturesUpdated(EventMetadata(TestConstants.time), features))
74
 
74
 
75
-        assertArrayEquals(arrayOf("abc", "def"), serverState.features[ServerFeature.ChannelModes])
76
-        assertEquals(true, serverState.features[ServerFeature.WhoxSupport])
75
+        assertArrayEquals(arrayOf("abc", "def"), fakeServerState.features[ServerFeature.ChannelModes])
76
+        assertEquals(true, fakeServerState.features[ServerFeature.WhoxSupport])
77
     }
77
     }
78
 
78
 
79
 }
79
 }

+ 77
- 80
src/test/kotlin/com/dmdirc/ktirc/events/handlers/UserStateHandlerTest.kt View File

5
 import com.dmdirc.ktirc.events.*
5
 import com.dmdirc.ktirc.events.*
6
 import com.dmdirc.ktirc.io.CaseMapping
6
 import com.dmdirc.ktirc.io.CaseMapping
7
 import com.dmdirc.ktirc.model.*
7
 import com.dmdirc.ktirc.model.*
8
-import com.nhaarman.mockitokotlin2.argForWhich
9
-import com.nhaarman.mockitokotlin2.doReturn
10
-import com.nhaarman.mockitokotlin2.mock
11
-import com.nhaarman.mockitokotlin2.whenever
8
+import io.mockk.every
9
+import io.mockk.mockk
12
 import org.junit.jupiter.api.Assertions.*
10
 import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.BeforeEach
11
 import org.junit.jupiter.api.BeforeEach
14
 import org.junit.jupiter.api.Test
12
 import org.junit.jupiter.api.Test
15
 
13
 
16
 internal class UserStateHandlerTest {
14
 internal class UserStateHandlerTest {
17
 
15
 
18
-    private val serverState = ServerState("", "")
19
-    private val userState = UserState { CaseMapping.Rfc }
16
+    private val fakeServerState = ServerState("", "")
17
+    private val fakeUserState = UserState { CaseMapping.Rfc }
20
 
18
 
21
-    private val ircClient = mock<IrcClient> {
22
-        on { serverState } doReturn serverState
23
-        on { userState } doReturn userState
24
-        on { isLocalUser(argForWhich<User> { nickname == "zeroCool" }) } doReturn true
25
-        on { isLocalUser("zeroCool") } doReturn true
19
+    private val ircClient = mockk<IrcClient> {
20
+        every { serverState } returns fakeServerState
21
+        every { userState } returns fakeUserState
22
+        every { isLocalUser(any<User>()) } answers { arg<User>(0).nickname == "zeroCool" }
23
+        every { isLocalUser(any<String>()) } answers { arg<String>(0) == "zeroCool" }
26
     }
24
     }
27
 
25
 
28
     private val handler = UserStateHandler()
26
     private val handler = UserStateHandler()
29
 
27
 
30
     @BeforeEach
28
     @BeforeEach
31
     fun setUp() {
29
     fun setUp() {
32
-        serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
30
+        fakeServerState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
33
     }
31
     }
34
 
32
 
35
     @Test
33
     @Test
36
     fun `adds channel to user on join`() {
34
     fun `adds channel to user on join`() {
37
-        userState += User("acidBurn")
35
+        fakeUserState += User("acidBurn")
38
 
36
 
39
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
37
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
40
 
38
 
41
-        assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
39
+        assertEquals(listOf("#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
42
     }
40
     }
43
 
41
 
44
     @Test
42
     @Test
45
     fun `updates user info on join`() {
43
     fun `updates user info on join`() {
46
-        userState += User("acidBurn")
44
+        fakeUserState += User("acidBurn")
47
 
45
 
48
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
46
         handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
49
 
47
 
50
-        val details = userState["acidBurn"]?.details!!
48
+        val details = fakeUserState["acidBurn"]?.details!!
51
         assertEquals("libby", details.ident)
49
         assertEquals("libby", details.ident)
52
         assertEquals("root.localhost", details.hostname)
50
         assertEquals("root.localhost", details.hostname)
53
     }
51
     }
54
 
52
 
55
     @Test
53
     @Test
56
     fun `removes channel from user on part`() {
54
     fun `removes channel from user on part`() {
57
-        userState += User("acidBurn")
58
-        userState.addToChannel(User("acidBurn"), "#thegibson")
59
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
55
+        fakeUserState += User("acidBurn")
56
+        fakeUserState.addToChannel(User("acidBurn"), "#thegibson")
57
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
60
 
58
 
61
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
59
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
62
 
60
 
63
-        assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
61
+        assertEquals(listOf("#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
64
     }
62
     }
65
 
63
 
66
     @Test
64
     @Test
67
     fun `removes user on part from last channel`() {
65
     fun `removes user on part from last channel`() {
68
-        userState += User("acidBurn")
69
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
66
+        fakeUserState += User("acidBurn")
67
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
70
 
68
 
71
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
69
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
72
 
70
 
73
-        assertNull(userState["acidBurn"])
71
+        assertNull(fakeUserState["acidBurn"])
74
     }
72
     }
75
 
73
 
76
     @Test
74
     @Test
77
     fun `removes channel from all users on local part`() {
75
     fun `removes channel from all users on local part`() {
78
-        userState += User("acidBurn")
79
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
80
-        userState.addToChannel(User("acidBurn"), "#thegibson")
76
+        fakeUserState += User("acidBurn")
77
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
78
+        fakeUserState.addToChannel(User("acidBurn"), "#thegibson")
81
 
79
 
82
-        userState += User("zeroCool")
83
-        userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
84
-        userState.addToChannel(User("zeroCool"), "#thegibson")
80
+        fakeUserState += User("zeroCool")
81
+        fakeUserState.addToChannel(User("zeroCool"), "#dumpsterdiving")
82
+        fakeUserState.addToChannel(User("zeroCool"), "#thegibson")
85
 
83
 
86
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
84
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
87
 
85
 
88
-        assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
89
-        assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
86
+        assertEquals(listOf("#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
87
+        assertEquals(listOf("#thegibson"), fakeUserState["zeroCool"]?.channels?.toList())
90
     }
88
     }
91
 
89
 
92
     @Test
90
     @Test
93
     fun `removes remote users with no remaining channels on local part`() {
91
     fun `removes remote users with no remaining channels on local part`() {
94
-        userState += User("acidBurn")
95
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
92
+        fakeUserState += User("acidBurn")
93
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
96
 
94
 
97
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
95
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
98
 
96
 
99
-        assertNull(userState["acidBurn"])
97
+        assertNull(fakeUserState["acidBurn"])
100
     }
98
     }
101
 
99
 
102
     @Test
100
     @Test
103
     fun `keeps local user with no remaining channels after local part`() {
101
     fun `keeps local user with no remaining channels after local part`() {
104
-        userState += User("zeroCool")
105
-        userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
102
+        fakeUserState += User("zeroCool")
103
+        fakeUserState.addToChannel(User("zeroCool"), "#dumpsterdiving")
106
 
104
 
107
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
105
         handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
108
 
106
 
109
-        assertNotNull(userState["zeroCool"])
107
+        assertNotNull(fakeUserState["zeroCool"])
110
     }
108
     }
111
 
109
 
112
 
110
 
113
     @Test
111
     @Test
114
     fun `removes channel from user on kick`() {
112
     fun `removes channel from user on kick`() {
115
-        userState += User("acidBurn")
116
-        userState.addToChannel(User("acidBurn"), "#thegibson")
117
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
113
+        fakeUserState += User("acidBurn")
114
+        fakeUserState.addToChannel(User("acidBurn"), "#thegibson")
115
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
118
 
116
 
119
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
117
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
120
 
118
 
121
-        assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
119
+        assertEquals(listOf("#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
122
     }
120
     }
123
 
121
 
124
     @Test
122
     @Test
125
     fun `removes user on kick from last channel`() {
123
     fun `removes user on kick from last channel`() {
126
-        userState += User("acidBurn")
127
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
124
+        fakeUserState += User("acidBurn")
125
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
128
 
126
 
129
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
127
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
130
 
128
 
131
-        assertNull(userState["acidBurn"])
129
+        assertNull(fakeUserState["acidBurn"])
132
     }
130
     }
133
 
131
 
134
     @Test
132
     @Test
135
     fun `removes channel from all users on local kick`() {
133
     fun `removes channel from all users on local kick`() {
136
-        userState += User("acidBurn")
137
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
138
-        userState.addToChannel(User("acidBurn"), "#thegibson")
134
+        fakeUserState += User("acidBurn")
135
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
136
+        fakeUserState.addToChannel(User("acidBurn"), "#thegibson")
139
 
137
 
140
-        userState += User("zeroCool")
141
-        userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
142
-        userState.addToChannel(User("zeroCool"), "#thegibson")
138
+        fakeUserState += User("zeroCool")
139
+        fakeUserState.addToChannel(User("zeroCool"), "#dumpsterdiving")
140
+        fakeUserState.addToChannel(User("zeroCool"), "#thegibson")
143
 
141
 
144
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
142
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
145
 
143
 
146
-        assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
147
-        assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
144
+        assertEquals(listOf("#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
145
+        assertEquals(listOf("#thegibson"), fakeUserState["zeroCool"]?.channels?.toList())
148
     }
146
     }
149
 
147
 
150
     @Test
148
     @Test
151
     fun `removes remote users with no remaining channels on local kick`() {
149
     fun `removes remote users with no remaining channels on local kick`() {
152
-        userState += User("acidBurn")
153
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
150
+        fakeUserState += User("acidBurn")
151
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
154
 
152
 
155
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
153
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
156
 
154
 
157
-        assertNull(userState["acidBurn"])
155
+        assertNull(fakeUserState["acidBurn"])
158
     }
156
     }
159
 
157
 
160
     @Test
158
     @Test
161
     fun `keeps local user with no remaining channels after local kick`() {
159
     fun `keeps local user with no remaining channels after local kick`() {
162
-        userState += User("zeroCool")
163
-        userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
160
+        fakeUserState += User("zeroCool")
161
+        fakeUserState.addToChannel(User("zeroCool"), "#dumpsterdiving")
164
 
162
 
165
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
163
         handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
166
 
164
 
167
-        assertNotNull(userState["zeroCool"])
165
+        assertNotNull(fakeUserState["zeroCool"])
168
     }
166
     }
169
 
167
 
170
     @Test
168
     @Test
171
     fun `removes user entirely on quit`() {
169
     fun `removes user entirely on quit`() {
172
-        userState += User("acidBurn")
173
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
170
+        fakeUserState += User("acidBurn")
171
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
174
 
172
 
175
         handler.processEvent(ircClient, UserQuit(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost")))
173
         handler.processEvent(ircClient, UserQuit(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost")))
176
 
174
 
177
-        assertNull(userState["acidBurn"])
175
+        assertNull(fakeUserState["acidBurn"])
178
     }
176
     }
179
 
177
 
180
     @Test
178
     @Test
181
     fun `adds users to channels on names received`() {
179
     fun `adds users to channels on names received`() {
182
-        userState += User("acidBurn")
183
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
180
+        fakeUserState += User("acidBurn")
181
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
184
 
182
 
185
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn")))
183
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn")))
186
 
184
 
187
-        assertEquals(listOf("#dumpsterdiving", "#thegibson"), userState["acidBurn"]?.channels?.toList())
185
+        assertEquals(listOf("#dumpsterdiving", "#thegibson"), fakeUserState["acidBurn"]?.channels?.toList())
188
     }
186
     }
189
 
187
 
190
     @Test
188
     @Test
191
     fun `updates user details on names received`() {
189
     fun `updates user details on names received`() {
192
-        userState += User("acidBurn")
193
-        userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
190
+        fakeUserState += User("acidBurn")
191
+        fakeUserState.addToChannel(User("acidBurn"), "#dumpsterdiving")
194
 
192
 
195
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn!libby@root.localhost")))
193
         handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn!libby@root.localhost")))
196
 
194
 
197
-        val details = userState["acidBurn"]?.details!!
195
+        val details = fakeUserState["acidBurn"]?.details!!
198
         assertEquals("libby", details.ident)
196
         assertEquals("libby", details.ident)
199
         assertEquals("root.localhost", details.hostname)
197
         assertEquals("root.localhost", details.hostname)
200
     }
198
     }
201
 
199
 
202
     @Test
200
     @Test
203
     fun `updates user info on account change`() {
201
     fun `updates user info on account change`() {
204
-        userState += User("acidBurn")
202
+        fakeUserState += User("acidBurn")
205
 
203
 
206
         handler.processEvent(ircClient, UserAccountChanged(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "acidBurn"))
204
         handler.processEvent(ircClient, UserAccountChanged(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "acidBurn"))
207
 
205
 
208
-        val details = userState["acidBurn"]?.details!!
206
+        val details = fakeUserState["acidBurn"]?.details!!
209
         assertEquals("acidBurn", details.account)
207
         assertEquals("acidBurn", details.account)
210
     }
208
     }
211
 
209
 
212
     @Test
210
     @Test
213
     fun `updates local nickname for local nick changes`() {
211
     fun `updates local nickname for local nick changes`() {
214
-        val user = User("acidBurn", "libby", "root.localhost")
215
-        whenever(ircClient.isLocalUser(user)).doReturn(true)
212
+        val user = User("zeroCool", "dade", "root.localhost")
216
 
213
 
217
-        handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "acid~"))
214
+        handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "crashOverride"))
218
 
215
 
219
-        assertEquals("acid~", serverState.localNickname)
216
+        assertEquals("crashOverride", fakeServerState.localNickname)
220
     }
217
     }
221
 
218
 
222
     @Test
219
     @Test
223
     fun `updates nickname for remote nick changes`() {
220
     fun `updates nickname for remote nick changes`() {
224
         val user = User("acidBurn", "libby", "root.localhost")
221
         val user = User("acidBurn", "libby", "root.localhost")
225
-        userState += User("AcidBurn")
222
+        fakeUserState += User("AcidBurn")
226
 
223
 
227
         handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "acid~"))
224
         handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "acid~"))
228
 
225
 
229
-        assertNotNull(userState["acid~"])
230
-        assertNull(userState["AcidBurn"])
231
-        assertEquals("acid~", userState["acid~"]?.details?.nickname)
226
+        assertNotNull(fakeUserState["acid~"])
227
+        assertNull(fakeUserState["AcidBurn"])
228
+        assertEquals("acid~", fakeUserState["acid~"]?.details?.nickname)
232
     }
229
     }
233
 
230
 
234
     @Test
231
     @Test
235
     fun `updates details for remote host changes`() {
232
     fun `updates details for remote host changes`() {
236
         val user = User("acidBurn", "libby", "root.localhost")
233
         val user = User("acidBurn", "libby", "root.localhost")
237
-        userState += User("AcidBurn")
234
+        fakeUserState += User("AcidBurn")
238
 
235
 
239
         handler.processEvent(ircClient, UserHostChanged(EventMetadata(TestConstants.time), user, "burn", "root.gibson"))
236
         handler.processEvent(ircClient, UserHostChanged(EventMetadata(TestConstants.time), user, "burn", "root.gibson"))
240
 
237
 
241
-        assertEquals("burn", userState["acidBurn"]?.details?.ident)
242
-        assertEquals("root.gibson", userState["acidBurn"]?.details?.hostname)
238
+        assertEquals("burn", fakeUserState["acidBurn"]?.details?.ident)
239
+        assertEquals("root.gibson", fakeUserState["acidBurn"]?.details?.hostname)
243
     }
240
     }
244
 
241
 
245
 }
242
 }

+ 22
- 18
src/test/kotlin/com/dmdirc/ktirc/events/mutators/BatchMutatorTest.kt View File

7
 import com.dmdirc.ktirc.model.Batch
7
 import com.dmdirc.ktirc.model.Batch
8
 import com.dmdirc.ktirc.model.ServerState
8
 import com.dmdirc.ktirc.model.ServerState
9
 import com.dmdirc.ktirc.model.User
9
 import com.dmdirc.ktirc.model.User
10
-import com.nhaarman.mockitokotlin2.*
10
+import io.mockk.every
11
+import io.mockk.mockk
12
+import io.mockk.verify
11
 import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.Assertions.*
12
 import org.junit.jupiter.api.Test
14
 import org.junit.jupiter.api.Test
13
 
15
 
15
 
17
 
16
     private val mutator = BatchMutator()
18
     private val mutator = BatchMutator()
17
 
19
 
18
-    private val serverState = ServerState("", "")
19
-    private val messageEmitter = mock<MessageEmitter>()
20
-    private val ircClient = mock<IrcClient> {
21
-        on { serverState } doReturn serverState
20
+    private val messageEmitter = mockk<MessageEmitter>()
21
+    private val fakeServerState = ServerState("", "")
22
+    private val ircClient = mockk<IrcClient> {
23
+        every { serverState } returns fakeServerState
22
     }
24
     }
23
 
25
 
24
     @Test
26
     @Test
36
         val events = mutator.mutateEvent(ircClient, messageEmitter, event)
38
         val events = mutator.mutateEvent(ircClient, messageEmitter, event)
37
 
39
 
38
         assertTrue(events.isEmpty())
40
         assertTrue(events.isEmpty())
39
-        assertNotNull(serverState.batches["abcdef"])
40
-        serverState.batches["abcdef"]?.let {
41
+        assertNotNull(fakeServerState.batches["abcdef"])
42
+        fakeServerState.batches["abcdef"]?.let {
41
             assertEquals(listOf("foo", "bar"), it.arguments)
43
             assertEquals(listOf("foo", "bar"), it.arguments)
42
             assertEquals("netsplit", it.type)
44
             assertEquals("netsplit", it.type)
43
             assertTrue(it.events.isEmpty())
45
             assertTrue(it.events.isEmpty())
47
 
49
 
48
     @Test
50
     @Test
49
     fun `adds to batch when event has a batch ID`() {
51
     fun `adds to batch when event has a batch ID`() {
50
-        serverState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
52
+        fakeServerState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
51
 
53
 
52
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
54
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
53
         mutator.mutateEvent(ircClient, messageEmitter, event)
55
         mutator.mutateEvent(ircClient, messageEmitter, event)
54
 
56
 
55
-        assertEquals(listOf(event), serverState.batches["abcdef"]!!.events)
57
+        assertEquals(listOf(event), fakeServerState.batches["abcdef"]!!.events)
56
     }
58
     }
57
 
59
 
58
     @Test
60
     @Test
59
     fun `suppresses event when it has a batch ID`() {
61
     fun `suppresses event when it has a batch ID`() {
60
-        serverState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
62
+        fakeServerState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
61
 
63
 
62
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
64
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
63
         val events = mutator.mutateEvent(ircClient, messageEmitter, event)
65
         val events = mutator.mutateEvent(ircClient, messageEmitter, event)
67
 
69
 
68
     @Test
70
     @Test
69
     fun `passes event for processing only when it has a batch ID`() {
71
     fun `passes event for processing only when it has a batch ID`() {
70
-        serverState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
72
+        fakeServerState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time))
71
 
73
 
72
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
74
         val event = UserNickChanged(EventMetadata(TestConstants.time, "abcdef"), User("zeroCool"), "crashOverride")
73
         mutator.mutateEvent(ircClient, messageEmitter, event)
75
         mutator.mutateEvent(ircClient, messageEmitter, event)
74
 
76
 
75
-        verify(messageEmitter).handleEvent(any(), same(event), eq(true))
77
+        verify {
78
+            messageEmitter.handleEvent(any(), refEq(event), eq(true))
79
+        }
76
     }
80
     }
77
 
81
 
78
     @Test
82
     @Test
79
     fun `sends a batch when it finishes and the parent is null`() {
83
     fun `sends a batch when it finishes and the parent is null`() {
80
-        serverState.batches["abcdef"] = Batch("netsplit", listOf("p1", "p2"), EventMetadata(TestConstants.time), events = mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
84
+        fakeServerState.batches["abcdef"] = Batch("netsplit", listOf("p1", "p2"), EventMetadata(TestConstants.time), events = mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
81
 
85
 
82
         val events = mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
86
         val events = mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
83
 
87
 
92
 
96
 
93
     @Test
97
     @Test
94
     fun `adds a batch to its parent when it finishes`() {
98
     fun `adds a batch to its parent when it finishes`() {
95
-        serverState.batches["12345"] = Batch("history", emptyList(), EventMetadata(TestConstants.time))
96
-        serverState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time, batchId = "12345"), mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
99
+        fakeServerState.batches["12345"] = Batch("history", emptyList(), EventMetadata(TestConstants.time))
100
+        fakeServerState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time, batchId = "12345"), mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
97
 
101
 
98
         val events = mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
102
         val events = mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
99
 
103
 
100
         assertEquals(0, events.size)
104
         assertEquals(0, events.size)
101
 
105
 
102
-        val parent = serverState.batches["12345"]?.events
106
+        val parent = fakeServerState.batches["12345"]?.events
103
         assertEquals(1, parent?.size)
107
         assertEquals(1, parent?.size)
104
 
108
 
105
         val event = parent?.get(0) as BatchReceived
109
         val event = parent?.get(0) as BatchReceived
109
 
113
 
110
     @Test
114
     @Test
111
     fun `deletes batch when it finishes`() {
115
     fun `deletes batch when it finishes`() {
112
-        serverState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time), events = mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
116
+        fakeServerState.batches["abcdef"] = Batch("netsplit", emptyList(), EventMetadata(TestConstants.time), events = mutableListOf(ServerConnected(EventMetadata(TestConstants.time, "abcdef"))))
113
 
117
 
114
         mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
118
         mutator.mutateEvent(ircClient, messageEmitter, BatchFinished(EventMetadata(TestConstants.time), "abcdef"))
115
 
119
 
116
-        assertNull(serverState.batches["abcdef"])
120
+        assertNull(fakeServerState.batches["abcdef"])
117
     }
121
     }
118
 
122
 
119
 }
123
 }

+ 30
- 29
src/test/kotlin/com/dmdirc/ktirc/events/mutators/ChannelFanOutMutatorTest.kt View File

7
 import com.dmdirc.ktirc.io.CaseMapping
7
 import com.dmdirc.ktirc.io.CaseMapping
8
 import com.dmdirc.ktirc.io.MessageEmitter
8
 import com.dmdirc.ktirc.io.MessageEmitter
9
 import com.dmdirc.ktirc.model.*
9
 import com.dmdirc.ktirc.model.*
10
-import com.nhaarman.mockitokotlin2.doReturn
11
-import com.nhaarman.mockitokotlin2.mock
10
+import io.mockk.every
11
+import io.mockk.mockk
12
 import org.junit.jupiter.api.Assertions
12
 import org.junit.jupiter.api.Assertions
13
+import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.Test
14
 import org.junit.jupiter.api.Test
14
 
15
 
15
 internal class ChannelFanOutMutatorTest {
16
 internal class ChannelFanOutMutatorTest {
16
 
17
 
17
     private val mutator = ChannelFanOutMutator()
18
     private val mutator = ChannelFanOutMutator()
18
-    private val channelStateMap = ChannelStateMap { CaseMapping.Rfc }
19
-    private val serverState = ServerState("", "")
20
-    private val behaviour = BehaviourConfig()
21
-    private val messageEmitter = mock<MessageEmitter>()
22
-    private val ircClient = mock<IrcClient> {
23
-        on { serverState } doReturn serverState
24
-        on { channelState } doReturn channelStateMap
25
-        on { behaviour } doReturn behaviour
26
-        on { isLocalUser(User("acidburn", "libby", "root.localhost")) } doReturn true
27
-        on { isLocalUser("acidburn") } doReturn  true
19
+    private val fakeServerState = ServerState("", "")
20
+    private val fakeChannelStateMap = ChannelStateMap { CaseMapping.Rfc }
21
+    private val fakeBehaviour = BehaviourConfig()
22
+    private val messageEmitter = mockk<MessageEmitter>()
23
+    private val ircClient = mockk<IrcClient> {
24
+        every { serverState } returns fakeServerState
25
+        every { channelState } returns fakeChannelStateMap
26
+        every { behaviour } returns fakeBehaviour
27
+        every { isLocalUser(any<User>()) } answers { arg<User>(0) == User("acidburn", "libby", "root.localhost") }
28
+        every { isLocalUser(any<String>()) } answers { arg<String>(0) == "acidburn" }
28
     }
29
     }
29
 
30
 
30
     @Test
31
     @Test
31
     fun `raises ChannelQuit event for each channel a user quits from`() {
32
     fun `raises ChannelQuit event for each channel a user quits from`() {
32
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
33
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
33
             users += ChannelUser("ZeroCool")
34
             users += ChannelUser("ZeroCool")
34
-            channelStateMap += this
35
+            fakeChannelStateMap += this
35
         }
36
         }
36
 
37
 
37
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
38
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
38
             users += ChannelUser("ZeroCool")
39
             users += ChannelUser("ZeroCool")
39
-            channelStateMap += this
40
+            fakeChannelStateMap += this
40
         }
41
         }
41
 
42
 
42
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
43
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
43
             users += ChannelUser("AcidBurn")
44
             users += ChannelUser("AcidBurn")
44
-            channelStateMap += this
45
+            fakeChannelStateMap += this
45
         }
46
         }
46
 
47
 
47
         val quitEvent = UserQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "Hack the planet!")
48
         val quitEvent = UserQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "Hack the planet!")
48
         val events = mutator.mutateEvent(ircClient, messageEmitter, quitEvent)
49
         val events = mutator.mutateEvent(ircClient, messageEmitter, quitEvent)
49
 
50
 
50
         val names = mutableListOf<String>()
51
         val names = mutableListOf<String>()
51
-        Assertions.assertEquals(3, events.size)
52
-        Assertions.assertSame(quitEvent, events[0])
52
+        assertEquals(3, events.size)
53
+        assertSame(quitEvent, events[0])
53
         events.subList(1, events.size).forEach { event ->
54
         events.subList(1, events.size).forEach { event ->
54
             (event as ChannelQuit).let {
55
             (event as ChannelQuit).let {
55
-                Assertions.assertEquals(TestConstants.time, it.metadata.time)
56
-                Assertions.assertEquals("zerocool", it.user.nickname)
57
-                Assertions.assertEquals("Hack the planet!", it.reason)
56
+                assertEquals(TestConstants.time, it.metadata.time)
57
+                assertEquals("zerocool", it.user.nickname)
58
+                assertEquals("Hack the planet!", it.reason)
58
                 names.add(it.target)
59
                 names.add(it.target)
59
             }
60
             }
60
         }
61
         }
61
 
62
 
62
-        Assertions.assertTrue("#thegibson" in names)
63
-        Assertions.assertTrue("#dumpsterdiving" in names)
63
+        assertTrue("#thegibson" in names)
64
+        assertTrue("#dumpsterdiving" in names)
64
     }
65
     }
65
 
66
 
66
     @Test
67
     @Test
67
     fun `raises ChannelNickChanged event for each channel a user changes nicks in`() {
68
     fun `raises ChannelNickChanged event for each channel a user changes nicks in`() {
68
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
69
         with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
69
             users += ChannelUser("ZeroCool")
70
             users += ChannelUser("ZeroCool")
70
-            channelStateMap += this
71
+            fakeChannelStateMap += this
71
         }
72
         }
72
 
73
 
73
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
74
         with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
74
             users += ChannelUser("ZeroCool")
75
             users += ChannelUser("ZeroCool")
75
-            channelStateMap += this
76
+            fakeChannelStateMap += this
76
         }
77
         }
77
 
78
 
78
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
79
         with (ChannelState("#chat") { CaseMapping.Rfc }) {
79
             users += ChannelUser("AcidBurn")
80
             users += ChannelUser("AcidBurn")
80
-            channelStateMap += this
81
+            fakeChannelStateMap += this
81
         }
82
         }
82
 
83
 
83
         val nickEvent = UserNickChanged(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "zer0c00l")
84
         val nickEvent = UserNickChanged(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "zer0c00l")
84
         val events = mutator.mutateEvent(ircClient, messageEmitter, nickEvent)
85
         val events = mutator.mutateEvent(ircClient, messageEmitter, nickEvent)
85
 
86
 
86
         val names = mutableListOf<String>()
87
         val names = mutableListOf<String>()
87
-        Assertions.assertEquals(3, events.size)
88
-        Assertions.assertSame(nickEvent, events[0])
88
+        assertEquals(3, events.size)
89
+        assertSame(nickEvent, events[0])
89
         events.subList(1, events.size).forEach { event ->
90
         events.subList(1, events.size).forEach { event ->
90
             (event as ChannelNickChanged).let {
91
             (event as ChannelNickChanged).let {
91
                 Assertions.assertEquals(TestConstants.time, it.metadata.time)
92
                 Assertions.assertEquals(TestConstants.time, it.metadata.time)
95
             }
96
             }
96
         }
97
         }
97
 
98
 
98
-        Assertions.assertTrue("#thegibson" in names)
99
-        Assertions.assertTrue("#dumpsterdiving" in names)
99
+        assertTrue("#thegibson" in names)
100
+        assertTrue("#dumpsterdiving" in names)
100
     }
101
     }
101
 }
102
 }

+ 6
- 6
src/test/kotlin/com/dmdirc/ktirc/events/mutators/ServerReadyMutatorTest.kt View File

7
 import com.dmdirc.ktirc.model.ServerState
7
 import com.dmdirc.ktirc.model.ServerState
8
 import com.dmdirc.ktirc.model.ServerStatus
8
 import com.dmdirc.ktirc.model.ServerStatus
9
 import com.dmdirc.ktirc.model.User
9
 import com.dmdirc.ktirc.model.User
10
-import com.nhaarman.mockitokotlin2.doReturn
11
-import com.nhaarman.mockitokotlin2.mock
10
+import io.mockk.every
11
+import io.mockk.mockk
12
 import org.junit.jupiter.api.Assertions.*
12
 import org.junit.jupiter.api.Assertions.*
13
 import org.junit.jupiter.api.Test
13
 import org.junit.jupiter.api.Test
14
 
14
 
15
 internal class ServerReadyMutatorTest {
15
 internal class ServerReadyMutatorTest {
16
 
16
 
17
-    private val serverState = ServerState("", "")
18
-    private val messageEmitter = mock<MessageEmitter>()
19
-    private val ircClient = mock<IrcClient> {
20
-        on { serverState } doReturn serverState
17
+    private val messageEmitter = mockk<MessageEmitter>()
18
+    private val fakeServerState = ServerState("", "")
19
+    private val ircClient = mockk<IrcClient> {
20
+        every { serverState } returns fakeServerState
21
     }
21
     }
22
 
22
 
23
     private val mutator = ServerReadyMutator()
23
     private val mutator = ServerReadyMutator()

+ 1
- 0
src/test/resources/io/mockk/settings.properties View File

1
+relaxUnitFun=true

Loading…
Cancel
Save