-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stubbing nil values in Obj-C mocks
- Loading branch information
1 parent
331b6f4
commit 8f243ee
Showing
8 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// OptionalsTests.swift | ||
// MockingbirdTests | ||
// | ||
// Created by typealias on 12/22/21. | ||
// | ||
|
||
import Mockingbird | ||
@testable import MockingbirdTestsHost | ||
import XCTest | ||
|
||
class OptionalsTests: BaseTestCase { | ||
|
||
var optionalsMock: OptionalsProtocolMock! | ||
var optionalsInstance: OptionalsProtocol { optionalsMock } | ||
|
||
override func setUpWithError() throws { | ||
self.optionalsMock = mock(OptionalsProtocol.self) | ||
} | ||
|
||
func testStubNonNilReturnValue() { | ||
given(optionalsMock.methodWithOptionalReturn()).willReturn(true) | ||
XCTAssertEqual(optionalsInstance.methodWithOptionalReturn(), true) | ||
verify(optionalsMock.methodWithOptionalReturn()).wasCalled() | ||
} | ||
|
||
func testStubNilReturnValue() { | ||
given(optionalsMock.methodWithOptionalReturn()).willReturn(nil) | ||
XCTAssertNil(optionalsInstance.methodWithOptionalReturn()) | ||
verify(optionalsMock.methodWithOptionalReturn()).wasCalled() | ||
} | ||
|
||
func testStubNonNilBridgedReturnValue() { | ||
given(optionalsMock.methodWithOptionalBridgedReturn()).willReturn("foobar") | ||
XCTAssertEqual(optionalsInstance.methodWithOptionalBridgedReturn(), "foobar") | ||
verify(optionalsMock.methodWithOptionalBridgedReturn()).wasCalled() | ||
} | ||
|
||
func testStubNilBridgedReturnValue() { | ||
given(optionalsMock.methodWithOptionalBridgedReturn()).willReturn(nil) | ||
XCTAssertNil(optionalsInstance.methodWithOptionalBridgedReturn()) | ||
verify(optionalsMock.methodWithOptionalBridgedReturn()).wasCalled() | ||
} | ||
|
||
func testStubNonNilBridgedProperty() { | ||
given(optionalsMock.optionalBridgedVariable).willReturn("foobar") | ||
XCTAssertEqual(optionalsInstance.optionalBridgedVariable, "foobar") | ||
verify(optionalsMock.optionalBridgedVariable).wasCalled() | ||
} | ||
|
||
func testStubNilBridgedProperty() { | ||
given(optionalsMock.optionalBridgedVariable).willReturn(nil) | ||
XCTAssertNil(optionalsInstance.optionalBridgedVariable) | ||
verify(optionalsMock.optionalBridgedVariable).wasCalled() | ||
} | ||
} |