mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-07 16:40:43 +08:00
Improve AbstractNoticeProcessorTest
This commit is contained in:
parent
1f03374eb4
commit
e202149c3a
@ -31,10 +31,7 @@ import net.mamoe.mirai.internal.network.protocol.packet.IncomingPacket
|
|||||||
import net.mamoe.mirai.internal.utils.io.JceStruct
|
import net.mamoe.mirai.internal.utils.io.JceStruct
|
||||||
import net.mamoe.mirai.internal.utils.io.ProtocolStruct
|
import net.mamoe.mirai.internal.utils.io.ProtocolStruct
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars
|
import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars
|
||||||
import net.mamoe.mirai.utils.TypeSafeMap
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.cast
|
|
||||||
import net.mamoe.mirai.utils.currentTimeSeconds
|
|
||||||
import net.mamoe.mirai.utils.hexToUBytes
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +42,9 @@ internal abstract class AbstractNoticeProcessorTest : AbstractNettyNHTest(), Gro
|
|||||||
System.setProperty("mirai.network.notice.pipeline.log.full", "true")
|
System.setProperty("mirai.network.notice.pipeline.log.full", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected object UseTestContext {
|
protected class UseTestContext(
|
||||||
|
val attributes: MutableTypeSafeMap
|
||||||
|
) {
|
||||||
val EMPTY_BYTE_ARRAY get() = net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY
|
val EMPTY_BYTE_ARRAY get() = net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY
|
||||||
fun String.hexToBytes() = hexToUBytes().toByteArray()
|
fun String.hexToBytes() = hexToUBytes().toByteArray()
|
||||||
|
|
||||||
@ -61,7 +60,8 @@ internal abstract class AbstractNoticeProcessorTest : AbstractNettyNHTest(), Gro
|
|||||||
block: UseTestContext.() -> ProtocolStruct
|
block: UseTestContext.() -> ProtocolStruct
|
||||||
): ProcessResult {
|
): ProcessResult {
|
||||||
val handler = LoggingPacketHandlerAdapter(PacketLoggingStrategyImpl(bot), bot.logger)
|
val handler = LoggingPacketHandlerAdapter(PacketLoggingStrategyImpl(bot), bot.logger)
|
||||||
return pipeline.process(bot, block(UseTestContext), attributes).also { list ->
|
val context = UseTestContext(attributes.toMutableTypeSafeMap())
|
||||||
|
return pipeline.process(bot, block(context), context.attributes).also { list ->
|
||||||
for (packet in list) {
|
for (packet in list) {
|
||||||
handler.handlePacket(IncomingPacket("test", packet))
|
handler.handlePacket(IncomingPacket("test", packet))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user