|
@@ -1,8 +1,6 @@
|
1
|
1
|
package com.dmdirc.ktirc
|
2
|
2
|
|
3
|
|
-import com.dmdirc.ktirc.events.IrcEvent
|
4
|
|
-import com.dmdirc.ktirc.events.ServerConnected
|
5
|
|
-import com.dmdirc.ktirc.events.ServerWelcome
|
|
3
|
+import com.dmdirc.ktirc.events.*
|
6
|
4
|
import com.dmdirc.ktirc.io.CaseMapping
|
7
|
5
|
import com.dmdirc.ktirc.io.LineBufferedSocket
|
8
|
6
|
import com.dmdirc.ktirc.model.Profile
|
|
@@ -76,16 +74,37 @@ internal class IrcClientImplTest {
|
76
|
74
|
}
|
77
|
75
|
|
78
|
76
|
@Test
|
79
|
|
- fun `IrcClientImpl emits connected event with local time`() = runBlocking {
|
|
77
|
+ fun `IrcClientImpl emits connection events with local time`() = runBlocking {
|
80
|
78
|
currentTimeProvider = { TestConstants.time }
|
81
|
79
|
val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
82
|
80
|
client.socketFactory = mockSocketFactory
|
83
|
81
|
client.onEvent(mockEventHandler)
|
84
|
82
|
client.connect()
|
85
|
83
|
|
86
|
|
- val captor = argumentCaptor<ServerConnected>()
|
87
|
|
- verify(mockEventHandler, timeout(500)).invoke(captor.capture())
|
|
84
|
+ val captor = argumentCaptor<IrcEvent>()
|
|
85
|
+ verify(mockEventHandler, timeout(500).atLeast(2)).invoke(captor.capture())
|
|
86
|
+
|
|
87
|
+ assertTrue(captor.firstValue is ServerConnecting)
|
88
|
88
|
assertEquals(TestConstants.time, captor.firstValue.time)
|
|
89
|
+
|
|
90
|
+ assertTrue(captor.secondValue is ServerConnected)
|
|
91
|
+ assertEquals(TestConstants.time, captor.secondValue.time)
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ fun `IrcClientImpl emits disconnected event with local time when read channel closed`() = runBlocking {
|
|
96
|
+ currentTimeProvider = { TestConstants.time }
|
|
97
|
+ val client = IrcClientImpl(Server(HOST, PORT), Profile(NICK, REAL_NAME, USER_NAME))
|
|
98
|
+ client.socketFactory = mockSocketFactory
|
|
99
|
+ client.connect()
|
|
100
|
+ client.blockUntilConnected()
|
|
101
|
+
|
|
102
|
+ client.onEvent(mockEventHandler)
|
|
103
|
+ readLineChannel.close()
|
|
104
|
+
|
|
105
|
+ val captor = argumentCaptor<ServerDisconnected>()
|
|
106
|
+ verify(mockEventHandler, timeout(500)).invoke(captor.capture())
|
|
107
|
+ assertEquals(TestConstants.time, captor.lastValue.time)
|
89
|
108
|
}
|
90
|
109
|
|
91
|
110
|
@Test
|