From 4d10338815bca98fc355f6a92ddd4259cd63ac2b Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 17 Jun 2021 00:20:41 +0800 Subject: [PATCH] Do not add `BotOfflineEventMonitor` in `SetStateTest` --- .../kotlin/network/impl/netty/SetStateTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mirai-core/src/commonTest/kotlin/network/impl/netty/SetStateTest.kt b/mirai-core/src/commonTest/kotlin/network/impl/netty/SetStateTest.kt index 402e03d3191..b5514dc8234 100644 --- a/mirai-core/src/commonTest/kotlin/network/impl/netty/SetStateTest.kt +++ b/mirai-core/src/commonTest/kotlin/network/impl/netty/SetStateTest.kt @@ -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 @@ -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 { @@ -76,4 +83,18 @@ internal class SetStateTest : AbstractNettyNHTest() { assertIs(list[0]) } } + + @Test + fun `Precondition - setState should ignore duplications 2 OK to CLOSED to CLOSED`() = runBlockingUnit { + assertNotNull(network.setStateOK(channel)) + assertState(OK) + assertEventBroadcasts { + assertNotNull(network.setStateClosed(IllegalStateException("1"))) + assertState(CLOSED) + eventDispatcher.joinBroadcast() + }.let { list -> + assertEquals(1, list.size) + assertIs(list[0]) + } + } } \ No newline at end of file