Skip to content

Commit 0936b15

Browse files
committed
feat: add MockEventProcessor implementation for testing
- Introduced `MockEventProcessor` interface in the test module with a companion object for creating mock event processors. - Provides a `MockEventProcessorImpl` class for custom event handling logic via coroutines flow. Signed-off-by: Forte <ForteScarlet@163.com>
1 parent 609b9d5 commit 0936b15

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

simbot-test/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# simbot-test
2+
3+
> [!warning]
4+
> 测试模块施工中、实验中。
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)