Skip to content

Commit

Permalink
Do not add BotOfflineEventMonitor in SetStateTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Jun 16, 2021
1 parent 5efced6 commit 4d10338
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

package net.mamoe.mirai.internal.network.impl.netty

import kotlinx.coroutines.CoroutineScope
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.events.BotOfflineEvent
import net.mamoe.mirai.internal.AbstractBot
import net.mamoe.mirai.internal.network.components.BotOfflineEventMonitor
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State.*
import net.mamoe.mirai.internal.test.assertEventBroadcasts
import net.mamoe.mirai.internal.test.runBlockingUnit
Expand Down Expand Up @@ -63,6 +66,10 @@ internal class SetStateTest : AbstractNettyNHTest() {

@Test
fun `setState should ignore duplications 2 OK to CLOSED to CLOSED`() = runBlockingUnit {
overrideComponents[BotOfflineEventMonitor] = object : BotOfflineEventMonitor {
override fun attachJob(bot: AbstractBot, scope: CoroutineScope) {
}
}
assertNotNull(network.setStateOK(channel))
assertState(OK)
assertEventBroadcasts<Event> {
Expand All @@ -76,4 +83,18 @@ internal class SetStateTest : AbstractNettyNHTest() {
assertIs<BotOfflineEvent.Active>(list[0])
}
}

@Test
fun `Precondition - setState should ignore duplications 2 OK to CLOSED to CLOSED`() = runBlockingUnit {
assertNotNull(network.setStateOK(channel))
assertState(OK)
assertEventBroadcasts<Event> {
assertNotNull(network.setStateClosed(IllegalStateException("1")))
assertState(CLOSED)
eventDispatcher.joinBroadcast()
}.let { list ->
assertEquals(1, list.size)
assertIs<BotOfflineEvent.Active>(list[0])
}
}
}

0 comments on commit 4d10338

Please sign in to comment.