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