|
| 1 | +/* |
| 2 | + * Copyright (c) 2025. ForteScarlet. |
| 3 | + * |
| 4 | + * Project https://github.com/simple-robot/simpler-robot |
| 5 | + * Email ForteScarlet@163.com |
| 6 | + * |
| 7 | + * This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Lesser General Public License as published by |
| 11 | + * the Free Software Foundation, either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * Lesser GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the Lesser GNU General Public License |
| 20 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +package love.forte.simbot.test.event |
| 25 | + |
| 26 | +import kotlinx.coroutines.flow.Flow |
| 27 | +import kotlinx.coroutines.flow.flow |
| 28 | +import love.forte.simbot.event.Event |
| 29 | +import love.forte.simbot.event.EventProcessor |
| 30 | +import love.forte.simbot.event.EventResult |
| 31 | +import kotlin.jvm.JvmStatic |
| 32 | + |
| 33 | +/** |
| 34 | + * Mock [EventProcessor]. |
| 35 | + * @since 4.13.0 |
| 36 | + * @author ForteScarlet |
| 37 | + */ |
| 38 | +public interface MockEventProcessor : EventProcessor { |
| 39 | + public companion object { |
| 40 | + public inline operator fun invoke(crossinline block: suspend (Event) -> EventResult): MockEventProcessor { |
| 41 | + return create { event -> flow { block(event) } } |
| 42 | + } |
| 43 | + |
| 44 | + @JvmStatic |
| 45 | + public fun create(block: (Event) -> Flow<EventResult>): MockEventProcessor { |
| 46 | + return MockEventProcessorImpl(block) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +private class MockEventProcessorImpl(private val processor: (Event) -> Flow<EventResult>) : MockEventProcessor { |
| 53 | + override fun push(event: Event): Flow<EventResult> = processor(event) |
| 54 | +} |
0 commit comments