-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventBusTests.swift
48 lines (38 loc) · 1.2 KB
/
EventBusTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import XCTest
@testable import Bus
class MockEvent: IEvent {
static var executed2: Bool = false
static var executed3: Bool = false
}
class NotRegisteredMockEvent: IEvent {}
class MockEventHandler: IEventHandler {
var handle: (MockEvent) async throws -> Void = { _ in }
}
class MockEventHandler2: IEventHandler {
var handle: (_ event: MockEvent) async throws -> Void = { event in
MockEvent.executed2 = true
}
}
class MockEventHandler3: IEventHandler {
var handle: (_ event: MockEvent) async throws -> Void = { event in
MockEvent.executed3 = true
}
}
final class EventBusTests: XCTestCase {
func testRegisterHandler() {
XCTAssertNoThrow(try EventBus.register(MockEventHandler()))
}
func testHandleRegisteredQuery() async throws {
XCTAssertFalse(MockEvent.executed2)
XCTAssertFalse(MockEvent.executed3)
try EventBus.register(MockEventHandler2())
try EventBus.register(MockEventHandler3())
do {
try await EventBus.execute(MockEvent())
} catch {
XCTFail("Unexpected error: \(error)")
}
XCTAssertTrue(MockEvent.executed2)
XCTAssertTrue(MockEvent.executed3)
}
}