|
@@ -49,7 +49,7 @@ internal class IrcClientImplTest {
|
49
|
49
|
}
|
50
|
50
|
|
51
|
51
|
@Test
|
52
|
|
- fun `IrcClientImpl uses socket factory to create a new socket on connect`() {
|
|
52
|
+ fun `uses socket factory to create a new socket on connect`() {
|
53
|
53
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
54
|
54
|
client.socketFactory = mockSocketFactory
|
55
|
55
|
client.connect()
|
|
@@ -58,7 +58,7 @@ internal class IrcClientImplTest {
|
58
|
58
|
}
|
59
|
59
|
|
60
|
60
|
@Test
|
61
|
|
- fun `IrcClientImpl uses socket factory to create a new tls on connect`() {
|
|
61
|
+ fun `uses socket factory to create a new tls on connect`() {
|
62
|
62
|
val client = IrcClientImpl(Server(HOST, PORT, true), Profile(NICK, REAL_NAME, USER_NAME))
|
63
|
63
|
client.socketFactory = mockSocketFactory
|
64
|
64
|
client.connect()
|
|
@@ -67,7 +67,7 @@ internal class IrcClientImplTest {
|
67
|
67
|
}
|
68
|
68
|
|
69
|
69
|
@Test
|
70
|
|
- fun `IrcClientImpl throws if socket already exists`() {
|
|
70
|
+ fun `throws if socket already exists`() {
|
71
|
71
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
72
|
72
|
client.socketFactory = mockSocketFactory
|
73
|
73
|
client.connect()
|
|
@@ -78,7 +78,7 @@ internal class IrcClientImplTest {
|
78
|
78
|
}
|
79
|
79
|
|
80
|
80
|
@Test
|
81
|
|
- fun `IrcClientImpl emits connection events with local time`() = runBlocking {
|
|
81
|
+ fun `emits connection events with local time`() = runBlocking {
|
82
|
82
|
currentTimeProvider = { TestConstants.time }
|
83
|
83
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
84
|
84
|
client.socketFactory = mockSocketFactory
|
|
@@ -96,48 +96,43 @@ internal class IrcClientImplTest {
|
96
|
96
|
}
|
97
|
97
|
|
98
|
98
|
@Test
|
99
|
|
- fun `IrcClientImpl emits disconnected event with local time when read channel closed`() = runBlocking {
|
|
99
|
+ fun `emits disconnected event with local time when read channel closed`() = runBlocking {
|
100
|
100
|
currentTimeProvider = { TestConstants.time }
|
101
|
101
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
102
|
102
|
client.socketFactory = mockSocketFactory
|
103
|
103
|
client.connect()
|
104
|
|
- client.blockUntilConnected()
|
105
|
104
|
|
106
|
105
|
client.onEvent(mockEventHandler)
|
107
|
106
|
readLineChannel.close()
|
108
|
107
|
|
109
|
108
|
val captor = argumentCaptor<ServerDisconnected>()
|
110
|
|
- verify(mockEventHandler, timeout(500)).invoke(captor.capture())
|
|
109
|
+ verify(mockEventHandler, timeout(500).atLeast(2)).invoke(captor.capture())
|
111
|
110
|
assertEquals(TestConstants.time, captor.lastValue.time)
|
112
|
111
|
}
|
113
|
112
|
|
114
|
113
|
@Test
|
115
|
|
- fun `IrcClientImpl sends basic connection strings`() = runBlocking {
|
|
114
|
+ fun `sends basic connection strings`() = runBlocking {
|
116
|
115
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
117
|
116
|
client.socketFactory = mockSocketFactory
|
118
|
117
|
client.connect()
|
119
|
118
|
|
120
|
|
- client.blockUntilConnected()
|
121
|
|
-
|
122
|
119
|
assertEquals("CAP LS 302", String(sendLineChannel.receive()))
|
123
|
120
|
assertEquals("NICK :$NICK", String(sendLineChannel.receive()))
|
124
|
121
|
assertEquals("USER $USER_NAME 0 * :$REAL_NAME", String(sendLineChannel.receive()))
|
125
|
122
|
}
|
126
|
123
|
|
127
|
124
|
@Test
|
128
|
|
- fun `IrcClientImpl sends password first, when present`() = runBlocking {
|
|
125
|
+ fun `sends password first, when present`() = runBlocking {
|
129
|
126
|
val client = IrcClientImpl(Server(HOST, PORT, password = PASSWORD), Profile(NICK, REAL_NAME, USER_NAME))
|
130
|
127
|
client.socketFactory = mockSocketFactory
|
131
|
128
|
client.connect()
|
132
|
129
|
|
133
|
|
- client.blockUntilConnected()
|
134
|
|
-
|
135
|
130
|
assertEquals("CAP LS 302", String(sendLineChannel.receive()))
|
136
|
131
|
assertEquals("PASS :$PASSWORD", String(sendLineChannel.receive()))
|
137
|
132
|
}
|
138
|
133
|
|
139
|
134
|
@Test
|
140
|
|
- fun `IrcClientImpl sends events to provided event handler`() {
|
|
135
|
+ fun `sends events to provided event handler`() {
|
141
|
136
|
val client = IrcClientImpl(Server(HOST, PORT, password = PASSWORD), Profile(NICK, REAL_NAME, USER_NAME))
|
142
|
137
|
client.socketFactory = mockSocketFactory
|
143
|
138
|
client.onEvent(mockEventHandler)
|
|
@@ -152,14 +147,14 @@ internal class IrcClientImplTest {
|
152
|
147
|
}
|
153
|
148
|
|
154
|
149
|
@Test
|
155
|
|
- fun `IrcClient gets case mapping from server features`() {
|
|
150
|
+ fun `gets case mapping from server features`() {
|
156
|
151
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
157
|
152
|
client.serverState.features[ServerFeature.ServerCaseMapping] = CaseMapping.RfcStrict
|
158
|
153
|
assertEquals(CaseMapping.RfcStrict, client.caseMapping)
|
159
|
154
|
}
|
160
|
155
|
|
161
|
156
|
@Test
|
162
|
|
- fun `IrcClient indicates if user is local user or not`() {
|
|
157
|
+ fun `indicates if user is local user or not`() {
|
163
|
158
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
164
|
159
|
client.serverState.localNickname = "[acidBurn]"
|
165
|
160
|
|
|
@@ -168,7 +163,7 @@ internal class IrcClientImplTest {
|
168
|
163
|
}
|
169
|
164
|
|
170
|
165
|
@Test
|
171
|
|
- fun `IrcClient indicates if nickname is local user or not`() {
|
|
166
|
+ fun `indicates if nickname is local user or not`() {
|
172
|
167
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
173
|
168
|
client.serverState.localNickname = "[acidBurn]"
|
174
|
169
|
|
|
@@ -177,7 +172,7 @@ internal class IrcClientImplTest {
|
177
|
172
|
}
|
178
|
173
|
|
179
|
174
|
@Test
|
180
|
|
- fun `IrcClient uses current case mapping to check local user`() {
|
|
175
|
+ fun `uses current case mapping to check local user`() {
|
181
|
176
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
182
|
177
|
client.serverState.localNickname = "[acidBurn]"
|
183
|
178
|
client.serverState.features[ServerFeature.ServerCaseMapping] = CaseMapping.Ascii
|
|
@@ -185,13 +180,11 @@ internal class IrcClientImplTest {
|
185
|
180
|
}
|
186
|
181
|
|
187
|
182
|
@Test
|
188
|
|
- fun `IrcClientImpl sends text to socket`() = runBlocking {
|
|
183
|
+ fun `sends text to socket`() = runBlocking {
|
189
|
184
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
190
|
185
|
client.socketFactory = mockSocketFactory
|
191
|
186
|
client.connect()
|
192
|
187
|
|
193
|
|
- client.blockUntilConnected()
|
194
|
|
-
|
195
|
188
|
client.send("testing 123")
|
196
|
189
|
|
197
|
190
|
assertEquals(true, withTimeoutOrNull(500) {
|
|
@@ -207,26 +200,22 @@ internal class IrcClientImplTest {
|
207
|
200
|
}
|
208
|
201
|
|
209
|
202
|
@Test
|
210
|
|
- fun `IrcClientImpl disconnects the socket`() = runBlocking {
|
|
203
|
+ fun `disconnects the socket`() = runBlocking {
|
211
|
204
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
212
|
205
|
client.socketFactory = mockSocketFactory
|
213
|
206
|
client.connect()
|
214
|
207
|
|
215
|
|
- client.blockUntilConnected()
|
216
|
|
-
|
217
|
208
|
client.disconnect()
|
218
|
209
|
|
219
|
210
|
verify(mockSocket, timeout(500)).disconnect()
|
220
|
211
|
}
|
221
|
212
|
|
222
|
213
|
@Test
|
223
|
|
- fun `IrcClientImpl sends messages in order`() = runBlocking {
|
|
214
|
+ fun `sends messages in order`() = runBlocking {
|
224
|
215
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
225
|
216
|
client.socketFactory = mockSocketFactory
|
226
|
217
|
client.connect()
|
227
|
218
|
|
228
|
|
- client.blockUntilConnected()
|
229
|
|
-
|
230
|
219
|
(0..100).forEach { client.send("TEST $it") }
|
231
|
220
|
|
232
|
221
|
assertEquals(100, withTimeoutOrNull(500) {
|
|
@@ -242,21 +231,28 @@ internal class IrcClientImplTest {
|
242
|
231
|
}
|
243
|
232
|
|
244
|
233
|
@Test
|
245
|
|
- fun `IrcClientImpl defaults local nickname to profile`() = runBlocking {
|
|
234
|
+ fun `defaults local nickname to profile`() = runBlocking {
|
246
|
235
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
247
|
236
|
assertEquals(NICK, client.serverState.localNickname)
|
248
|
237
|
}
|
249
|
238
|
|
250
|
239
|
@Test
|
251
|
|
- fun `IrcClientImpl defaults server name to host name`() = runBlocking {
|
|
240
|
+ fun `defaults server name to host name`() = runBlocking {
|
252
|
241
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
253
|
242
|
assertEquals(HOST, client.serverState.serverName)
|
254
|
243
|
}
|
255
|
244
|
|
256
|
|
- private suspend fun IrcClientImpl.blockUntilConnected() {
|
257
|
|
- // Yuck. Maybe connect should be asynchronous?
|
258
|
|
- while (serverState.status <= ServerStatus.Connecting) {
|
259
|
|
- delay(50)
|
|
245
|
+ @Test
|
|
246
|
+ fun `reset clears all state`() {
|
|
247
|
+ with (IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))) {
|
|
248
|
+ userState += User("acidBurn")
|
|
249
|
+ channelState += ChannelState("#thegibson") { CaseMapping.Rfc }
|
|
250
|
+ serverState.serverName = "root.$HOST"
|
|
251
|
+ reset()
|
|
252
|
+
|
|
253
|
+ assertEquals(0, userState.count())
|
|
254
|
+ assertEquals(0, channelState.count())
|
|
255
|
+ assertEquals(HOST, serverState.serverName)
|
260
|
256
|
}
|
261
|
257
|
}
|
262
|
258
|
|