This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Mock<T: RawRepresentable> where T.RawValue == FunctionName { | |
| let log = FunctionLogger<T>() | |
| /// Retrieve the potential calls for a given function name. | |
| /// - Parameters: | |
| /// - name: The name of the function to retrieve calls for. | |
| /// - Returns: The optional `FunctionCall` for the name provided. | |
| func calls(with name: T) -> FunctionCall? { log[name] } | |
| /// Log a function call with the given name and parameters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FunctionCall: Hashable { | |
| /// The name of the function | |
| let name: FunctionName | |
| /// The number of calls for the function. | |
| var numberOfCalls: Int { calls.count } | |
| /// The parameters sent to the function. | |
| private(set) var calls = [Any?]() | |
| init(name: FunctionName) { | |
| self.name = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // When `b` returns true, `hasAnswer` should be true. | |
| func testCheckAnswerTrue() { | |
| b.validateAnswerResponse = true | |
| a.checkAnswer() | |
| XCTAssertTrue(a.hasAnswer) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// A Bool indicating if the class has received any function calls. | |
| var hasReceivedCalls: Bool { get } | |
| /// Retrieve the potential calls for a given function name. | |
| /// - Parameters: | |
| /// - name: The name of the function to retrieve calls for. | |
| /// - Returns: The optional `FunctionCall` for the name provided. | |
| func calls(with name: FunctionName) -> FunctionCall? | |
| /// Log a function call with the given name and parameters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| XCTAssertTrue(self.router.hasReceivedCalls) | |
| XCTAssertFalse(self.reviewMock.hasReceivedCalls) | |
| let call = self.router.calls(with: RouterMock.AlertRouterTypeFunctions.presentAlert) | |
| XCTAssertNotNil(call) | |
| XCTAssertEqual(call?.calls, 1) | |
| XCTAssertEqual(call?.parameters[0] as? String, NSLocalizedString("fw_promo_mysound_hdr", comment: "")) | |
| XCTAssertEqual(call?.parameters[1] as? String, "Update Jabra Elite 45h to get you started with MySound.") | |
| XCTAssertEqual((call?.parameters[2] as? AlertAction)?.title, NSLocalizedString("jabra_support_fwpop_btn_later", comment: "")) | |
| XCTAssertEqual((call?.parameters[3] as? AlertAction)?.title, NSLocalizedString("update_now", comment: "")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func presentAlert(title: String? = nil, message: String? = nil, cancelAction: AlertAction? = nil, okAction: AlertAction? = nil) { | |
| router.presentAlert(title: title, message: message, cancelAction: cancelAction, okAction: okAction, from: router.topViewController) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A { | |
| /// A `Bool` indicating if we have the answer to the universe. | |
| private(set) var hasAnswer = false | |
| /// The instance of `BType` we are using to check if we have the answer. | |
| private let b: BType | |
| init(b: BType) { | |
| self.b = b | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol BType { | |
| /// Validates the answer. | |
| func validateAnswer() -> Bool | |
| } | |
| protocol CType { | |
| /// The answer to the universe. | |
| var number: Int { get } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let a = A() | |
| a.b = B() | |
| a.checkAnswer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A { | |
| /// The instance of B we are using to check if we have the answer. | |
| var b: B? | |
| /// A `Bool` indicating if we have the answer to the universe. | |
| private(set) var hasAnswer = false | |
| /// Checks if we have the answer to the universe and updates the `hasAnswer` property. | |
| func checkAnswer() { | |
| hasAnswer = b?.validateAnswer() ?? false | |
| } |