@@ -46,3 +46,67 @@ class MPListenerControllerMock: NSObject, MPListenerControllerProtocol {
4646 onAPICalledExpectation? . fulfill ( )
4747 }
4848}
49+
50+ extension MPListenerControllerMock {
51+
52+ /// Verifies that the listener was called with the expected selector and parameters.
53+ /// Automatically checks `onAPICalledCalled`, the selector, and up to three parameters.
54+ func assertCalled(
55+ _ expectedSelector: Selector ,
56+ param1 expectedParam1: NSObject ? = nil ,
57+ param2 expectedParam2: NSObject ? = nil ,
58+ param3 expectedParam3: NSObject ? = nil ,
59+ file: StaticString = #file,
60+ line: UInt = #line
61+ ) {
62+ XCTAssertTrue ( onAPICalledCalled, " Expected onAPICalled to be called " , file: file, line: line)
63+
64+ guard let actualSelector = onAPICalledApiName else {
65+ XCTFail ( " Expected API name \( expectedSelector) , but none was recorded " , file: file, line: line)
66+ return
67+ }
68+ XCTAssertEqual (
69+ NSStringFromSelector ( actualSelector) ,
70+ NSStringFromSelector ( expectedSelector) ,
71+ " Expected API selector to match " ,
72+ file: file,
73+ line: line
74+ )
75+
76+ if let expectedParam1 {
77+ XCTAssertEqual (
78+ onAPICalledParameter1,
79+ expectedParam1,
80+ " Expected param1 to match for \( expectedSelector) " ,
81+ file: file,
82+ line: line
83+ )
84+ }
85+
86+ if let expectedParam2 {
87+ XCTAssertEqual (
88+ onAPICalledParameter2,
89+ expectedParam2,
90+ " Expected param2 to match for \( expectedSelector) " ,
91+ file: file,
92+ line: line
93+ )
94+ }
95+
96+ if let expectedParam3 {
97+ XCTAssertEqual (
98+ onAPICalledParameter3,
99+ expectedParam3,
100+ " Expected param3 to match for \( expectedSelector) " ,
101+ file: file,
102+ line: line
103+ )
104+ }
105+ }
106+
107+ /// Verifies that no API call occurred.
108+ func assertNotCalled( file: StaticString = #file, line: UInt = #line) {
109+ XCTAssertFalse ( onAPICalledCalled, " Expected onAPICalled NOT to be called " , file: file, line: line)
110+ XCTAssertTrue ( onAPICalledApiNames. isEmpty, " Expected no recorded API names " , file: file, line: line)
111+ }
112+ }
0 commit comments