├── Cartfile ├── Gemfile ├── Sources └── OCMockito │ ├── include │ └── OCMockito │ │ ├── OCMockito.h │ │ ├── MKTObjectMock.h │ │ ├── MKTBaseMockObject.h │ │ ├── MKTProtocolMock.h │ │ ├── MKTClassObjectMock.h │ │ ├── MKTOngoingStubbing.h │ │ ├── MKTObjectAndProtocolMock.h │ │ ├── NSInvocation+OCMockito.h │ │ └── MKTNonObjectArgumentMatching.h │ ├── Invocation │ ├── MKTParseCallStack.h │ ├── MKTFilterCallStack.h │ ├── MKTLocation.h │ ├── MKTCallStackElement.h │ ├── MKTParseCallStack.m │ ├── MKTPrinter.h │ ├── MKTInvocation.m │ ├── MKTInvocation.h │ ├── MKTMatchingInvocationsFinder.h │ ├── MKTLocation.m │ ├── MKTInvocationMatcher.h │ ├── NSInvocation+OCMockito.h │ ├── MKTCallStackElement.m │ ├── MKTMatchingInvocationsFinder.m │ ├── MKT_TPDWeakProxy.h │ ├── MKTFilterCallStack.m │ └── NSInvocation+OCMockito.m │ ├── Stubbing │ ├── MKTStubbedInvocationMatcher.h │ ├── MKTReturnsValue.h │ ├── MKTExecutesBlock.h │ ├── MKTThrowsException.h │ ├── MKTReturnsValue.m │ ├── MKTExecutesBlock.m │ ├── MKTAnswer.h │ ├── MKTThrowsException.m │ ├── MKTInvocationContainer.h │ ├── MKTStubbedInvocationMatcher.m │ └── MKTInvocationContainer.m │ ├── Helpers │ ├── ArgumentGetters │ │ ├── MKTArgumentGetterChain.h │ │ ├── MKTBoolArgumentGetter.h │ │ ├── MKTCharArgumentGetter.h │ │ ├── MKTIntArgumentGetter.h │ │ ├── MKTLongArgumentGetter.h │ │ ├── MKTClassArgumentGetter.h │ │ ├── MKTDoubleArgumentGetter.h │ │ ├── MKTFloatArgumentGetter.h │ │ ├── MKTLongLongArgumentGetter.h │ │ ├── MKTObjectArgumentGetter.h │ │ ├── MKTShortArgumentGetter.h │ │ ├── MKTStructArgumentGetter.h │ │ ├── MKTPointerArgumentGetter.h │ │ ├── MKTSelectorArgumentGetter.h │ │ ├── MKTUnsignedIntArgumentGetter.h │ │ ├── MKTUnsignedCharArgumentGetter.h │ │ ├── MKTUnsignedLongArgumentGetter.h │ │ ├── MKTUnsignedShortArgumentGetter.h │ │ ├── MKTUnsignedLongLongArgumentGetter.h │ │ ├── MKTIntArgumentGetter.m │ │ ├── MKTBoolArgumentGetter.m │ │ ├── MKTCharArgumentGetter.m │ │ ├── MKTLongArgumentGetter.m │ │ ├── MKTFloatArgumentGetter.m │ │ ├── MKTShortArgumentGetter.m │ │ ├── MKTDoubleArgumentGetter.m │ │ ├── MKTLongLongArgumentGetter.m │ │ ├── MKTClassArgumentGetter.m │ │ ├── MKTUnsignedIntArgumentGetter.m │ │ ├── MKTPointerArgumentGetter.m │ │ ├── MKTUnsignedCharArgumentGetter.m │ │ ├── MKTUnsignedLongArgumentGetter.m │ │ ├── MKTObjectArgumentGetter.m │ │ ├── MKTUnsignedShortArgumentGetter.m │ │ ├── MKTSelectorArgumentGetter.m │ │ ├── MKTUnsignedLongLongArgumentGetter.m │ │ ├── MKTStructArgumentGetter.m │ │ ├── MKTArgumentGetter.h │ │ └── MKTArgumentGetter.m │ └── ReturnValueSetters │ │ ├── MKTReturnValueSetterChain.h │ │ ├── MKTIntReturnSetter.h │ │ ├── MKTBoolReturnSetter.h │ │ ├── MKTCharReturnSetter.h │ │ ├── MKTClassReturnSetter.h │ │ ├── MKTDoubleReturnSetter.h │ │ ├── MKTFloatReturnSetter.h │ │ ├── MKTLongReturnSetter.h │ │ ├── MKTObjectReturnSetter.h │ │ ├── MKTShortReturnSetter.h │ │ ├── MKTLongLongReturnSetter.h │ │ ├── MKTStructReturnSetter.h │ │ ├── MKTUnsignedIntReturnSetter.h │ │ ├── MKTUnsignedCharReturnSetter.h │ │ ├── MKTUnsignedLongReturnSetter.h │ │ ├── MKTUnsignedShortReturnSetter.h │ │ ├── MKTUnsignedLongLongReturnSetter.h │ │ ├── MKTIntReturnSetter.m │ │ ├── MKTBoolReturnSetter.m │ │ ├── MKTCharReturnSetter.m │ │ ├── MKTLongReturnSetter.m │ │ ├── MKTFloatReturnSetter.m │ │ ├── MKTShortReturnSetter.m │ │ ├── MKTClassReturnSetter.m │ │ ├── MKTDoubleReturnSetter.m │ │ ├── MKTObjectReturnSetter.m │ │ ├── MKTLongLongReturnSetter.m │ │ ├── MKTUnsignedIntReturnSetter.m │ │ ├── MKTUnsignedCharReturnSetter.m │ │ ├── MKTUnsignedLongReturnSetter.m │ │ ├── MKTUnsignedShortReturnSetter.m │ │ ├── MKTUnsignedLongLongReturnSetter.m │ │ ├── MKTStructReturnSetter.m │ │ ├── MKTReturnValueSetter.h │ │ ├── MKTReturnValueSetter.m │ │ └── MKTReturnValueSetterChain.m │ ├── Mocking │ ├── MKTObjectMock.h │ ├── MKTBaseMockObject.h │ ├── MKTDynamicProperties.h │ ├── MKTSingletonSwizzler.h │ ├── MKTProtocolMock.h │ ├── MKTClassObjectMock.h │ ├── MKTObjectAndProtocolMock.h │ ├── MKTObjectMock.m │ ├── MKTClassObjectMock.m │ ├── MKTObjectAndProtocolMock.m │ └── MKTProtocolMock.m │ ├── Verifying │ ├── MKTExactTimes.h │ ├── MKTAtMostTimes.h │ ├── MKTAtLeastTimes.h │ ├── MKTVerificationMode.h │ ├── MKTNumberOfInvocationsChecker.h │ ├── MKTAtMostNumberOfInvocationsChecker.h │ ├── MKTAtLeastNumberOfInvocationsChecker.h │ ├── MKTMissingInvocationChecker.h │ ├── MKTInvocationsChecker.h │ ├── MKTVerificationData.h │ ├── MKTVerificationData.m │ ├── MKTAtLeastNumberOfInvocationsChecker.m │ ├── MKTAtMostNumberOfInvocationsChecker.m │ ├── MKTAtMostTimes.m │ ├── MKTAtLeastTimes.m │ ├── MKTNumberOfInvocationsChecker.m │ └── MKTExactTimes.m │ └── Core │ ├── MKTMockitoCore.h │ ├── MKTTestLocation.h │ ├── MKTTestLocation.m │ ├── MKTMockingProgress.h │ ├── MKTMockitoCore.m │ ├── MKTNonObjectArgumentMatching.h │ └── MKTMockingProgress.m ├── mdsnippets.json ├── Examples ├── MacExample-CocoaPods │ ├── Example │ │ ├── Example.m │ │ └── Example.h │ ├── Podfile │ ├── README.md │ └── ExampleTests │ │ ├── ExampleTests-Info.plist │ │ └── ExampleTests.m ├── MacExample-Framework │ ├── Example │ │ ├── Example.m │ │ └── Example.h │ ├── README.md │ └── ExampleTests │ │ ├── ExampleTests-Info.plist │ │ └── ExampleTests.m ├── iOSExample-Cocoapods │ ├── Example │ │ ├── Example.m │ │ └── Example.h │ ├── Podfile │ ├── README.md │ └── ExampleTests │ │ ├── ExampleTests-Info.plist │ │ └── ExampleTests.m ├── iOSExample-Framework │ ├── Example │ │ ├── Example.m │ │ └── Example.h │ ├── README.md │ └── ExampleTests │ │ ├── ExampleTests-Info.plist │ │ └── ExampleTests.m └── MacExample-SwiftPackageManager │ ├── README.md │ ├── Sources │ └── Example │ │ ├── Example.m │ │ └── Example.h │ ├── Package.swift │ └── Tests │ └── ExampleTests │ └── ExampleTests.m ├── Frameworks ├── README.md └── gethamcrest ├── merge_dependabot.sh ├── .github ├── dependabot.yml └── workflows │ └── updateMarkdown.yml ├── .slather.yml ├── .gitignore ├── Cartfile.project ├── Tests └── OCMockitoTests │ ├── FakeLocation.h │ ├── FakeLocation.m │ ├── MockTestCase.m │ ├── MockInvocationsFinder.h │ ├── ArgumentCaptorTests.m │ ├── MockInvocationsFinder.m │ ├── StubClassTests.m │ ├── StubbingCopyTests.m │ ├── VerifyClassObjectTests.m │ ├── VerifyCountNeverTests.m │ ├── MockTestCase.h │ ├── VerifyObjectAndProtocolTests.m │ ├── MKTClassObjectMockTests.m │ ├── StubSingletonProgrammerErrorTests.m │ ├── VerifyCountAtMostTimesTests.m │ ├── NSInvocation+OCMockitoTests.m │ ├── BlockMatchingTests.m │ ├── VerifyProgrammerErrorTests.m │ ├── DummyObject.h │ ├── VerifyAndStubTests.m │ ├── VerifyProtocolTests.m │ ├── MKTParseCallStackTests.m │ └── VerifyCountAtLeastTimesTests.m ├── Resources ├── Tests-Info.plist ├── OCMockito-Info.plist ├── MakeDistribution.sh └── XcodeTargets.xcconfig ├── LICENSE.txt ├── Package.swift ├── OCMockito.podspec └── OCMockito.xcodeproj └── xcshareddata └── xcschemes └── OCMockito.xcscheme /Cartfile: -------------------------------------------------------------------------------- 1 | github "hamcrest/OCHamcrest" ~> 9.1.1 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'slather' 4 | -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/OCMockito.h: -------------------------------------------------------------------------------- 1 | ../../Core/OCMockito.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTObjectMock.h: -------------------------------------------------------------------------------- 1 | ../../Mocking/MKTObjectMock.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTBaseMockObject.h: -------------------------------------------------------------------------------- 1 | ../../Mocking/MKTBaseMockObject.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTProtocolMock.h: -------------------------------------------------------------------------------- 1 | ../../Mocking/MKTProtocolMock.h -------------------------------------------------------------------------------- /mdsnippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "Convention": "InPlaceOverwrite", 3 | "TocLevel": 5 4 | } 5 | -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTClassObjectMock.h: -------------------------------------------------------------------------------- 1 | ../../Mocking/MKTClassObjectMock.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTOngoingStubbing.h: -------------------------------------------------------------------------------- 1 | ../../Stubbing/MKTOngoingStubbing.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTObjectAndProtocolMock.h: -------------------------------------------------------------------------------- 1 | ../../Mocking/MKTObjectAndProtocolMock.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/NSInvocation+OCMockito.h: -------------------------------------------------------------------------------- 1 | ../../Invocation/NSInvocation+OCMockito.h -------------------------------------------------------------------------------- /Sources/OCMockito/include/OCMockito/MKTNonObjectArgumentMatching.h: -------------------------------------------------------------------------------- 1 | ../../Core/MKTNonObjectArgumentMatching.h -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/Example/Example.m: -------------------------------------------------------------------------------- 1 | #import "Example.h" 2 | 3 | @implementation Example 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/MacExample-Framework/Example/Example.m: -------------------------------------------------------------------------------- 1 | #import "Example.h" 2 | 3 | @implementation Example 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/Example/Example.m: -------------------------------------------------------------------------------- 1 | #import "Example.h" 2 | 3 | @implementation Example 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/iOSExample-Framework/Example/Example.m: -------------------------------------------------------------------------------- 1 | #import "Example.h" 2 | 3 | @implementation Example 4 | @end 5 | -------------------------------------------------------------------------------- /Frameworks/README.md: -------------------------------------------------------------------------------- 1 | To build OCMockito without CocoaPods, execute the following script: 2 | - gethamcrest 3 | -------------------------------------------------------------------------------- /Examples/MacExample-SwiftPackageManager/README.md: -------------------------------------------------------------------------------- 1 | `swift test` to run unit tests. Try changing some tests to fail. 2 | -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/Example/Example.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Example : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/MacExample-Framework/Example/Example.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Example : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/Example/Example.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Example : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/iOSExample-Framework/Example/Example.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Example : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/MacExample-SwiftPackageManager/Sources/Example/Example.m: -------------------------------------------------------------------------------- 1 | #import "Example.h" 2 | 3 | @implementation Example 4 | @end 5 | -------------------------------------------------------------------------------- /Examples/MacExample-SwiftPackageManager/Sources/Example/Example.h: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Example : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /merge_dependabot.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | GH_TOKEN="$GITHUB_TOKEN" gh pr merge --auto --rebase "$PR_URL" 5 | -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/Podfile: -------------------------------------------------------------------------------- 1 | target 'ExampleTests' do 2 | inherit! :search_paths 3 | use_frameworks! 4 | pod 'OCMockito', '~> 7.0' 5 | end 6 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/Podfile: -------------------------------------------------------------------------------- 1 | target 'ExampleTests' do 2 | inherit! :search_paths 3 | use_frameworks! 4 | pod 'OCMockito', '~> 7.0' 5 | end 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.slather.yml: -------------------------------------------------------------------------------- 1 | ci_service: github 2 | coverage_service: coveralls 3 | xcodeproj: ./OCMockito.xcodeproj 4 | scheme: OCMockito 5 | ignore: 6 | - Frameworks/* 7 | - Sources/*/ThirdParty/* 8 | - Tests/* 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gcda 2 | *.gcno 3 | .DS_Store 4 | .idea/ 5 | build/ 6 | *.pbxuser 7 | *.perspectivev3 8 | project.xcworkspace/ 9 | xcuserdata/ 10 | OCHamcrest* 11 | compile_commands.json 12 | /Carthage 13 | .swiftpm 14 | **/Package.resolved 15 | .build -------------------------------------------------------------------------------- /Cartfile.project: -------------------------------------------------------------------------------- 1 | OCMockito: 2 | project: OCMockito.xcodeproj 3 | sdks: 4 | - macosx 5 | - iphonesimulator 6 | - iphoneos 7 | - appletvos 8 | - appletvsimulator 9 | - watchsimulator 10 | - watchos 11 | - xros 12 | - xrsimulator 13 | -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/README.md: -------------------------------------------------------------------------------- 1 | To set up this example: 2 | 3 | 1. Terminal: sudo install cocoapods 4 | 2. Terminal: pod install 5 | 3. Open the generated Example.xcworkspace 6 | 7 | Then command-U to run unit tests. Try changing one of the tests to fail. 8 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/README.md: -------------------------------------------------------------------------------- 1 | To set up this example: 2 | 3 | 1. Terminal: sudo install cocoapods 4 | 2. Terminal: pod install 5 | 3. Open the generated Example.xcworkspace 6 | 7 | Then command-U to run unit tests. Try changing one of the tests to fail. 8 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/FakeLocation.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | @import Foundation; 6 | 7 | 8 | @interface FakeLocation : NSObject 9 | @end 10 | -------------------------------------------------------------------------------- /Examples/MacExample-Framework/README.md: -------------------------------------------------------------------------------- 1 | To set up this example, open Example.xcodeproj: 2 | 3 | Drag OCMockito.xcframework and OCHamcrest.xcframework into the project, specifying: 4 | * "Copy items into destination group's folder" 5 | * Add to targets: ExampleTests 6 | 7 | Then command-U to run unit tests. Try changing one of the tests to fail. 8 | -------------------------------------------------------------------------------- /Examples/iOSExample-Framework/README.md: -------------------------------------------------------------------------------- 1 | To set up this example, open Example.xcodeproj: 2 | 3 | Drag OCMockito.xcframework and OCHamcrest.xcframework into the project, specifying: 4 | * "Copy items into destination group's folder" 5 | * Add to targets: ExampleTests 6 | 7 | Then command-U to run unit tests. Try changing one of the tests to fail. 8 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/FakeLocation.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "FakeLocation.h" 6 | 7 | 8 | @implementation FakeLocation 9 | 10 | - (NSString *)description 11 | { 12 | return @"FAKE CALL STACK"; 13 | } 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTParseCallStack.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTCallStackElement; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | NSArray *MKTParseCallStack(NSArray *callStackSymbols); 13 | 14 | NS_ASSUME_NONNULL_END 15 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTFilterCallStack.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTCallStackElement; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | NSArray *MKTFilterCallStack(NSArray *callStackSymbols); 13 | 14 | NS_ASSUME_NONNULL_END 15 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTLocation.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTLocation : NSObject 11 | 12 | - (instancetype)init; 13 | - (instancetype)initWithCallStack:(NSArray *)callStack NS_DESIGNATED_INITIALIZER; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTStubbedInvocationMatcher.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationMatcher.h" 6 | #import "MKTAnswer.h" 7 | 8 | 9 | NS_ASSUME_NONNULL_BEGIN 10 | 11 | @interface MKTStubbedInvocationMatcher : MKTInvocationMatcher 12 | 13 | - (void)addAnswer:(id )answer; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTArgumentGetterChain.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTArgumentGetter; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | /*! 13 | * @abstract Returns chain of argument getters. 14 | */ 15 | FOUNDATION_EXPORT MKTArgumentGetter *MKTArgumentGetterChain(void); 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTReturnValueSetterChain.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTReturnValueSetter; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | /*! 13 | * @abstract Returns chain of return value handlers. 14 | */ 15 | FOUNDATION_EXPORT MKTReturnValueSetter *MKTReturnValueSetterChain(void); 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Frameworks/gethamcrest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | OCH_VERSION=9.1.1 3 | OCH=OCHamcrest-${OCH_VERSION} 4 | OCH_ZIP=${OCH}.zip 5 | 6 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7 | pushd "$DIR" 8 | 9 | curl -L https://github.com/hamcrest/OCHamcrest/releases/download/v${OCH_VERSION}/${OCH_ZIP} > ${OCH_ZIP} 10 | OUT=$? 11 | if [ "${OUT}" -ne "0" ]; then 12 | echo OCHamcrest download failed 13 | exit ${OUT} 14 | fi 15 | 16 | rm -rf ${OCH} 17 | unzip ${OCH_ZIP} 18 | rm ${OCH_ZIP} 19 | 20 | mkdir -p ../Carthage/Build/ 21 | mv ${OCH}/OCHamcrest.xcframework ../Carthage/Build 22 | 23 | popd 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTObjectMock.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Mock object of a given class. 12 | */ 13 | @interface MKTObjectMock : MKTBaseMockObject 14 | 15 | - (instancetype)initWithClass:(Class)aClass NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTBaseMockObject.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | 9 | NS_ASSUME_NONNULL_BEGIN 10 | 11 | @interface MKTBaseMockObject : NSProxy 12 | 13 | + (BOOL)isMockObject:(nullable id)object; 14 | 15 | - (instancetype)init; 16 | - (void)stopMocking; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTDynamicProperties.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTDynamicProperties : NSObject 11 | 12 | - (instancetype)initWithClass:(Class)aClass NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)init NS_UNAVAILABLE; 14 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector; 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTReturnsValue.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTAnswer.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Method answer that returns a value. 12 | */ 13 | @interface MKTReturnsValue : NSObject 14 | 15 | - (instancetype)initWithValue:(nullable id)value NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTExactTimes.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import "MKTVerificationMode.h" 7 | 8 | 9 | NS_ASSUME_NONNULL_BEGIN 10 | 11 | @interface MKTExactTimes : NSObject 12 | 13 | - (instancetype)initWithCount:(NSUInteger)wantedNumberOfInvocations NS_DESIGNATED_INITIALIZER; 14 | - (instancetype)init NS_UNAVAILABLE; 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTExecutesBlock.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTAnswer.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Method answer that executes a block. 12 | */ 13 | @interface MKTExecutesBlock : NSObject 14 | 15 | - (instancetype)initWithBlock:(id (^)(NSInvocation *))block NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTThrowsException.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTAnswer.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Method answer that throws an exception. 12 | */ 13 | @interface MKTThrowsException : NSObject 14 | 15 | - (instancetype)initWithException:(NSException *)exception NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtMostTimes.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Emile Cantin 5 | 6 | #import 7 | #import "MKTVerificationMode.h" 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface MKTAtMostTimes : NSObject 13 | 14 | - (instancetype)initWithMaximumCount:(NSUInteger)maxNumberOfInvocations NS_DESIGNATED_INITIALIZER; 15 | - (instancetype)init NS_UNAVAILABLE; 16 | 17 | @end 18 | 19 | NS_ASSUME_NONNULL_END 20 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtLeastTimes.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Markus Gasser 5 | 6 | #import 7 | #import "MKTVerificationMode.h" 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface MKTAtLeastTimes : NSObject 13 | 14 | - (instancetype)initWithMinimumCount:(NSUInteger)minNumberOfInvocations NS_DESIGNATED_INITIALIZER; 15 | - (instancetype)init NS_UNAVAILABLE; 16 | 17 | @end 18 | 19 | NS_ASSUME_NONNULL_END 20 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTBoolArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTBoolArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTCharArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTCharArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTIntArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTIntArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTLongArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTLongArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTClassArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTClassArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTDoubleArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTDoubleArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTFloatArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTFloatArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTLongLongArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTLongLongArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | @end 15 | 16 | NS_ASSUME_NONNULL_END 17 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTObjectArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTObjectArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTShortArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTShortArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTStructArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTStructArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTPointerArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTPointerArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTSelectorArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTSelectorArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTIntReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTIntReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTCallStackElement.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTCallStackElement : NSObject 11 | 12 | @property (nonatomic, copy, readonly) NSString *moduleName; 13 | @property (nonatomic, copy, readonly) NSString *instruction; 14 | 15 | - (instancetype)initWithSymbols:(NSString *)element NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedIntArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedIntArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTBoolReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTBoolReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTCharReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTCharReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTClassReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTClassReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTDoubleReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTDoubleReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTFloatReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTFloatReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTLongReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTLongReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTObjectReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTObjectReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTShortReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTShortReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedCharArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedCharArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedLongArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedLongArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedShortArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedShortArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTLongLongReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTLongLongReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedLongLongArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedLongLongArgumentGetter : MKTArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTStructReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTStructReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | 19 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedIntReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedIntReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedCharReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedCharReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedLongReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedLongReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedShortReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedShortReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedLongLongReturnSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @interface MKTUnsignedLongLongReturnSetter : MKTReturnValueSetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 13 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_UNAVAILABLE; 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | 19 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTReturnsValue.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnsValue.h" 6 | 7 | 8 | @interface MKTReturnsValue () 9 | @property (nullable, nonatomic, strong, readonly) id value; 10 | @end 11 | 12 | @implementation MKTReturnsValue 13 | 14 | - (instancetype)initWithValue:(nullable id)value 15 | { 16 | self = [super init]; 17 | if (self) 18 | _value = value; 19 | return self; 20 | } 21 | 22 | - (nullable id)answerInvocation:(NSInvocation *)invocation 23 | { 24 | return self.value; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTVerificationMode.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import "MKTTestLocation.h" 7 | 8 | @class MKTVerificationData; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /*! 14 | * @abstract Allows verifying that certain behavior happened at least once / exact number of times / 15 | * never. 16 | */ 17 | @protocol MKTVerificationMode 18 | 19 | - (void)verifyData:(MKTVerificationData *)data testLocation:(MKTTestLocation)testLocation; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTSingletonSwizzler.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Igor Sales 5 | 6 | #import 7 | 8 | @class MKTClassObjectMock; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTSingletonSwizzler : NSObject 14 | 15 | - (instancetype)initWithMock:(MKTClassObjectMock *)classMock NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)init NS_UNAVAILABLE; 17 | - (void)swizzleSingletonAtSelector:(SEL)singletonSelector; 18 | - (void)unswizzleSingletonsForMock; 19 | 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTIntReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTIntReturnSetter.h" 6 | 7 | 8 | @implementation MKTIntReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(int) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | int value = [returnValue intValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTBoolReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTBoolReturnSetter.h" 6 | 7 | 8 | @implementation MKTBoolReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(BOOL) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | BOOL value = [returnValue boolValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTCharReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTCharReturnSetter.h" 6 | 7 | 8 | @implementation MKTCharReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(char) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | char value = [returnValue charValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTLongReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTLongReturnSetter.h" 6 | 7 | 8 | @implementation MKTLongReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(long) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | long value = [returnValue longValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTFloatReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTFloatReturnSetter.h" 6 | 7 | 8 | @implementation MKTFloatReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(float) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | float value = [returnValue floatValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTShortReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTShortReturnSetter.h" 6 | 7 | 8 | @implementation MKTShortReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(short) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | short value = [returnValue shortValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTClassReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTClassReturnSetter.h" 6 | 7 | 8 | @implementation MKTClassReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(Class) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | __unsafe_unretained Class value = returnValue; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTDoubleReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTDoubleReturnSetter.h" 6 | 7 | 8 | @implementation MKTDoubleReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(double) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | double value = [returnValue doubleValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTObjectReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTObjectReturnSetter.h" 6 | 7 | 8 | @implementation MKTObjectReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(id) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | __unsafe_unretained id value = returnValue; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTParseCallStack.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTParseCallStack.h" 6 | 7 | #import "MKTCallStackElement.h" 8 | 9 | 10 | NSArray *MKTParseCallStack(NSArray *callStackSymbols) 11 | { 12 | NSMutableArray *result = [[NSMutableArray alloc] init]; 13 | for (NSString *rawElement in callStackSymbols) 14 | { 15 | MKTCallStackElement *element = [[MKTCallStackElement alloc] initWithSymbols:rawElement]; 16 | [result addObject:element]; 17 | } 18 | return result; 19 | } 20 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTIntArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTIntArgumentGetter.h" 6 | 7 | @implementation MKTIntArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(int) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | int arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTExecutesBlock.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTExecutesBlock.h" 6 | 7 | 8 | @interface MKTExecutesBlock () 9 | @property (nonatomic, copy, readonly) id (^block)(NSInvocation *); 10 | @end 11 | 12 | @implementation MKTExecutesBlock 13 | 14 | - (instancetype)initWithBlock:(id (^)(NSInvocation *))block 15 | { 16 | self = [super init]; 17 | if (self) 18 | _block = [block copy]; 19 | return self; 20 | } 21 | 22 | - (nullable id)answerInvocation:(NSInvocation *)invocation 23 | { 24 | return self.block(invocation); 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTBoolArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTBoolArgumentGetter.h" 6 | 7 | @implementation MKTBoolArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(BOOL) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | BOOL arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTCharArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTCharArgumentGetter.h" 6 | 7 | @implementation MKTCharArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(char) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | char arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTLongArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTLongArgumentGetter.h" 6 | 7 | @implementation MKTLongArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(long) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | long arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTLongLongReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTLongLongReturnSetter.h" 6 | 7 | 8 | @implementation MKTLongLongReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(long long) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | long long value = [returnValue longLongValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTFloatArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTFloatArgumentGetter.h" 6 | 7 | @implementation MKTFloatArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(float) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | float arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTShortArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTShortArgumentGetter.h" 6 | 7 | @implementation MKTShortArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(short) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | short arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTProtocolMock.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Mock object implementing a given protocol. 12 | */ 13 | @interface MKTProtocolMock : MKTBaseMockObject 14 | 15 | @property (nonatomic, strong, readonly) Protocol *mockedProtocol; 16 | 17 | - (instancetype)initWithProtocol:(Protocol *)aProtocol 18 | includeOptionalMethods:(BOOL)includeOptionalMethods NS_DESIGNATED_INITIALIZER; 19 | - (instancetype)init NS_UNAVAILABLE; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTAnswer.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Specifies an action that is executed and a return value that is returned when you 12 | * interact with the mock. 13 | */ 14 | @protocol MKTAnswer 15 | 16 | /*! 17 | * @abstract Answer a particular invocation. 18 | * @param invocation Method invocation to answer. 19 | * @return The value to be returned. 20 | */ 21 | - (nullable id)answerInvocation:(NSInvocation *)invocation; 22 | 23 | @end 24 | 25 | NS_ASSUME_NONNULL_END 26 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTDoubleArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTDoubleArgumentGetter.h" 6 | 7 | @implementation MKTDoubleArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(double) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | double arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTThrowsException.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTThrowsException.h" 6 | 7 | 8 | @interface MKTThrowsException () 9 | @property (nonatomic, strong, readonly) NSException *exception; 10 | @end 11 | 12 | @implementation MKTThrowsException 13 | 14 | - (instancetype)initWithException:(NSException *)exception 15 | { 16 | self = [super init]; 17 | if (self) 18 | _exception = exception; 19 | return self; 20 | } 21 | 22 | - (nullable id)answerInvocation:(NSInvocation *)invocation 23 | { 24 | [self.exception raise]; 25 | return nil; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Resources/Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTLongLongArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTLongLongArgumentGetter.h" 6 | 7 | @implementation MKTLongLongArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(long long) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | long long arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedIntReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedIntReturnSetter.h" 6 | 7 | 8 | @implementation MKTUnsignedIntReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(unsigned int) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | unsigned int value = [returnValue unsignedIntValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTClassObjectMock.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by David Hart 5 | 6 | #import 7 | 8 | 9 | NS_ASSUME_NONNULL_BEGIN 10 | 11 | /*! 12 | * @abstract Mock object of a given class object. 13 | */ 14 | @interface MKTClassObjectMock : MKTBaseMockObject 15 | 16 | @property (nonatomic, strong, readonly) Class mockedClass; 17 | 18 | - (instancetype)initWithClass:(Class)aClass NS_DESIGNATED_INITIALIZER; 19 | - (instancetype)init NS_UNAVAILABLE; 20 | - (void)swizzleSingletonAtSelector:(SEL)singletonSelector; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTClassArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTClassArgumentGetter.h" 6 | 7 | @implementation MKTClassArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(Class) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | __unsafe_unretained Class arg = nil; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return arg; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedCharReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedCharReturnSetter.h" 6 | 7 | 8 | @implementation MKTUnsignedCharReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(unsigned char) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | unsigned char value = [returnValue unsignedCharValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedLongReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedLongReturnSetter.h" 6 | 7 | 8 | @implementation MKTUnsignedLongReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(unsigned long) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | unsigned long value = [returnValue unsignedLongValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedShortReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedShortReturnSetter.h" 6 | 7 | 8 | @implementation MKTUnsignedShortReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(unsigned short) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | unsigned short value = [returnValue unsignedShortValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTMockitoCore.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | #import "MKTTestLocation.h" 8 | 9 | @class MKTObjectMock; 10 | @class MKTOngoingStubbing; 11 | @protocol MKTVerificationMode; 12 | 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | @interface MKTMockitoCore : NSObject 17 | 18 | + (instancetype)sharedCore; 19 | 20 | - (MKTOngoingStubbing *)stubAtLocation:(MKTTestLocation)location; 21 | 22 | - (id)verifyMock:(MKTObjectMock *)mock 23 | withMode:(id )mode 24 | atLocation:(MKTTestLocation)location; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedIntArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedIntArgumentGetter.h" 6 | 7 | @implementation MKTUnsignedIntArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(unsigned int) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | unsigned int arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTPrinter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTPrinter : NSObject 14 | 15 | - (NSString *)printMatcher:(MKTInvocationMatcher *)matcher; 16 | - (NSString *)printInvocation:(MKTInvocation *)invocation; 17 | - (NSString *)printMismatchOf:(MKTInvocation *)invocation 18 | expectation:(MKTInvocationMatcher *)expectation; 19 | 20 | @end 21 | 22 | 23 | FOUNDATION_EXPORT NSString *MKTOrdinal(NSUInteger index); 24 | 25 | NS_ASSUME_NONNULL_END 26 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTPointerArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTPointerArgumentGetter.h" 6 | 7 | 8 | @implementation MKTPointerArgumentGetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 11 | { 12 | self = [super initWithType:@encode(void *) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 17 | { 18 | void *arg; 19 | [invocation getArgument:&arg atIndex:idx]; 20 | return [NSValue valueWithPointer:arg]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedCharArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedCharArgumentGetter.h" 6 | 7 | @implementation MKTUnsignedCharArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(unsigned char) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | unsigned char arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedLongArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedLongArgumentGetter.h" 6 | 7 | @implementation MKTUnsignedLongArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(unsigned long) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | unsigned long arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MockTestCase.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MockTestCase.h" 6 | 7 | 8 | @implementation MockTestCase 9 | 10 | - (void)failWithException:(NSException *)exception 11 | { 12 | ++_failureCount; 13 | [self setFailureException:exception]; 14 | } 15 | 16 | - (void)recordFailureWithDescription:(NSString *)description 17 | inFile:(NSString *)filename 18 | atLine:(NSUInteger)lineNumber 19 | expected:(BOOL)expected 20 | { 21 | self.failureCount += 1; 22 | self.failureDescription = description; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTObjectArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTObjectArgumentGetter.h" 6 | 7 | @implementation MKTObjectArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(id) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | __unsafe_unretained id arg = nil; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return arg ? arg : [NSNull null]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedShortArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedShortArgumentGetter.h" 6 | 7 | @implementation MKTUnsignedShortArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(unsigned short) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | unsigned short arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MockInvocationsFinder.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTMatchingInvocationsFinder.h" 6 | 7 | 8 | @interface MockInvocationsFinder : MKTMatchingInvocationsFinder 9 | 10 | @property (nonatomic, copy) NSArray *capturedInvocations; 11 | @property (nonatomic, strong) MKTInvocationMatcher *capturedWanted; 12 | @property (nonatomic, assign) NSUInteger stubbedCount; 13 | @property (nonatomic, assign) NSUInteger capturedInvocationIndex; 14 | @property (nonatomic, strong) MKTLocation *stubbedLocationOfInvocationAtIndex; 15 | @property (nonatomic, strong) MKTLocation *stubbedLocationOfLastInvocation; 16 | @end 17 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTUnsignedLongLongReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedLongLongReturnSetter.h" 6 | 7 | 8 | @implementation MKTUnsignedLongLongReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:@encode(unsigned long long) successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | unsigned long long value = [returnValue unsignedLongLongValue]; 19 | [invocation setReturnValue:&value]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTSelectorArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTSelectorArgumentGetter.h" 6 | 7 | @implementation MKTSelectorArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(SEL) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | SEL arg = nil; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return arg ? NSStringFromSelector(arg) : [NSNull null]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/ExampleTests/ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/MacExample-Framework/ExampleTests/ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/ExampleTests/ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/iOSExample-Framework/ExampleTests/ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTUnsignedLongLongArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTUnsignedLongLongArgumentGetter.h" 6 | 7 | @implementation MKTUnsignedLongLongArgumentGetter 8 | 9 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 10 | { 11 | self = [super initWithType:@encode(unsigned long long) successor:successor]; 12 | return self; 13 | } 14 | 15 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 16 | { 17 | unsigned long long arg; 18 | [invocation getArgument:&arg atIndex:idx]; 19 | return @(arg); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTObjectAndProtocolMock.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Kevin Lundberg 5 | 6 | #import 7 | 8 | 9 | NS_ASSUME_NONNULL_BEGIN 10 | 11 | /*! 12 | * @abstract Mock object of a given class that also implements a given protocol. 13 | */ 14 | @interface MKTObjectAndProtocolMock : MKTProtocolMock 15 | 16 | - (instancetype)initWithClass:(Class)aClass protocol:(Protocol *)protocol NS_DESIGNATED_INITIALIZER; 17 | - (instancetype)initWithProtocol:(Protocol *)aProtocol 18 | includeOptionalMethods:(BOOL)includeOptionalMethods NS_UNAVAILABLE; 19 | 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTInvocation.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocation.h" 6 | 7 | #import "MKTLocation.h" 8 | 9 | 10 | @implementation MKTInvocation 11 | 12 | - (instancetype)initWithInvocation:(NSInvocation *)invocation 13 | { 14 | return [self initWithInvocation:invocation 15 | location:[[MKTLocation alloc] init]]; 16 | } 17 | 18 | - (instancetype)initWithInvocation:(NSInvocation *)invocation location:(MKTLocation *)location 19 | { 20 | self = [super init]; 21 | if (self) { 22 | _invocation = invocation; 23 | _location = location; 24 | } 25 | return self; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTInvocation.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTLocation; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface MKTInvocation : NSObject 13 | 14 | @property (nonatomic, strong, readonly) NSInvocation *invocation; 15 | @property (nonatomic, strong, readonly) MKTLocation *location; 16 | @property (nonatomic, assign) BOOL verified; 17 | 18 | - (instancetype)initWithInvocation:(NSInvocation *)invocation; 19 | - (instancetype)initWithInvocation:(NSInvocation *)invocation location:(MKTLocation *)location NS_DESIGNATED_INITIALIZER; 20 | - (instancetype)init NS_UNAVAILABLE; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTMatchingInvocationsFinder.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | @class MKTLocation; 10 | 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MKTMatchingInvocationsFinder : NSObject 15 | 16 | @property (nonatomic, assign, readonly) NSUInteger count; 17 | 18 | - (void)findInvocationsInList:(NSArray *)invocations matching:(MKTInvocationMatcher *)wanted; 19 | - (MKTLocation *)locationOfInvocationAtIndex:(NSUInteger)index; 20 | - (MKTLocation *)locationOfLastInvocation; 21 | - (void)markInvocationsAsVerified; 22 | 23 | @end 24 | 25 | NS_ASSUME_NONNULL_END 26 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTNumberOfInvocationsChecker.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationsChecker.h" 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTNumberOfInvocationsChecker : MKTInvocationsChecker 14 | 15 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)initWithWantedDescription:(NSString *)wantedDescription NS_UNAVAILABLE; 17 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 18 | wanted:(MKTInvocationMatcher *)wanted 19 | wantedCount:(NSUInteger)wantedCount; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtMostNumberOfInvocationsChecker.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationsChecker.h" 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTAtMostNumberOfInvocationsChecker : MKTInvocationsChecker 14 | 15 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)initWithWantedDescription:(NSString *)wantedDescription NS_UNAVAILABLE; 17 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 18 | wanted:(MKTInvocationMatcher *)wanted 19 | wantedCount:(NSUInteger)wantedCount; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtLeastNumberOfInvocationsChecker.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationsChecker.h" 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTAtLeastNumberOfInvocationsChecker : MKTInvocationsChecker 14 | 15 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)initWithWantedDescription:(NSString *)wantedDescription NS_UNAVAILABLE; 17 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 18 | wanted:(MKTInvocationMatcher *)wanted 19 | wantedCount:(NSUInteger)wantedCount; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTMissingInvocationChecker.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationsChecker.h" 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MKTMissingInvocationChecker : MKTInvocationsChecker 14 | 15 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 16 | - (instancetype)initWithWantedDescription:(NSString *)wantedDescription NS_UNAVAILABLE; 17 | - (nullable NSString *)checkInvocations:(NSArray *)invocations wanted:(MKTInvocationMatcher *)wanted; 18 | 19 | @end 20 | 21 | 22 | MKTInvocation *MKTFindSimilarInvocation(NSArray *invocations, MKTInvocationMatcher *wanted); 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTStructReturnSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTStructReturnSetter.h" 6 | 7 | 8 | @implementation MKTStructReturnSetter 9 | 10 | - (instancetype)initWithSuccessor:(nullable MKTReturnValueSetter *)successor 11 | { 12 | self = [super initWithType:"{" successor:successor]; 13 | return self; 14 | } 15 | 16 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation 17 | { 18 | NSMethodSignature *methodSignature = [invocation methodSignature]; 19 | NSMutableData *value = [NSMutableData dataWithLength:[methodSignature methodReturnLength]]; 20 | [returnValue getValue:[value mutableBytes]]; 21 | [invocation setReturnValue:[value mutableBytes]]; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/ArgumentCaptorTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | @import XCTest; 8 | 9 | 10 | @interface ArgumentCaptorTests : XCTestCase 11 | @end 12 | 13 | @implementation ArgumentCaptorTests 14 | 15 | - (void)testExactTimes_CapturingAllValues_ShouldGiveActualArgumentsWithoutDoubling 16 | { 17 | NSString *aMock = mock([NSString class]); 18 | HCArgumentCaptor *captor = [[HCArgumentCaptor alloc] init]; 19 | 20 | [aMock stringByAppendingString:@"FOO"]; 21 | [aMock stringByAppendingString:@"BAR"]; 22 | [verifyCount(aMock, times(2)) stringByAppendingString:(id)captor]; 23 | 24 | assertThat(captor.allValues, containsIn(@[ @"FOO", @"BAR" ])); 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /.github/workflows/updateMarkdown.yml: -------------------------------------------------------------------------------- 1 | name: Update markdown snippets 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | update-markdown-snippets: 8 | runs-on: windows-latest 9 | steps: 10 | - uses: actions/checkout@v6 11 | - name: Run MarkdownSnippets 12 | run: | 13 | dotnet tool install --global MarkdownSnippets.Tool 14 | mdsnippets ${GITHUB_WORKSPACE} 15 | 16 | shell: bash 17 | - name: Push changes 18 | run: | 19 | git config --local user.email "action@github.com" 20 | git config --local user.name "GitHub Action" 21 | git commit -m ". d Update markdown snippets" -a || echo "nothing to commit" 22 | remote="https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git" 23 | branch="${GITHUB_REF:11}" 24 | git push "${remote}" ${branch} || echo "nothing to push" 25 | shell: bash 26 | 27 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MockInvocationsFinder.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MockInvocationsFinder.h" 6 | 7 | 8 | @implementation MockInvocationsFinder 9 | 10 | - (void)findInvocationsInList:(NSArray *)invocations matching:(MKTInvocationMatcher *)wanted 11 | { 12 | self.capturedInvocations = invocations; 13 | self.capturedWanted = wanted; 14 | } 15 | 16 | - (NSUInteger)count 17 | { 18 | return self.stubbedCount; 19 | } 20 | 21 | - (MKTLocation *)locationOfInvocationAtIndex:(NSUInteger)index 22 | { 23 | self.capturedInvocationIndex = index; 24 | return self.stubbedLocationOfInvocationAtIndex; 25 | } 26 | 27 | - (MKTLocation *)locationOfLastInvocation 28 | { 29 | return self.stubbedLocationOfLastInvocation; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTTestLocation.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | typedef struct 11 | { 12 | __unsafe_unretained id testCase; 13 | const char *fileName; 14 | int lineNumber; 15 | } MKTTestLocation; 16 | 17 | 18 | static inline MKTTestLocation MKTTestLocationMake(id test, const char *file, int line) 19 | { 20 | MKTTestLocation location; 21 | location.testCase = test; 22 | location.fileName = file; 23 | location.lineNumber = line; 24 | return location; 25 | } 26 | 27 | void MKTFailTest(id testCase, const char *fileName, int lineNumber, NSString *description); 28 | void MKTFailTestLocation(MKTTestLocation testLocation, NSString *description); 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTInvocationsChecker.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTMatchingInvocationsFinder; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface MKTInvocationsChecker : NSObject 13 | 14 | @property (nonatomic, strong) MKTMatchingInvocationsFinder *invocationsFinder; 15 | 16 | - (instancetype)initWithWantedDescription:(NSString *)wantedDescription NS_DESIGNATED_INITIALIZER; 17 | - (instancetype)init NS_UNAVAILABLE; 18 | - (NSString *)tooLittleActual:(NSUInteger)actualCount wantedCount:(NSUInteger)wantedCount; 19 | - (NSString *)tooManyActual:(NSUInteger)actualCount wantedCount:(NSUInteger)wantedCount; 20 | - (NSString *)neverWantedButActual:(NSUInteger)actualCount; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTVerificationData.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | #import "MKTTestLocation.h" 8 | 9 | @class MKTInvocation; 10 | @class MKTInvocationContainer; 11 | @class MKTInvocationMatcher; 12 | 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | @interface MKTVerificationData : NSObject 17 | 18 | @property (nonatomic, copy, readonly) NSArray *invocations; 19 | @property (nonatomic, strong, readonly) MKTInvocationMatcher *wanted; 20 | 21 | - (instancetype)initWithInvocationContainer:(MKTInvocationContainer *)invocationContainer 22 | invocationMatcher:(MKTInvocationMatcher *)wanted NS_DESIGNATED_INITIALIZER; 23 | - (instancetype)init NS_UNAVAILABLE; 24 | 25 | @end 26 | 27 | NS_ASSUME_NONNULL_END 28 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTInvocationContainer.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | @class MKTStubbedInvocationMatcher; 10 | @protocol HCMatcher; 11 | @protocol MKTAnswer; 12 | 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | @interface MKTInvocationContainer : NSObject 17 | 18 | @property (nonatomic, copy, readonly) NSArray *registeredInvocations; 19 | 20 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 21 | - (void)setInvocationForPotentialStubbing:(NSInvocation *)invocation; 22 | - (void)setMatcher:(id )matcher atIndex:(NSUInteger)argumentIndex; 23 | - (void)addAnswer:(id )answer; 24 | - (nullable MKTStubbedInvocationMatcher *)findAnswerFor:(NSInvocation *)invocation; 25 | - (BOOL)isStubbingCopyMethod; 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTStructArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTStructArgumentGetter.h" 6 | 7 | typedef struct {} MKTDummyStructure; 8 | 9 | 10 | @implementation MKTStructArgumentGetter 11 | 12 | - (instancetype)initWithSuccessor:(nullable MKTArgumentGetter *)successor 13 | { 14 | self = [super initWithType:@encode(MKTDummyStructure) successor:successor]; 15 | return self; 16 | } 17 | 18 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 19 | { 20 | NSUInteger structSize = 0; 21 | NSGetSizeAndAlignment(type, &structSize, NULL); 22 | void *structMem = calloc(1, structSize); 23 | [invocation getArgument:structMem atIndex:idx]; 24 | id arg = [NSData dataWithBytes:structMem length:structSize]; 25 | free(structMem); 26 | return arg; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTVerificationData.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTVerificationData.h" 6 | 7 | #import "MKTInvocationContainer.h" 8 | 9 | 10 | @interface MKTVerificationData () 11 | @property (nonatomic, strong, readonly) MKTInvocationContainer *invocationContainer; 12 | @end 13 | 14 | 15 | @implementation MKTVerificationData 16 | 17 | @dynamic invocations; 18 | 19 | - (instancetype)initWithInvocationContainer:(MKTInvocationContainer *)invocationContainer 20 | invocationMatcher:(MKTInvocationMatcher *)wanted 21 | { 22 | self = [super init]; 23 | if (self) 24 | { 25 | _invocationContainer = invocationContainer; 26 | _wanted = wanted; 27 | } 28 | return self; 29 | } 30 | 31 | - (NSArray *)invocations 32 | { 33 | return self.invocationContainer.registeredInvocations; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTLocation.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTLocation.h" 6 | 7 | #import "MKTFilterCallStack.h" 8 | #import "MKTParseCallStack.h" 9 | 10 | 11 | @interface MKTLocation () 12 | @property (nonatomic, strong, readonly) NSArray *callStack; // strong not copy, for speed 13 | @end 14 | 15 | @implementation MKTLocation 16 | 17 | - (instancetype)init 18 | { 19 | self = [self initWithCallStack:[NSThread callStackSymbols]]; 20 | return self; 21 | } 22 | 23 | - (instancetype)initWithCallStack:(NSArray *)callStack 24 | { 25 | self = [super init]; 26 | if (self) 27 | _callStack = callStack; 28 | return self; 29 | } 30 | 31 | - (NSString *)description 32 | { 33 | NSArray *stack = MKTFilterCallStack(MKTParseCallStack(self.callStack)); 34 | return [stack componentsJoinedByString:@"\n"]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTInvocationMatcher.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | @protocol HCMatcher; 8 | 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface MKTInvocationMatcher : NSObject 13 | 14 | @property (nonatomic, strong, readonly) NSInvocation *expected; 15 | @property (nonatomic, assign, readonly) NSUInteger numberOfArguments; 16 | @property (nonatomic, copy, readonly) NSArray> *matchers; 17 | 18 | - (instancetype)init NS_DESIGNATED_INITIALIZER; 19 | - (void)setMatcher:(id )matcher atIndex:(NSUInteger)index; 20 | - (void)setExpectedInvocation:(NSInvocation *)expectedInvocation; 21 | - (BOOL)matches:(NSInvocation *)actual; 22 | - (void)stopArgumentCapture; 23 | - (void)enumerateMismatchesOf:(NSInvocation *)actual 24 | usingBlock:(void (^)(NSUInteger idx, NSString *description))block; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /Resources/OCMockito-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | NSHumanReadableCopyright 26 | Copyright © 2011 Jonathan M. Reid 27 | NSPrincipalClass 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/MacExample-SwiftPackageManager/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Example", 8 | products: [ 9 | .library( 10 | name: "Example", 11 | targets: ["Example"]), 12 | ], 13 | // begin-snippet: swiftpm-declare-dependencies 14 | dependencies: [ 15 | .package( 16 | url: "https://github.com/jonreid/OCMockito", 17 | .upToNextMajor(from: "7.0.0") 18 | ), 19 | ], 20 | // end-snippet 21 | targets: [ 22 | .target( 23 | name: "Example", 24 | dependencies: [], 25 | publicHeadersPath: "./" 26 | ), 27 | // begin-snippet: swiftpm-use-dependencies 28 | .testTarget( 29 | name: "ExampleTests", 30 | dependencies: [ 31 | "Example", 32 | "OCMockito", 33 | ] 34 | ), 35 | // end-snippet 36 | ] 37 | ) 38 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/StubClassTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | @import XCTest; 8 | 9 | 10 | @interface ClassMethodsReturningObject : NSObject 11 | @end 12 | 13 | @implementation ClassMethodsReturningObject 14 | + (id)methodReturningObject { return self; } 15 | @end 16 | 17 | 18 | @interface StubClassTests : XCTestCase 19 | @end 20 | 21 | @implementation StubClassTests 22 | { 23 | __strong Class myMockClass; 24 | } 25 | 26 | - (void)setUp 27 | { 28 | [super setUp]; 29 | myMockClass = mockClass([ClassMethodsReturningObject class]); 30 | } 31 | 32 | - (void)tearDown 33 | { 34 | myMockClass = Nil; 35 | [super tearDown]; 36 | } 37 | 38 | - (void)testStubbedMethod_ShouldReturnGivenObject 39 | { 40 | [given([myMockClass methodReturningObject]) willReturn:@"STUBBED"]; 41 | 42 | assertThat([myMockClass methodReturningObject], is(@"STUBBED")); 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/NSInvocation+OCMockito.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract NSInvocation helper methods 12 | */ 13 | @interface NSInvocation (OCMockito) 14 | 15 | /*! 16 | * @abstract Returns all invocation arguments in an NSArray. 17 | * @discussion Non-object arguments are boxed as follows: 18 | *
    19 | *
  • nil: NSNull
  • 20 | *
  • Primitive numeric values: NSNumber
  • 21 | *
  • Pointers: NSValue
  • 22 | *
  • Selectors: NSString
  • 23 | *
  • Structs: NSData
  • 24 | *
25 | */ 26 | - (NSArray *)mkt_arguments; 27 | 28 | /*! @abstract Sets invocation return value. */ 29 | - (void)mkt_setReturnValue:(nullable id)returnValue; 30 | 31 | /*! @abstract Retains arguments but with weak invocation target to avoid retain cycles. */ 32 | - (void)mkt_retainArgumentsWithWeakTarget; 33 | 34 | @end 35 | 36 | NS_ASSUME_NONNULL_END 37 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTStubbedInvocationMatcher.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTStubbedInvocationMatcher.h" 6 | 7 | 8 | @interface MKTStubbedInvocationMatcher () 9 | @property (nonatomic, copy, readonly) NSMutableArray> *answers; 10 | @property (nonatomic, assign) NSUInteger index; 11 | @end 12 | 13 | @implementation MKTStubbedInvocationMatcher 14 | 15 | - (instancetype)init 16 | { 17 | self = [super init]; 18 | if (self) 19 | _answers = [[NSMutableArray alloc] init]; 20 | return self; 21 | } 22 | 23 | - (void)addAnswer:(id )answer 24 | { 25 | [self.answers addObject:answer]; 26 | } 27 | 28 | - (nullable id)answerInvocation:(NSInvocation *)invocation 29 | { 30 | id a = self.answers[self.index]; 31 | NSUInteger bumpedIndex = self.index + 1; 32 | if (bumpedIndex < self.answers.count) 33 | self.index = bumpedIndex; 34 | return [a answerInvocation:invocation]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtLeastNumberOfInvocationsChecker.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTAtLeastNumberOfInvocationsChecker.h" 6 | 7 | #import "MKTMatchingInvocationsFinder.h" 8 | 9 | 10 | @implementation MKTAtLeastNumberOfInvocationsChecker 11 | 12 | - (instancetype)init 13 | { 14 | self = [super initWithWantedDescription:@"Wanted at least"]; 15 | return self; 16 | } 17 | 18 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 19 | wanted:(MKTInvocationMatcher *)wanted 20 | wantedCount:(NSUInteger)wantedCount 21 | { 22 | [self.invocationsFinder findInvocationsInList:invocations matching:wanted]; 23 | NSUInteger actualCount = self.invocationsFinder.count; 24 | NSString *description; 25 | if (wantedCount > actualCount) 26 | description = [self tooLittleActual:actualCount wantedCount:wantedCount]; 27 | return description; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2011 Jonathan M. Reid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/StubbingCopyTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | 6 | #import 7 | #import 8 | @import XCTest; 9 | 10 | 11 | @interface CopyingClass : NSObject 12 | @property (nonatomic, copy, readonly) NSURL *url; 13 | - (instancetype)initWithURL:(NSURL *)url; 14 | @end 15 | 16 | @implementation CopyingClass 17 | 18 | - (instancetype)initWithURL:(NSURL *)url 19 | { 20 | self = [super init]; 21 | if (self) 22 | _url = [url copy]; 23 | return self; 24 | } 25 | 26 | @end 27 | 28 | 29 | @interface StubbingCopyTests : XCTestCase 30 | @end 31 | 32 | @implementation StubbingCopyTests 33 | 34 | - (void)testCopyingWithCopyExpectation 35 | { 36 | NSURL *mockUrl = mock([NSURL class]); 37 | [given([mockUrl copy]) willReturn:mockUrl]; 38 | 39 | CopyingClass *copyingClass = [[CopyingClass alloc] initWithURL:mockUrl]; 40 | 41 | assertThat(copyingClass.url, is(sameInstance(mockUrl))); 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyClassObjectTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface VerifyClassObjectTests : XCTestCase 13 | @end 14 | 15 | @implementation VerifyClassObjectTests 16 | { 17 | __strong Class mockStringClass; 18 | } 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | mockStringClass = mockClass([NSString class]); 24 | } 25 | 26 | - (void)tearDown 27 | { 28 | mockStringClass = Nil; 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testVerify_WithClassMethodInvoked_ShouldPass 33 | { 34 | [mockStringClass string]; 35 | 36 | [verify(mockStringClass) string]; 37 | } 38 | 39 | - (void)testVerify_WithClassMethodNotInvoked_ShouldFail 40 | { 41 | MockTestCase *mockTestCase = [[MockTestCase alloc] init]; 42 | 43 | [verifyWithMockTestCase(mockStringClass, mockTestCase) string]; 44 | 45 | assertThat(@(mockTestCase.failureCount), is(@1)); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTArgumentGetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Chain-of-responsibility for converting NSInvocation argument to object. 12 | */ 13 | @interface MKTArgumentGetter : NSObject 14 | 15 | /*! 16 | * @abstract Initializes a newly allocated argument getter. 17 | * @param handlerType Argument type managed by this getter. Assign with \@encode compiler directive. 18 | * @param successor Successor in chain to handle argument type. 19 | */ 20 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor NS_DESIGNATED_INITIALIZER; 21 | - (instancetype)init NS_UNAVAILABLE; 22 | 23 | /*! 24 | * @abstract Retrieve designated argument of specified type from NSInvocation, or pass to successor. 25 | */ 26 | - (nullable id)retrieveArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTReturnValueSetter.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Chain-of-responsibility for converting objects to NSInvocation return values. 12 | */ 13 | @interface MKTReturnValueSetter : NSObject 14 | 15 | /*! 16 | * @abstract Initializes a newly allocated return value setter. 17 | * @param handlerType Return type managed by this setter. Assign with \@encode compiler directive. 18 | * @param successor Successor in chain to handle return type. 19 | */ 20 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor NS_DESIGNATED_INITIALIZER; 21 | - (instancetype)init NS_UNAVAILABLE; 22 | ; 23 | 24 | /*! 25 | * @abstract Set NSInvocation return value of specified type, or pass to successor. 26 | */ 27 | - (void)setReturnValue:(nullable id)returnValue ofType:(char const *)type onInvocation:(NSInvocation *)invocation; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyCountNeverTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface VerifyCountNeverTests : XCTestCase 13 | @end 14 | 15 | @implementation VerifyCountNeverTests 16 | { 17 | NSMutableArray *mockArray; 18 | } 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | mockArray = mock([NSMutableArray class]); 24 | } 25 | 26 | - (void)tearDown 27 | { 28 | mockArray = nil; 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testVerifyNever_WithMethodNotInvoked_ShouldPass 33 | { 34 | [verifyCount(mockArray, never()) removeAllObjects]; 35 | } 36 | 37 | - (void)testVerifyNever_WithMethodInvoked_ShouldFail 38 | { 39 | MockTestCase *mockTestCase = [[MockTestCase alloc] init]; 40 | [mockArray removeAllObjects]; 41 | 42 | [verifyCountWithMockTestCase(mockArray, never(), mockTestCase) removeAllObjects]; 43 | 44 | assertThat(@(mockTestCase.failureCount), is(@1)); 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTTestLocation.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTTestLocation.h" 6 | 7 | #import 8 | #import 9 | #import 10 | 11 | void MKTFailTest(id testCase, const char *fileName, int lineNumber, NSString *description) 12 | { 13 | HCTestFailure *failure = [[HCTestFailure alloc] initWithTestCase:testCase 14 | fileName:[NSString stringWithUTF8String:fileName] 15 | lineNumber:(NSUInteger)lineNumber 16 | reason:description]; 17 | HCTestFailureReporter *failureReporter = [HCTestFailureReporterChain reporterChain]; 18 | [failureReporter handleFailure:failure]; 19 | } 20 | 21 | void MKTFailTestLocation(MKTTestLocation testLocation, NSString *description) 22 | { 23 | MKTFailTest(testLocation.testCase, testLocation.fileName, testLocation.lineNumber, description); 24 | } 25 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtMostNumberOfInvocationsChecker.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTAtMostNumberOfInvocationsChecker.h" 6 | 7 | #import "MKTMatchingInvocationsFinder.h" 8 | 9 | 10 | @implementation MKTAtMostNumberOfInvocationsChecker 11 | 12 | - (instancetype)init 13 | { 14 | self = [super initWithWantedDescription:@"Wanted at most"]; 15 | return self; 16 | } 17 | 18 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 19 | wanted:(MKTInvocationMatcher *)wanted 20 | wantedCount:(NSUInteger)wantedCount 21 | { 22 | [self.invocationsFinder findInvocationsInList:invocations matching:wanted]; 23 | NSUInteger actualCount = self.invocationsFinder.count; 24 | NSString *description; 25 | if (wantedCount == 0 && actualCount > 0) 26 | description = [self neverWantedButActual:actualCount]; 27 | else if (wantedCount < actualCount) 28 | description = [self tooManyActual:actualCount wantedCount:wantedCount]; 29 | return description; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTMockingProgress.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | 7 | #import "MKTTestLocation.h" 8 | 9 | @class MKTInvocationMatcher; 10 | @class MKTOngoingStubbing; 11 | @class MKTBaseMockObject; 12 | @protocol HCMatcher; 13 | @protocol MKTVerificationMode; 14 | 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | @interface MKTMockingProgress : NSObject 19 | 20 | @property (nonatomic, assign, readonly) MKTTestLocation testLocation; 21 | 22 | + (instancetype)sharedProgress; 23 | - (void)reset; 24 | 25 | - (void)stubbingStartedAtLocation:(MKTTestLocation)location; 26 | - (void)reportOngoingStubbing:(MKTOngoingStubbing *)ongoingStubbing; 27 | - (MKTOngoingStubbing *)pullOngoingStubbing; 28 | 29 | - (void)verificationStarted:(id )mode atLocation:(MKTTestLocation)location withMock:(MKTBaseMockObject *)mock; 30 | 31 | - (nullable id )pullVerificationModeWithMock:(MKTBaseMockObject *)mock; 32 | 33 | - (void)setMatcher:(id )matcher forArgument:(NSUInteger)index; 34 | - (MKTInvocationMatcher *)pullInvocationMatcher; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtMostTimes.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Emile Cantin 5 | 6 | #import "MKTAtMostTimes.h" 7 | 8 | #import "MKTAtMostNumberOfInvocationsChecker.h" 9 | #import "MKTVerificationData.h" 10 | 11 | 12 | @interface MKTAtMostTimes () 13 | @property (nonatomic, assign, readonly) NSUInteger wantedCount; 14 | @end 15 | 16 | @implementation MKTAtMostTimes 17 | 18 | - (instancetype)initWithMaximumCount:(NSUInteger)maxNumberOfInvocations 19 | { 20 | self = [super init]; 21 | if (self) 22 | _wantedCount = maxNumberOfInvocations; 23 | return self; 24 | } 25 | 26 | 27 | #pragma mark - MKTVerificationMode 28 | 29 | - (void)verifyData:(MKTVerificationData *)data testLocation:(MKTTestLocation)testLocation 30 | { 31 | MKTAtMostNumberOfInvocationsChecker *checker = [[MKTAtMostNumberOfInvocationsChecker alloc] init]; 32 | NSString *failureDescription = [checker checkInvocations:data.invocations 33 | wanted:data.wanted 34 | wantedCount:self.wantedCount]; 35 | if (failureDescription) 36 | MKTFailTestLocation(testLocation, failureDescription); 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Resources/MakeDistribution.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION=7.0.2 4 | DISTFILE=OCMockito-${VERSION} 5 | DISTPATH=build/${DISTFILE} 6 | PROJECTROOT=.. 7 | 8 | echo Preparing clean build 9 | rm -rf build 10 | mkdir build 11 | 12 | echo Downloading OCHamcrest 13 | source ../Frameworks/gethamcrest 14 | OUT=$? 15 | if [ "${OUT}" -ne "0" ]; then 16 | exit ${OUT} 17 | fi 18 | 19 | echo Building XCFramework 20 | source makeXCFramework.sh 21 | OUT=$? 22 | if [ "${OUT}" -ne "0" ]; then 23 | echo OCMockito build failed 24 | exit ${OUT} 25 | fi 26 | 27 | echo Assembling Distribution 28 | rm -rf "${DISTPATH}" 29 | mkdir "${DISTPATH}" 30 | cp -R "build/OCMockito.xcframework" "${DISTPATH}" 31 | cp "${PROJECTROOT}/README.md" "${DISTPATH}" 32 | cp "${PROJECTROOT}/CHANGELOG.md" "${DISTPATH}" 33 | cp "${PROJECTROOT}/LICENSE.txt" "${DISTPATH}" 34 | cp -R "${PROJECTROOT}/Examples" "${DISTPATH}" 35 | 36 | find "${DISTPATH}/Examples" -type d \( -name 'build' -or -name 'xcuserdata' -or -name '.svn' -or -name '.git' \) | while read -r DIR 37 | do 38 | rm -R "${DIR}"; 39 | done 40 | 41 | find "${DISTPATH}/Examples" -type f \( -name '*.pbxuser' -or -name '*.perspectivev3' -or -name '*.mode1v3' -or -name '.DS_Store' -or -name '.gitignore' \) | while read -r FILE 42 | do 43 | rm "${FILE}"; 44 | done 45 | 46 | pushd build 47 | zip --recurse-paths --symlinks ${DISTFILE}.zip ${DISTFILE} 48 | open . 49 | popd 50 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTAtLeastTimes.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Markus Gasser 5 | 6 | #import "MKTAtLeastTimes.h" 7 | 8 | #import "MKTAtLeastNumberOfInvocationsChecker.h" 9 | #import "MKTVerificationData.h" 10 | 11 | 12 | @interface MKTAtLeastTimes () 13 | @property (nonatomic, assign, readonly) NSUInteger wantedCount; 14 | @end 15 | 16 | @implementation MKTAtLeastTimes 17 | 18 | - (instancetype)initWithMinimumCount:(NSUInteger)minNumberOfInvocations 19 | { 20 | self = [super init]; 21 | if (self) 22 | _wantedCount = minNumberOfInvocations; 23 | return self; 24 | } 25 | 26 | 27 | #pragma mark - MKTVerificationMode 28 | 29 | - (void)verifyData:(MKTVerificationData *)data testLocation:(MKTTestLocation)testLocation 30 | { 31 | MKTAtLeastNumberOfInvocationsChecker *checker = [[MKTAtLeastNumberOfInvocationsChecker alloc] init]; 32 | NSString *failureDescription = [checker checkInvocations:data.invocations 33 | wanted:data.wanted 34 | wantedCount:self.wantedCount]; 35 | if (failureDescription) 36 | MKTFailTestLocation(testLocation, failureDescription); 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MockTestCase.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | @import Foundation; 6 | 7 | 8 | #define stubSingletonWithMockTestCase(mockClass, aSelector, mockTestCase) \ 9 | MKTStubSingletonWithLocation(mockClass, aSelector, mockTestCase, __FILE__, __LINE__) 10 | 11 | #define verifyWithMockTestCase(mock, mockTestCase) \ 12 | MKTVerifyWithLocation(mock, mockTestCase, __FILE__, __LINE__) 13 | 14 | #define verifyCountWithMockTestCase(mock, mode, mockTestCase) \ 15 | MKTVerifyCountWithLocation(mock, mode, mockTestCase, __FILE__, __LINE__) 16 | 17 | #define stopMockingWithMockTestCase(mock, mockTestCase) \ 18 | MKTStopMockingWithLocation(mock, mockTestCase, __FILE__, __LINE__) 19 | 20 | 21 | @interface MockTestCase : NSObject 22 | 23 | @property (nonatomic, assign) NSUInteger failureCount; 24 | @property (nonatomic, strong) NSException *failureException; 25 | @property (nonatomic, copy) NSString *failureDescription; 26 | 27 | - (void)failWithException:(NSException *)exception; 28 | - (void)recordFailureWithDescription:(NSString *)description 29 | inFile:(NSString *)filename 30 | atLine:(NSUInteger)lineNumber 31 | expected:(BOOL)expected; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTNumberOfInvocationsChecker.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTNumberOfInvocationsChecker.h" 6 | 7 | #import "MKTInvocationMatcher.h" 8 | #import "MKTMatchingInvocationsFinder.h" 9 | 10 | 11 | @implementation MKTNumberOfInvocationsChecker 12 | 13 | - (instancetype)init 14 | { 15 | self = [super initWithWantedDescription:@"Wanted"]; 16 | return self; 17 | } 18 | 19 | - (nullable NSString *)checkInvocations:(NSArray *)invocations 20 | wanted:(MKTInvocationMatcher *)wanted 21 | wantedCount:(NSUInteger)wantedCount 22 | { 23 | [self.invocationsFinder findInvocationsInList:invocations matching:wanted]; 24 | NSUInteger actualCount = self.invocationsFinder.count; 25 | NSString *description; 26 | if (wantedCount > actualCount) 27 | description = [self tooLittleActual:actualCount wantedCount:wantedCount]; 28 | else if (wantedCount == 0 && actualCount > 0) 29 | description = [self neverWantedButActual:actualCount]; 30 | else if (wantedCount < actualCount) 31 | description = [self tooManyActual:actualCount wantedCount:wantedCount]; 32 | [self.invocationsFinder markInvocationsAsVerified]; 33 | return description; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTMockitoCore.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTMockitoCore.h" 6 | 7 | #import "MKTMockingProgress.h" 8 | #import "MKTVerificationMode.h" 9 | #import "MKTObjectMock.h" 10 | 11 | @interface MKTMockitoCore () 12 | @property (nonatomic, strong, readonly) MKTMockingProgress *mockingProgress; 13 | @end 14 | 15 | @implementation MKTMockitoCore 16 | 17 | + (instancetype)sharedCore 18 | { 19 | static id sharedCore = nil; 20 | if (!sharedCore) 21 | sharedCore = [[self alloc] init]; 22 | return sharedCore; 23 | } 24 | 25 | - (instancetype)init 26 | { 27 | self = [super init]; 28 | if (self) 29 | _mockingProgress = [MKTMockingProgress sharedProgress]; 30 | return self; 31 | } 32 | 33 | - (MKTOngoingStubbing *)stubAtLocation:(MKTTestLocation)location 34 | { 35 | [self.mockingProgress stubbingStartedAtLocation:location]; 36 | return [self stub]; 37 | } 38 | 39 | - (MKTOngoingStubbing *)stub 40 | { 41 | return [self.mockingProgress pullOngoingStubbing]; 42 | } 43 | 44 | - (id)verifyMock:(MKTObjectMock *)mock 45 | withMode:(id )mode 46 | atLocation:(MKTTestLocation)location 47 | { 48 | [self.mockingProgress verificationStarted:mode atLocation:location withMock:mock]; 49 | return mock; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTReturnValueSetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetter.h" 6 | 7 | 8 | @interface MKTReturnValueSetter (SubclassResponsibility) 9 | - (void)setReturnValue:(id)returnValue onInvocation:(NSInvocation *)invocation; 10 | @end 11 | 12 | @interface MKTReturnValueSetter () 13 | @property (nonatomic, assign, readonly) char const *handlerType; 14 | @property (nullable, nonatomic, strong, readonly) MKTReturnValueSetter *successor; 15 | @end 16 | 17 | 18 | @implementation MKTReturnValueSetter 19 | 20 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTReturnValueSetter *)successor 21 | { 22 | self = [super init]; 23 | if (self) 24 | { 25 | _handlerType = handlerType; 26 | _successor = successor; 27 | } 28 | return self; 29 | } 30 | 31 | - (BOOL)handlesReturnType:(char const *)returnType 32 | { 33 | return returnType[0] == self.handlerType[0]; 34 | } 35 | 36 | - (void)setReturnValue:(nullable id)returnValue ofType:(char const *)type onInvocation:(NSInvocation *)invocation 37 | { 38 | if ([self handlesReturnType:type]) 39 | [self setReturnValue:returnValue onInvocation:invocation]; 40 | else 41 | [self.successor setReturnValue:returnValue ofType:type onInvocation:invocation]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ArgumentGetters/MKTArgumentGetter.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTArgumentGetter.h" 6 | 7 | 8 | @interface MKTArgumentGetter (SubclassResponsibility) 9 | - (id)getArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation; 10 | @end 11 | 12 | @interface MKTArgumentGetter () 13 | @property (nonatomic, assign, readonly) char const *handlerType; 14 | @property (nullable, nonatomic, strong, readonly) MKTArgumentGetter *successor; 15 | @end 16 | 17 | @implementation MKTArgumentGetter 18 | 19 | - (instancetype)initWithType:(char const *)handlerType successor:(nullable MKTArgumentGetter *)successor 20 | { 21 | self = [super init]; 22 | if (self) 23 | { 24 | _handlerType = handlerType; 25 | _successor = successor; 26 | } 27 | return self; 28 | } 29 | 30 | - (BOOL)handlesArgumentType:(char const *)argType 31 | { 32 | return argType[0] == self.handlerType[0]; 33 | } 34 | 35 | - (nullable id)retrieveArgumentAtIndex:(NSInteger)idx ofType:(char const *)type onInvocation:(NSInvocation *)invocation 36 | { 37 | if ([self handlesArgumentType:type]) 38 | return [self getArgumentAtIndex:idx ofType:type onInvocation:invocation]; 39 | 40 | return [self.successor retrieveArgumentAtIndex:idx ofType:type onInvocation:invocation]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTCallStackElement.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTCallStackElement.h" 6 | 7 | 8 | static NSRange trimTrailingSpacesFromRange(NSString *string, NSRange range) 9 | { 10 | while ([string characterAtIndex:range.location + range.length - 1] == ' ') 11 | range.length -= 1; 12 | return range; 13 | } 14 | 15 | static NSString *extractModuleName(NSString *element) 16 | { 17 | NSRange range = trimTrailingSpacesFromRange(element, NSMakeRange(4, 33)); 18 | return [element substringWithRange:range]; 19 | } 20 | 21 | static BOOL isAddress32Bit(NSString *element) 22 | { 23 | return [element characterAtIndex:50] == ' '; 24 | } 25 | 26 | static NSString *extractInstruction(NSString *element) 27 | { 28 | NSUInteger loc = 59; 29 | if (isAddress32Bit(element)) 30 | loc -= 8; 31 | NSRange range = NSMakeRange(loc, element.length - loc); 32 | return [element substringWithRange:range]; 33 | } 34 | 35 | 36 | @implementation MKTCallStackElement 37 | 38 | - (instancetype)initWithSymbols:(NSString *)element 39 | { 40 | self = [super init]; 41 | if (self) 42 | { 43 | _moduleName = extractModuleName(element); 44 | _instruction = extractInstruction(element); 45 | } 46 | return self; 47 | } 48 | 49 | - (NSString *)description 50 | { 51 | return [NSString stringWithFormat:@"%@ %@", self.moduleName, self.instruction]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTMatchingInvocationsFinder.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTMatchingInvocationsFinder.h" 6 | 7 | #import "MKTInvocation.h" 8 | #import "MKTInvocationMatcher.h" 9 | 10 | 11 | @interface MKTMatchingInvocationsFinder () 12 | @property (nonatomic, copy) NSArray *invocations; 13 | @end 14 | 15 | @implementation MKTMatchingInvocationsFinder 16 | 17 | @dynamic count; 18 | 19 | - (void)findInvocationsInList:(NSArray *)invocations matching:(MKTInvocationMatcher *)wanted 20 | { 21 | self.invocations = [invocations filteredArrayUsingPredicate: 22 | [NSPredicate predicateWithBlock:^BOOL(id obj, NSDictionary *bindings) { 23 | MKTInvocation *invocation = obj; 24 | return !invocation.verified && [wanted matches:invocation.invocation]; 25 | }]]; 26 | } 27 | 28 | - (NSUInteger)count 29 | { 30 | return self.invocations.count; 31 | } 32 | 33 | - (MKTLocation *)locationOfInvocationAtIndex:(NSUInteger)index 34 | { 35 | MKTInvocation *invocation = self.invocations[index]; 36 | return invocation.location; 37 | } 38 | 39 | - (MKTLocation *)locationOfLastInvocation 40 | { 41 | MKTInvocation *invocation = self.invocations.lastObject; 42 | return invocation.location; 43 | } 44 | 45 | - (void)markInvocationsAsVerified 46 | { 47 | for (MKTInvocation *invocation in self.invocations) 48 | invocation.verified = YES; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "OCMockito", 6 | platforms: [ 7 | .macOS(.v10_13), 8 | .iOS(.v9), 9 | .tvOS(.v12), 10 | .watchOS(.v2) 11 | ], 12 | products: [ 13 | .library(name: "OCMockito", targets: ["OCMockito"]), 14 | ], 15 | dependencies: [ 16 | .package( 17 | url: "https://github.com/hamcrest/OCHamcrest", 18 | .upToNextMajor(from: "9.1.1") 19 | ), 20 | ], 21 | targets: [ 22 | .target( 23 | name: "OCMockito", 24 | dependencies: ["OCHamcrest"], 25 | cSettings: [ 26 | .headerSearchPath("./Core"), 27 | .headerSearchPath("./Helpers/ArgumentGetters"), 28 | .headerSearchPath("./Helpers/ReturnValueSetters"), 29 | .headerSearchPath("./Invocation"), 30 | .headerSearchPath("./Mocking"), 31 | .headerSearchPath("./Stubbing"), 32 | .headerSearchPath("./Verifying") 33 | ] 34 | ), 35 | .testTarget( 36 | name: "OCMockitoTests", 37 | dependencies: ["OCMockito","OCHamcrest"], 38 | cSettings: [ 39 | .headerSearchPath("./"), 40 | .headerSearchPath("../../Sources/OCMockito/Core"), 41 | .headerSearchPath("../../Sources/OCMockito/Invocation"), 42 | .headerSearchPath("../../Sources/OCMockito/Stubbing"), 43 | .headerSearchPath("../../Sources/OCMockito/Verifying") 44 | ] 45 | ) 46 | ] 47 | ) 48 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKT_TPDWeakProxy.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright © 2013 Tetherpad 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | #import 23 | 24 | /** 25 | Instances of `TPDWeakProxy` hold a weak reference to the target object. 26 | */ 27 | 28 | @interface MKT_TPDWeakProxy : NSProxy 29 | 30 | /** 31 | Initializes an `TPDWeakProxy` object with the specified target object. 32 | 33 | @param object The target object for the proxy. 34 | 35 | @return The newly initialized proxy. 36 | */ 37 | - (instancetype)initWithObject:(id)object; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTObjectMock.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTObjectMock.h" 6 | 7 | #import "MKTDynamicProperties.h" 8 | 9 | 10 | @interface MKTObjectMock () 11 | @property (nonatomic, strong, readonly) Class mockedClass; 12 | @property (nonatomic, strong, readonly) MKTDynamicProperties *dynamicProperties; 13 | @end 14 | 15 | @implementation MKTObjectMock 16 | 17 | - (instancetype)initWithClass:(Class)aClass 18 | { 19 | self = [super init]; 20 | if (self) 21 | { 22 | _mockedClass = aClass; 23 | _dynamicProperties = [[MKTDynamicProperties alloc] initWithClass:aClass]; 24 | } 25 | return self; 26 | } 27 | 28 | - (NSString *)description 29 | { 30 | return [@"mock object of " stringByAppendingString:NSStringFromClass(self.mockedClass)]; 31 | } 32 | 33 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 34 | { 35 | NSMethodSignature *dynamicPropertySignature = [self.dynamicProperties methodSignatureForSelector:aSelector]; 36 | if (dynamicPropertySignature) 37 | return dynamicPropertySignature; 38 | return [self.mockedClass instanceMethodSignatureForSelector:aSelector]; 39 | } 40 | 41 | 42 | #pragma mark - NSObject protocol 43 | 44 | - (BOOL)isKindOfClass:(Class)aClass 45 | { 46 | return [self.mockedClass isSubclassOfClass:aClass]; 47 | } 48 | 49 | - (BOOL)respondsToSelector:(SEL)aSelector 50 | { 51 | return [self.dynamicProperties methodSignatureForSelector:aSelector] || 52 | [self.mockedClass instancesRespondToSelector:aSelector]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyObjectAndProtocolTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface VerifyObjectAndProtocolTests : XCTestCase 13 | @end 14 | 15 | @implementation VerifyObjectAndProtocolTests 16 | { 17 | NSMutableArray *mockLockingArray; 18 | MockTestCase *mockTestCase; 19 | } 20 | 21 | - (void)setUp 22 | { 23 | [super setUp]; 24 | mockLockingArray = mockObjectAndProtocol([NSMutableArray class], @protocol(NSLocking)); 25 | mockTestCase = [[MockTestCase alloc] init]; 26 | } 27 | 28 | - (void)tearDown 29 | { 30 | mockLockingArray = nil; 31 | mockTestCase = nil; 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testInvokingInstanceMethod_ShouldPass 36 | { 37 | [mockLockingArray removeAllObjects]; 38 | 39 | [verify(mockLockingArray) removeAllObjects]; 40 | } 41 | 42 | - (void)testVerify_WithInstanceMethodNotInvoked_ShouldFail 43 | { 44 | [verifyWithMockTestCase(mockLockingArray, mockTestCase) removeAllObjects]; 45 | 46 | assertThat(@(mockTestCase.failureCount), is(@1)); 47 | } 48 | 49 | - (void)testVerify_WithProtocolMethodInvoked_ShouldPass 50 | { 51 | [mockLockingArray lock]; 52 | 53 | [verify(mockLockingArray) lock]; 54 | } 55 | 56 | - (void)testVerify_WithProtocolMethodNotInvoked_ShouldFail 57 | { 58 | [verifyWithMockTestCase(mockLockingArray, mockTestCase) lock]; 59 | 60 | assertThat(@(mockTestCase.failureCount), is(@1)); 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTClassObjectMock.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by David Hart 5 | 6 | #import "MKTClassObjectMock.h" 7 | 8 | #import "MKTSingletonSwizzler.h" 9 | 10 | 11 | @interface MKTClassObjectMock () 12 | @property (nonatomic, strong) MKTSingletonSwizzler *swizzler; 13 | @end 14 | 15 | @implementation MKTClassObjectMock 16 | 17 | - (instancetype)initWithClass:(Class)aClass 18 | { 19 | self = [super init]; 20 | if (self) 21 | _mockedClass = aClass; 22 | return self; 23 | } 24 | 25 | - (MKTSingletonSwizzler *)swizzler 26 | { 27 | if (!_swizzler) 28 | _swizzler = [[MKTSingletonSwizzler alloc] initWithMock:self]; 29 | return _swizzler; 30 | } 31 | 32 | - (void)stopMocking 33 | { 34 | if (_swizzler) 35 | { 36 | [_swizzler unswizzleSingletonsForMock]; // Explicitly call for 32-bit iOS because dealloc is called too late. 37 | _swizzler = nil; 38 | } 39 | [super stopMocking]; 40 | } 41 | 42 | - (NSString *)description 43 | { 44 | return [@"mock class of " stringByAppendingString:NSStringFromClass(self.mockedClass)]; 45 | } 46 | 47 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 48 | { 49 | return [self.mockedClass methodSignatureForSelector:aSelector]; 50 | } 51 | 52 | - (void)swizzleSingletonAtSelector:(SEL)singletonSelector 53 | { 54 | [self.swizzler swizzleSingletonAtSelector:singletonSelector]; 55 | } 56 | 57 | #pragma mark - NSObject protocol 58 | 59 | - (BOOL)respondsToSelector:(SEL)aSelector 60 | { 61 | return [self.mockedClass respondsToSelector:aSelector]; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/MKTFilterCallStack.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTFilterCallStack.h" 6 | 7 | #import "MKTCallStackElement.h" 8 | 9 | 10 | static NSUInteger MKTFirstRelevantCallStackIndex(NSArray *parsedStack) 11 | { 12 | NSUInteger firstIndex = [parsedStack indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { 13 | MKTCallStackElement *element = obj; 14 | return [element.instruction hasPrefix:@"-[MKTBaseMockObject forwardInvocation:]"]; 15 | }]; 16 | return firstIndex + 3; 17 | } 18 | 19 | static NSUInteger MKTLastRelevantCallStackIndex(NSArray *parsedStack, 20 | NSUInteger startBackFrom, 21 | NSString *moduleName) 22 | { 23 | NSUInteger lastIndex = startBackFrom; 24 | while (lastIndex > 0 && ![[(parsedStack[lastIndex]) moduleName] isEqualToString:moduleName]) 25 | lastIndex -= 1; 26 | return [[(parsedStack[lastIndex]) moduleName] isEqualToString:moduleName] ? lastIndex : startBackFrom; 27 | } 28 | 29 | NSArray *MKTFilterCallStack(NSArray *parsedStack) 30 | { 31 | NSUInteger firstIndex = MKTFirstRelevantCallStackIndex(parsedStack); 32 | NSUInteger lastIndex = MKTLastRelevantCallStackIndex(parsedStack, parsedStack.count - 1, @"XCTest"); 33 | lastIndex = MKTLastRelevantCallStackIndex(parsedStack, lastIndex, [parsedStack[firstIndex] moduleName]); 34 | return [parsedStack subarrayWithRange:NSMakeRange(firstIndex, lastIndex - firstIndex + 1)]; 35 | } 36 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MKTClassObjectMockTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by David Hart 5 | 6 | #import 7 | #import 8 | @import XCTest; 9 | 10 | 11 | @interface MKTClassObjectMockTests : XCTestCase 12 | @end 13 | 14 | @implementation MKTClassObjectMockTests 15 | { 16 | __strong Class mockStringClass; 17 | } 18 | 19 | - (void)setUp 20 | { 21 | [super setUp]; 22 | mockStringClass = mockClass([NSString class]); 23 | } 24 | 25 | - (void)tearDown 26 | { 27 | mockStringClass = Nil; 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testDescription 32 | { 33 | assertThat([mockStringClass description], is(@"mock class of NSString")); 34 | } 35 | 36 | - (void)testMock_ShouldAnswerSameMethodSignatureForSelectorAsRealObject 37 | { 38 | SEL sel = NSSelectorFromString(@"text"); 39 | 40 | NSMethodSignature *signature = [mockStringClass methodSignatureForSelector:sel]; 41 | 42 | assertThat(signature, is(equalTo([[NSString class] methodSignatureForSelector:sel]))); 43 | } 44 | 45 | - (void)testMethodSignatureForSelectorNotInClass_ShouldAnswerNil 46 | { 47 | SEL sel = @selector(rangeOfString:options:); 48 | 49 | NSMethodSignature *signature = [mockStringClass methodSignatureForSelector:sel]; 50 | 51 | assertThat(signature, is(nilValue())); 52 | } 53 | 54 | - (void)testShouldRespondToKnownSelector 55 | { 56 | XCTAssertTrue([mockStringClass respondsToSelector:@selector(pathWithComponents:)]); 57 | } 58 | 59 | - (void)testShouldNotRespondToUnknownSelector 60 | { 61 | XCTAssertFalse([mockStringClass respondsToSelector:@selector(pathExtension)]); 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Sources/OCMockito/Verifying/MKTExactTimes.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTExactTimes.h" 6 | 7 | #import "MKTInvocationMatcher.h" 8 | #import "MKTNumberOfInvocationsChecker.h" 9 | #import "MKTVerificationData.h" 10 | #import "MKTMissingInvocationChecker.h" 11 | 12 | 13 | @interface MKTExactTimes () 14 | @property (nonatomic, assign, readonly) NSUInteger wantedCount; 15 | @end 16 | 17 | @implementation MKTExactTimes 18 | 19 | - (instancetype)initWithCount:(NSUInteger)wantedNumberOfInvocations 20 | { 21 | self = [super init]; 22 | if (self) 23 | _wantedCount = wantedNumberOfInvocations; 24 | return self; 25 | } 26 | 27 | 28 | #pragma mark - MKTVerificationMode 29 | 30 | - (void)verifyData:(MKTVerificationData *)data testLocation:(MKTTestLocation)testLocation 31 | { 32 | NSString *failureDescription; 33 | if (self.wantedCount > 0) 34 | { 35 | MKTMissingInvocationChecker *missingInvocation = [[MKTMissingInvocationChecker alloc] init]; 36 | failureDescription = [missingInvocation checkInvocations:data.invocations wanted:data.wanted]; 37 | [data.wanted stopArgumentCapture]; 38 | } 39 | if (!failureDescription) 40 | { 41 | MKTNumberOfInvocationsChecker *numberOfInvocations = [[MKTNumberOfInvocationsChecker alloc] init]; 42 | failureDescription = [numberOfInvocations checkInvocations:data.invocations 43 | wanted:data.wanted 44 | wantedCount:self.wantedCount]; 45 | } 46 | 47 | if (failureDescription) 48 | MKTFailTestLocation(testLocation, failureDescription); 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Resources/XcodeTargets.xcconfig: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // Contribution by Jens Nerup 3 | 4 | // Targeted Device Families 5 | // 6 | // The build system uses the selected device to set the correct value for the 7 | // `UIDeviceFamily` key it adds to the target's `Info.plist` file. This also drives the 8 | // --target-device flag to actool, which determines the idioms selected during catalog 9 | // compilation. 10 | TARGETED_DEVICE_FAMILY = 1,2,3,4,7 11 | 12 | IPHONEOS_DEPLOYMENT_TARGET = 9.0 13 | MACOSX_DEPLOYMENT_TARGET = 10.13 14 | TVOS_DEPLOYMENT_TARGET = 12.0 15 | WATCHOS_DEPLOYMENT_TARGET = 2.0 16 | XROS_DEPLOYMENT_TARGET = 1.0 17 | 18 | // Product Bundle Identifier 19 | // 20 | // A string that uniquely identifies the bundle. The string should be in reverse DNS 21 | // format using only alphanumeric characters (`A-Z`, `a-z`, `0-9`), the dot (`.`), and 22 | // the hyphen (`-`). This value is used as the `CFBundleIdentifier` in the `Info.plist` 23 | // of the built bundle. 24 | PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvos*] = org.hamcrest.OCMockito-tvOS 25 | PRODUCT_BUNDLE_IDENTIFIER[sdk=appletvsimulator*] = org.hamcrest.OCMockito-tvOS 26 | PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*] = org.hamcrest.OCMockito-iOS 27 | PRODUCT_BUNDLE_IDENTIFIER[sdk=iphonesimulator*] = org.hamcrest.OCMockito-iOS 28 | PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*] = org.hamcrest.OCHamcrest 29 | PRODUCT_BUNDLE_IDENTIFIER[sdk=watchos*] = org.hamcrest.OCMockito-watchOS 30 | PRODUCT_BUNDLE_IDENTIFIER[sdk=watchsimulator*] = org.hamcrest.OCMockito-watchOS 31 | PRODUCT_BUNDLE_IDENTIFIER[sdk=xros*] = org.hamcrest.OCMockito-visionOS 32 | PRODUCT_BUNDLE_IDENTIFIER[sdk=xrsimulator*] = org.hamcrest.OCMockito-visionOS 33 | 34 | // Supported Platforms 35 | // 36 | // The list of supported platforms from which a base SDK can be used. This setting is 37 | // used if the product can be built for multiple platforms using different SDKs. 38 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator watchos watchsimulator appletvos appletvsimulator xros xrsimulator 39 | -------------------------------------------------------------------------------- /Sources/OCMockito/Invocation/NSInvocation+OCMockito.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "NSInvocation+OCMockito.h" 6 | 7 | #import "MKTArgumentGetter.h" 8 | #import "MKTArgumentGetterChain.h" 9 | #import "MKTReturnValueSetter.h" 10 | #import "MKTReturnValueSetterChain.h" 11 | #import "MKT_TPDWeakProxy.h" 12 | 13 | 14 | @implementation NSInvocation (OCMockito) 15 | 16 | - (NSArray *)mkt_arguments 17 | { 18 | [self retainArguments]; // make sure no stack blocks are added to the autoreleased array that can outlive them 19 | 20 | NSMethodSignature *signature = self.methodSignature; 21 | NSUInteger numberOfArguments = signature.numberOfArguments; 22 | NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:numberOfArguments - 2]; 23 | 24 | for (NSUInteger idx = 2; idx < numberOfArguments; ++idx) // Indices 0 and 1 are self and _cmd 25 | { 26 | const char *argType = [signature getArgumentTypeAtIndex:idx]; 27 | id arg = [MKTArgumentGetterChain() retrieveArgumentAtIndex:(NSInteger)idx ofType:argType onInvocation:self]; 28 | if (arg) 29 | [arguments addObject:arg]; 30 | else 31 | { 32 | NSLog(@"mkt_arguments unhandled type: %s", argType); 33 | [arguments addObject:[NSNull null]]; 34 | } 35 | } 36 | 37 | return arguments; 38 | } 39 | 40 | - (void)mkt_setReturnValue:(nullable id)returnValue 41 | { 42 | char const *returnType = self.methodSignature.methodReturnType; 43 | [MKTReturnValueSetterChain() setReturnValue:returnValue ofType:returnType onInvocation:self]; 44 | } 45 | 46 | - (void)mkt_retainArgumentsWithWeakTarget 47 | { 48 | if (self.argumentsRetained) 49 | return; 50 | MKT_TPDWeakProxy *proxy = [[MKT_TPDWeakProxy alloc] initWithObject:self.target]; 51 | self.target = proxy; 52 | [self retainArguments]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTNonObjectArgumentMatching.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | @protocol HCMatcher; 6 | 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | /*! 11 | * @abstract Ability to specify OCHamcrest matchers for non-object arguments. 12 | */ 13 | @protocol MKTNonObjectArgumentMatching 14 | 15 | /*! 16 | * @abstract Specifies OCHamcrest matcher for a specific argument of a method. 17 | * @discussion For methods arguments that take objects, just pass the matcher directly as a method 18 | * call. But for arguments that take non-objects, pass in a dummy value to satisfy the compiler, but 19 | * call this to override it with the given matcher. Upon verification, the actual argument received 20 | * will be converted to an object before being checked by the matcher. 21 | * 22 | * The argument index is 0-based, so the first argument of a method has index 0. 23 | * 24 | * Examples: 25 | *
[[given([mockFetchedResultsController performFetch:NULL]) withMatcher:anything()] willReturn:\@YES];
26 | * This stubs performFetch: to return YES for any NSError ** argument. 27 | * 28 | *
[[verify(mockArray) withMatcher:greaterThan(@5]) forArgument:0] removeObjectAtIndex:0];
29 | * This verifies that removeObjectAtIndex: was called with an index greater than 5. 30 | */ 31 | - (id)withMatcher:(id )matcher forArgument:(NSUInteger)index; 32 | 33 | /*! 34 | * @abstract Specifies OCHamcrest matcher for the first argument of a method. 35 | * @discussion Equivalent to withMatcher:matcher forArgument:0. 36 | * 37 | * Example: 38 | *
[[verify(mockArray) withMatcher:greaterThan(\@5)] removeObjectAtIndex:0];
39 | * This verifies that removeObjectAtIndex: was called with an index greater than 5. 40 | */ 41 | - (id)withMatcher:(id )matcher; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/StubSingletonProgrammerErrorTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface StubSingletonProgrammerErrorTests : XCTestCase 13 | @end 14 | 15 | @implementation StubSingletonProgrammerErrorTests 16 | { 17 | MockTestCase *mockTestCase; 18 | } 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | mockTestCase = [[MockTestCase alloc] init]; 24 | } 25 | 26 | - (void)tearDown 27 | { 28 | mockTestCase = nil; 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testStubSingleton_WithNil_ShouldGiveError 33 | { 34 | #pragma clang diagnostic push 35 | #pragma clang diagnostic ignored "-Wnonnull" 36 | stubSingletonWithMockTestCase(nil, @selector(standardUserDefaults), mockTestCase); 37 | #pragma clang diagnostic pop 38 | 39 | assertThat(mockTestCase.failureDescription, 40 | is(@"Argument passed to stubSingleton() should be a class mock, but was nil")); 41 | } 42 | 43 | - (void)testStubSingleton_WithObjectMock_ShouldGiveError 44 | { 45 | id objectMock = mock([NSUserDefaults class]); 46 | 47 | stubSingletonWithMockTestCase(objectMock, @selector(standardUserDefaults), mockTestCase); 48 | 49 | assertThat(mockTestCase.failureDescription, 50 | is(@"Argument passed to stubSingleton() should be a class mock, but was type MKTObjectMock")); 51 | } 52 | 53 | - (void)testStubSingleton_WithNoSuchSingleton_ShouldGiveError 54 | { 55 | id classMock = mockClass([NSArray class]); 56 | 57 | stubSingletonWithMockTestCase(classMock, @selector(standardUserDefaults), mockTestCase); 58 | 59 | assertThat(mockTestCase.failureDescription, 60 | is(@"Method name passed to stubSingleton() should be a class method of NSArray, but was standardUserDefaults")); 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyCountAtMostTimesTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Emile Cantin 5 | 6 | #import 7 | #import 8 | 9 | #import "MockTestCase.h" 10 | @import XCTest; 11 | 12 | 13 | @interface VerifyCountAtMostTimesTests : XCTestCase 14 | @end 15 | 16 | @implementation VerifyCountAtMostTimesTests 17 | { 18 | NSMutableArray *mockArray; 19 | MockTestCase *mockTestCase; 20 | } 21 | 22 | - (void)setUp 23 | { 24 | [super setUp]; 25 | mockArray = mock([NSMutableArray class]); 26 | mockTestCase = [[MockTestCase alloc] init]; 27 | } 28 | 29 | - (void)tearDown 30 | { 31 | mockArray = nil; 32 | mockTestCase = nil; 33 | [super tearDown]; 34 | } 35 | 36 | - (void)callRemoveAllObjectsTimes:(int)count 37 | { 38 | for (int i = 0; i < count; ++i) 39 | [mockArray removeAllObjects]; 40 | } 41 | 42 | - (void)testAtMost_WithTooManyInvocations_ShouldFail 43 | { 44 | [self callRemoveAllObjectsTimes:3]; 45 | 46 | [verifyCountWithMockTestCase(mockArray, atMost(2), mockTestCase) removeAllObjects]; 47 | 48 | assertThat(@(mockTestCase.failureCount), is(@1)); 49 | } 50 | 51 | - (void)testAtMost_WithExactCount_ShouldPass 52 | { 53 | [self callRemoveAllObjectsTimes:1]; 54 | 55 | [verifyCount(mockArray, atMost(1)) removeAllObjects]; 56 | } 57 | 58 | - (void)testAtMost_WithFewerInvocations_ShouldPass 59 | { 60 | [self callRemoveAllObjectsTimes:2]; 61 | 62 | [verifyCount(mockArray, atMost(3)) removeAllObjects]; 63 | } 64 | 65 | - (void)testAtMostOneFailure_ShouldStateExpectedNumberOfInvocations 66 | { 67 | [self callRemoveAllObjectsTimes:3]; 68 | 69 | [verifyCountWithMockTestCase(mockArray, atMost(1), mockTestCase) removeAllObjects]; 70 | 71 | assertThat(mockTestCase.failureDescription, 72 | startsWith(@"Wanted at most 1 time but was called 3 times.")); 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/NSInvocation+OCMockitoTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | @import XCTest; 8 | 9 | 10 | @interface NSInvocation_OCMockitoTests : XCTestCase 11 | @end 12 | 13 | @implementation NSInvocation_OCMockitoTests 14 | { 15 | NSMutableArray *target; 16 | NSInvocation *invocation; 17 | } 18 | 19 | - (void)setUp 20 | { 21 | [super setUp]; 22 | target = [[NSMutableArray alloc] init]; 23 | SEL selector = @selector(count); 24 | NSMethodSignature *signature = [target methodSignatureForSelector:selector]; 25 | invocation = [NSInvocation invocationWithMethodSignature:signature]; 26 | [invocation setSelector:selector]; 27 | } 28 | 29 | - (void)tearDown 30 | { 31 | target = nil; 32 | invocation = nil; 33 | [super tearDown]; 34 | } 35 | 36 | - (void)testRetainArgumentsWithWeakTarget_ShouldRetainArguments 37 | { 38 | [invocation setTarget:target]; 39 | 40 | [invocation mkt_retainArgumentsWithWeakTarget]; 41 | 42 | XCTAssertTrue([invocation argumentsRetained]); 43 | } 44 | 45 | - (void)testRetainArgumentsWithWeakTarget_ShouldReplaceTargetWithWeakProxy 46 | { 47 | [invocation setTarget:target]; 48 | 49 | [invocation mkt_retainArgumentsWithWeakTarget]; 50 | 51 | assertThat([invocation target], hasDescription(containsSubstring(@"WeakProxy"))); 52 | } 53 | 54 | - (void)testRetainArgumentsWithWeakTarget_ShouldNotReplaceTargetOnSecondCall 55 | { 56 | [invocation setTarget:target]; 57 | [invocation mkt_retainArgumentsWithWeakTarget]; 58 | id weakProxy = [invocation target]; 59 | 60 | [invocation mkt_retainArgumentsWithWeakTarget]; 61 | 62 | assertThat([invocation target], is(sameInstance(weakProxy))); 63 | } 64 | 65 | - (void)testArguments_ShouldCopyStackBlocks 66 | { 67 | assertThat(@(invocation.argumentsRetained), isFalse()); 68 | [invocation mkt_arguments]; 69 | assertThat(@(invocation.argumentsRetained), isTrue()); 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/BlockMatchingTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | @import XCTest; 8 | 9 | 10 | typedef NSString *(^BlockReturningString)(void); 11 | 12 | @interface ObjectWithBlockArg : NSObject 13 | @end 14 | 15 | @implementation ObjectWithBlockArg 16 | 17 | - (NSString *)doBlock:(BlockReturningString)block 18 | { 19 | if (block) 20 | return block(); 21 | return nil; 22 | } 23 | 24 | @end 25 | 26 | 27 | @interface BlockMatchingTests : XCTestCase 28 | @end 29 | 30 | @implementation BlockMatchingTests 31 | { 32 | ObjectWithBlockArg *mockObj; 33 | } 34 | 35 | - (void)setUp 36 | { 37 | [super setUp]; 38 | mockObj = mock([ObjectWithBlockArg class]); 39 | } 40 | 41 | - (void)tearDown 42 | { 43 | mockObj = nil; 44 | [super tearDown]; 45 | } 46 | 47 | - (void)testMockingMethodWithBlockArg_WithNilValueMatcher_ShouldMatchNil 48 | { 49 | [given([mockObj doBlock:(id)nilValue()]) willReturn:@"match nil"]; 50 | [given([mockObj doBlock:(id)notNilValue()]) willReturn:@"match not nil"]; 51 | 52 | assertThat([mockObj doBlock:nil], is(@"match nil")); 53 | } 54 | 55 | - (void)testMockingMethodWithBlockArg_WithNotNilValueMatcher_ShouldMatchBlock 56 | { 57 | [given([mockObj doBlock:(id)nilValue()]) willReturn:@"match nil"]; 58 | [given([mockObj doBlock:(id)notNilValue()]) willReturn:@"match not nil"]; 59 | 60 | BlockReturningString anyBlock = ^NSString *{ return @"DUMMY"; }; 61 | 62 | assertThat([mockObj doBlock:anyBlock], is(@"match not nil")); 63 | } 64 | 65 | - (void)testMockingMethodWithBlockArg_WithArgumentCaptor_ShouldLetYouExecuteCapturedBlock 66 | { 67 | HCArgumentCaptor *argument = [[HCArgumentCaptor alloc] init]; 68 | 69 | [mockObj doBlock:^NSString * { 70 | return @"SUCCESS"; 71 | }]; 72 | [verify(mockObj) doBlock:(id)argument]; 73 | 74 | BlockReturningString block = argument.value; 75 | assertThat(block(), is(@"SUCCESS")); 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTObjectAndProtocolMock.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Kevin Lundberg 5 | 6 | #import "MKTObjectAndProtocolMock.h" 7 | 8 | #import "MKTDynamicProperties.h" 9 | #import 10 | 11 | 12 | @interface MKTObjectAndProtocolMock () 13 | @property (nonatomic, strong, readonly) Class mockedClass; 14 | @property (nonatomic, strong, readonly) MKTDynamicProperties *dynamicProperties; 15 | @end 16 | 17 | @implementation MKTObjectAndProtocolMock 18 | 19 | - (instancetype)initWithClass:(Class)aClass protocol:(Protocol *)protocol 20 | { 21 | self = [super initWithProtocol:protocol includeOptionalMethods:YES]; 22 | if (self) 23 | { 24 | _mockedClass = aClass; 25 | _dynamicProperties = [[MKTDynamicProperties alloc] initWithClass:aClass]; 26 | } 27 | return self; 28 | } 29 | 30 | - (NSString *)description 31 | { 32 | return [NSString stringWithFormat:@"mock object of %@ implementing %@ protocol", 33 | NSStringFromClass(self.mockedClass), NSStringFromProtocol(self.mockedProtocol)]; 34 | } 35 | 36 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 37 | { 38 | NSMethodSignature *dynamicPropertySignature = [self.dynamicProperties methodSignatureForSelector:aSelector]; 39 | if (dynamicPropertySignature) 40 | return dynamicPropertySignature; 41 | NSMethodSignature *signature = [self.mockedClass instanceMethodSignatureForSelector:aSelector]; 42 | if (signature) 43 | return signature; 44 | return [super methodSignatureForSelector:aSelector]; 45 | } 46 | 47 | 48 | #pragma mark - NSObject protocol 49 | 50 | - (BOOL)isKindOfClass:(Class)aClass 51 | { 52 | return [self.mockedClass isSubclassOfClass:aClass]; 53 | } 54 | 55 | - (BOOL)respondsToSelector:(SEL)aSelector 56 | { 57 | return [self.dynamicProperties methodSignatureForSelector:aSelector] || 58 | [self.mockedClass instancesRespondToSelector:aSelector] || 59 | [super respondsToSelector:aSelector]; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Examples/MacExample-CocoaPods/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | @import OCHamcrest; 2 | @import OCMockito; 3 | @import XCTest; 4 | 5 | 6 | @interface ExampleTests : XCTestCase 7 | @end 8 | 9 | @implementation ExampleTests 10 | 11 | - (void)testSimpleVerify 12 | { 13 | NSMutableArray *mockArray = mock([NSMutableArray class]); 14 | [mockArray removeAllObjects]; 15 | [verify(mockArray) removeAllObjects]; 16 | } 17 | 18 | - (void)testVerifyWithArgument 19 | { 20 | NSMutableArray *mockArray = mock([NSMutableArray class]); 21 | [mockArray removeObject:@"This is a test"]; 22 | [verify(mockArray) removeObject:@"This is a test"]; 23 | } 24 | 25 | - (void)testVerifyWithMatcher 26 | { 27 | NSMutableArray *mockArray = mock([NSMutableArray class]); 28 | [mockArray removeObject:@"This is a test"]; 29 | [verify(mockArray) removeObject:startsWith(@"This is")]; 30 | } 31 | 32 | - (void)testVerifyWithPrimitive 33 | { 34 | NSMutableArray *mockArray = mock([NSMutableArray class]); 35 | [mockArray removeObjectAtIndex:2]; 36 | [verify(mockArray) removeObjectAtIndex:2]; 37 | } 38 | 39 | - (void)testVerifyWithMatcherForPrimitive 40 | { 41 | NSMutableArray *mockArray = mock([NSMutableArray class]); 42 | [mockArray removeObjectAtIndex:2]; 43 | [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0] 44 | removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher 45 | } 46 | 47 | - (void)testSimpleStub 48 | { 49 | NSArray *mockArray = mock([NSArray class]); 50 | [given([mockArray lastObject]) willReturn:@"last"]; 51 | assertThat([mockArray lastObject], is(@"last")); 52 | } 53 | 54 | - (void)testStubsWithArguments 55 | { 56 | NSArray *mockArray = mock([NSArray class]); 57 | [given([mockArray objectAtIndex:0]) willReturn:@"foo"]; 58 | [given([mockArray objectAtIndex:1]) willReturn:@"bar"]; 59 | assertThat([mockArray objectAtIndex:0], is(@"foo")); 60 | } 61 | 62 | - (void)testStubReturningPrimitive 63 | { 64 | NSArray *mockArray = mock([NSArray class]); 65 | [given([mockArray count]) willReturnUnsignedInteger:3]; 66 | assertThatUnsignedInteger([mockArray count], is(equalToUnsignedInteger(3))); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Examples/MacExample-Framework/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | @import OCHamcrest; 2 | @import OCMockito; 3 | @import XCTest; 4 | 5 | 6 | @interface ExampleTests : XCTestCase 7 | @end 8 | 9 | @implementation ExampleTests 10 | 11 | - (void)testSimpleVerify 12 | { 13 | NSMutableArray *mockArray = mock([NSMutableArray class]); 14 | [mockArray removeAllObjects]; 15 | [verify(mockArray) removeAllObjects]; 16 | } 17 | 18 | - (void)testVerifyWithArgument 19 | { 20 | NSMutableArray *mockArray = mock([NSMutableArray class]); 21 | [mockArray removeObject:@"This is a test"]; 22 | [verify(mockArray) removeObject:@"This is a test"]; 23 | } 24 | 25 | - (void)testVerifyWithMatcher 26 | { 27 | NSMutableArray *mockArray = mock([NSMutableArray class]); 28 | [mockArray removeObject:@"This is a test"]; 29 | [verify(mockArray) removeObject:startsWith(@"This is")]; 30 | } 31 | 32 | - (void)testVerifyWithPrimitive 33 | { 34 | NSMutableArray *mockArray = mock([NSMutableArray class]); 35 | [mockArray removeObjectAtIndex:2]; 36 | [verify(mockArray) removeObjectAtIndex:2]; 37 | } 38 | 39 | - (void)testVerifyWithMatcherForPrimitive 40 | { 41 | NSMutableArray *mockArray = mock([NSMutableArray class]); 42 | [mockArray removeObjectAtIndex:2]; 43 | [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0] 44 | removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher 45 | } 46 | 47 | - (void)testSimpleStub 48 | { 49 | NSArray *mockArray = mock([NSArray class]); 50 | [given([mockArray lastObject]) willReturn:@"last"]; 51 | assertThat([mockArray lastObject], is(@"last")); 52 | } 53 | 54 | - (void)testStubsWithArguments 55 | { 56 | NSArray *mockArray = mock([NSArray class]); 57 | [given([mockArray objectAtIndex:0]) willReturn:@"foo"]; 58 | [given([mockArray objectAtIndex:1]) willReturn:@"bar"]; 59 | assertThat([mockArray objectAtIndex:0], is(@"foo")); 60 | } 61 | 62 | - (void)testStubReturningPrimitive 63 | { 64 | NSArray *mockArray = mock([NSArray class]); 65 | [given([mockArray count]) willReturnUnsignedInteger:3]; 66 | assertThatUnsignedInteger([mockArray count], is(equalToUnsignedInteger(3))); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Examples/iOSExample-Cocoapods/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | @import OCHamcrest; 2 | @import OCMockito; 3 | @import XCTest; 4 | 5 | 6 | @interface ExampleTests : XCTestCase 7 | @end 8 | 9 | @implementation ExampleTests 10 | 11 | - (void)testSimpleVerify 12 | { 13 | NSMutableArray *mockArray = mock([NSMutableArray class]); 14 | [mockArray removeAllObjects]; 15 | [verify(mockArray) removeAllObjects]; 16 | } 17 | 18 | - (void)testVerifyWithArgument 19 | { 20 | NSMutableArray *mockArray = mock([NSMutableArray class]); 21 | [mockArray removeObject:@"This is a test"]; 22 | [verify(mockArray) removeObject:@"This is a test"]; 23 | } 24 | 25 | - (void)testVerifyWithMatcher 26 | { 27 | NSMutableArray *mockArray = mock([NSMutableArray class]); 28 | [mockArray removeObject:@"This is a test"]; 29 | [verify(mockArray) removeObject:startsWith(@"This is")]; 30 | } 31 | 32 | - (void)testVerifyWithPrimitive 33 | { 34 | NSMutableArray *mockArray = mock([NSMutableArray class]); 35 | [mockArray removeObjectAtIndex:2]; 36 | [verify(mockArray) removeObjectAtIndex:2]; 37 | } 38 | 39 | - (void)testVerifyWithMatcherForPrimitive 40 | { 41 | NSMutableArray *mockArray = mock([NSMutableArray class]); 42 | [mockArray removeObjectAtIndex:2]; 43 | [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0] 44 | removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher 45 | } 46 | 47 | - (void)testSimpleStub 48 | { 49 | NSArray *mockArray = mock([NSArray class]); 50 | [given([mockArray lastObject]) willReturn:@"last"]; 51 | assertThat([mockArray lastObject], is(@"last")); 52 | } 53 | 54 | - (void)testStubsWithArguments 55 | { 56 | NSArray *mockArray = mock([NSArray class]); 57 | [given([mockArray objectAtIndex:0]) willReturn:@"foo"]; 58 | [given([mockArray objectAtIndex:1]) willReturn:@"bar"]; 59 | assertThat([mockArray objectAtIndex:0], is(@"foo")); 60 | } 61 | 62 | - (void)testStubReturningPrimitive 63 | { 64 | NSArray *mockArray = mock([NSArray class]); 65 | [given([mockArray count]) willReturnUnsignedInteger:3]; 66 | assertThatUnsignedInteger([mockArray count], is(equalToUnsignedInteger(3))); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Examples/iOSExample-Framework/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | @import OCHamcrest; 2 | @import OCMockito; 3 | @import XCTest; 4 | 5 | 6 | @interface ExampleTests : XCTestCase 7 | @end 8 | 9 | @implementation ExampleTests 10 | 11 | - (void)testSimpleVerify 12 | { 13 | NSMutableArray *mockArray = mock([NSMutableArray class]); 14 | [mockArray removeAllObjects]; 15 | [verify(mockArray) removeAllObjects]; 16 | } 17 | 18 | - (void)testVerifyWithArgument 19 | { 20 | NSMutableArray *mockArray = mock([NSMutableArray class]); 21 | [mockArray removeObject:@"This is a test"]; 22 | [verify(mockArray) removeObject:@"This is a test"]; 23 | } 24 | 25 | - (void)testVerifyWithMatcher 26 | { 27 | NSMutableArray *mockArray = mock([NSMutableArray class]); 28 | [mockArray removeObject:@"This is a test"]; 29 | [verify(mockArray) removeObject:startsWith(@"This is")]; 30 | } 31 | 32 | - (void)testVerifyWithPrimitive 33 | { 34 | NSMutableArray *mockArray = mock([NSMutableArray class]); 35 | [mockArray removeObjectAtIndex:2]; 36 | [verify(mockArray) removeObjectAtIndex:2]; 37 | } 38 | 39 | - (void)testVerifyWithMatcherForPrimitive 40 | { 41 | NSMutableArray *mockArray = mock([NSMutableArray class]); 42 | [mockArray removeObjectAtIndex:2]; 43 | [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0] 44 | removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher 45 | } 46 | 47 | - (void)testSimpleStub 48 | { 49 | NSArray *mockArray = mock([NSArray class]); 50 | [given([mockArray lastObject]) willReturn:@"last"]; 51 | assertThat([mockArray lastObject], is(@"last")); 52 | } 53 | 54 | - (void)testStubsWithArguments 55 | { 56 | NSArray *mockArray = mock([NSArray class]); 57 | [given([mockArray objectAtIndex:0]) willReturn:@"foo"]; 58 | [given([mockArray objectAtIndex:1]) willReturn:@"bar"]; 59 | assertThat([mockArray objectAtIndex:0], is(@"foo")); 60 | } 61 | 62 | - (void)testStubReturningPrimitive 63 | { 64 | NSArray *mockArray = mock([NSArray class]); 65 | [given([mockArray count]) willReturnUnsignedInteger:3]; 66 | assertThatUnsignedInteger([mockArray count], is(equalToUnsignedInteger(3))); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Examples/MacExample-SwiftPackageManager/Tests/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | @import OCHamcrest; 2 | @import OCMockito; 3 | @import XCTest; 4 | 5 | 6 | @interface ExampleTests : XCTestCase 7 | @end 8 | 9 | @implementation ExampleTests 10 | 11 | - (void)testSimpleVerify 12 | { 13 | NSMutableArray *mockArray = mock([NSMutableArray class]); 14 | [mockArray removeAllObjects]; 15 | [verify(mockArray) removeAllObjects]; 16 | } 17 | 18 | - (void)testVerifyWithArgument 19 | { 20 | NSMutableArray *mockArray = mock([NSMutableArray class]); 21 | [mockArray removeObject:@"This is a test"]; 22 | [verify(mockArray) removeObject:@"This is a test"]; 23 | } 24 | 25 | - (void)testVerifyWithMatcher 26 | { 27 | NSMutableArray *mockArray = mock([NSMutableArray class]); 28 | [mockArray removeObject:@"This is a test"]; 29 | [verify(mockArray) removeObject:startsWith(@"This is")]; 30 | } 31 | 32 | - (void)testVerifyWithPrimitive 33 | { 34 | NSMutableArray *mockArray = mock([NSMutableArray class]); 35 | [mockArray removeObjectAtIndex:2]; 36 | [verify(mockArray) removeObjectAtIndex:2]; 37 | } 38 | 39 | - (void)testVerifyWithMatcherForPrimitive 40 | { 41 | NSMutableArray *mockArray = mock([NSMutableArray class]); 42 | [mockArray removeObjectAtIndex:2]; 43 | [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0] 44 | removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher 45 | } 46 | 47 | - (void)testSimpleStub 48 | { 49 | NSArray *mockArray = mock([NSArray class]); 50 | [given([mockArray lastObject]) willReturn:@"last"]; 51 | assertThat([mockArray lastObject], is(@"last")); 52 | } 53 | 54 | - (void)testStubsWithArguments 55 | { 56 | NSArray *mockArray = mock([NSArray class]); 57 | [given([mockArray objectAtIndex:0]) willReturn:@"foo"]; 58 | [given([mockArray objectAtIndex:1]) willReturn:@"bar"]; 59 | assertThat([mockArray objectAtIndex:0], is(@"foo")); 60 | } 61 | 62 | - (void)testStubReturningPrimitive 63 | { 64 | NSArray *mockArray = mock([NSArray class]); 65 | [given([mockArray count]) willReturnUnsignedInteger:3]; 66 | assertThatUnsignedInteger([mockArray count], is(equalToUnsignedInteger(3))); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /OCMockito.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'OCMockito' 3 | s.version = '7.0.2' 4 | s.summary = 'OCMockito is an Objective-C implementation of Mockito, supporting creation, verification and stubbing of mock objects.' 5 | s.description = <<-DESC 6 | OCMockito is an Objective-C implementation of Mockito, supporting creation, 7 | verification and stubbing of mock objects. 8 | 9 | Key differences from other mocking frameworks: 10 | 11 | * Mock objects are always "nice," recording their calls instead of 12 | throwing exceptions about unspecified invocations. This makes tests less fragile. 13 | * No expect-run-verify, making tests more readable. Mock objects 14 | record their calls, then you verify the methods you want. 15 | * Verification failures are reported as unit test failures, 16 | identifying specific lines instead of throwing exceptions. This makes 17 | it easier to identify failures. 18 | DESC 19 | s.homepage = 'https://github.com/jonreid/OCMockito' 20 | s.license = { :type => 'MIT' } 21 | s.author = { 'Jon Reid' => 'jon@qualitycoding.org' } 22 | s.social_media_url = 'https://iosdev.space/@qcoding' 23 | 24 | s.osx.deployment_target = '10.13' 25 | s.ios.deployment_target = '9.0' 26 | s.tvos.deployment_target = '12.0' 27 | s.watchos.deployment_target = '2.0' 28 | s.visionos.deployment_target = '1.0' 29 | s.source = { :git => 'https://github.com/jonreid/OCMockito.git', :tag => 'v7.0.2' } 30 | s.source_files = 'Sources/OCMockito/**/*.{h,m}', 'Sources/ThirdParty/**/*.{h,m}' 31 | s.public_header_files = 'Sources/OCMockito/Core/MKTNonObjectArgumentMatching.h', 'Sources/OCMockito/Core/OCMockito.h', 'Sources/OCMockito/Invocation/NSInvocation+OCMockito.h', 'Sources/OCMockito/Mocking/MKTBaseMockObject.h', 'Sources/OCMockito/Mocking/MKTClassObjectMock.h', 'Sources/OCMockito/Mocking/MKTObjectAndProtocolMock.h', 'Sources/OCMockito/Mocking/MKTObjectMock.h', 'Sources/OCMockito/Mocking/MKTProtocolMock.h', 'Sources/OCMockito/Stubbing/MKTOngoingStubbing.h' 32 | s.requires_arc = true 33 | s.dependency 'OCHamcrest', '~> 9.1.1' 34 | end 35 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyProgrammerErrorTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface VerifyProgrammerErrorTests : XCTestCase 13 | @end 14 | 15 | @implementation VerifyProgrammerErrorTests 16 | { 17 | MockTestCase *mockTestCase; 18 | } 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | mockTestCase = [[MockTestCase alloc] init]; 24 | } 25 | 26 | - (void)tearDown 27 | { 28 | mockTestCase = nil; 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testVerify_WithNil_ShouldGiveError 33 | { 34 | #pragma clang diagnostic push 35 | #pragma clang diagnostic ignored "-Wnonnull" 36 | [verifyWithMockTestCase(nil, mockTestCase) removeAllObjects]; 37 | #pragma clang diagnostic pop 38 | 39 | assertThat(mockTestCase.failureDescription, 40 | is(@"Argument passed to verify() should be a mock, but was nil")); 41 | } 42 | 43 | - (void)testVerifyCount_WithNil_ShouldGiveError 44 | { 45 | #pragma clang diagnostic push 46 | #pragma clang diagnostic ignored "-Wnonnull" 47 | [verifyCountWithMockTestCase(nil, times(1), mockTestCase) removeAllObjects]; 48 | #pragma clang diagnostic pop 49 | 50 | assertThat(mockTestCase.failureDescription, 51 | is(@"Argument passed to verifyCount() should be a mock, but was nil")); 52 | } 53 | 54 | - (void)testVerify_WithNonMock_ShouldGiveError 55 | { 56 | NSMutableArray *realArray = [NSMutableArray array]; 57 | 58 | [verifyWithMockTestCase(realArray, mockTestCase) removeAllObjects]; 59 | 60 | assertThat(mockTestCase.failureDescription, 61 | startsWith(@"Argument passed to verify() should be a mock, but was type ")); 62 | } 63 | 64 | - (void)testVerifyCount_WithNonMock_ShouldGiveError 65 | { 66 | NSMutableArray *realArray = [NSMutableArray array]; 67 | 68 | [verifyCountWithMockTestCase(realArray, times(1), mockTestCase) removeAllObjects]; 69 | 70 | assertThat(mockTestCase.failureDescription, 71 | startsWith(@"Argument passed to verifyCount() should be a mock, but was type ")); 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/DummyObject.h: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | @import Foundation; 6 | 7 | @class MKTInvocation; 8 | @class MKTInvocationMatcher; 9 | @class MKTLocation; 10 | 11 | 12 | @interface DummyObject : NSObject 13 | 14 | + (NSInvocation *)invocationWithNoArgs; 15 | + (NSInvocation *)differentInvocationWithNoArgs; 16 | + (NSInvocation *)invocationWithObjectArg:(__unsafe_unretained id)argument; 17 | + (NSInvocation *)differentInvocationWithObjectArg:(__unsafe_unretained id)argument; 18 | + (NSInvocation *)invocationWithClassArg:(Class)argument; 19 | + (NSInvocation *)invocationWithSelectorArg:(SEL)argument; 20 | + (NSInvocation *)invocationWithBoolArg:(BOOL)argument; 21 | + (NSInvocation *)invocationWithCharArg:(char)argument; 22 | + (NSInvocation *)invocationWithIntArg:(int)argument; 23 | + (NSInvocation *)invocationWithShortArg:(short)argument; 24 | + (NSInvocation *)invocationWithLongArg:(long)argument; 25 | + (NSInvocation *)invocationWithLongLongArg:(long long)argument; 26 | + (NSInvocation *)invocationWithIntegerArg:(NSInteger)argument; 27 | + (NSInvocation *)invocationWithUnsignedCharArg:(unsigned char)argument; 28 | + (NSInvocation *)invocationWithUnsignedIntArg:(unsigned int)argument; 29 | + (NSInvocation *)invocationWithUnsignedShortArg:(unsigned short)argument; 30 | + (NSInvocation *)invocationWithUnsignedLongArg:(unsigned long)argument; 31 | + (NSInvocation *)invocationWithUnsignedLongLongArg:(unsigned long long)argument; 32 | + (NSInvocation *)invocationWithUnsignedIntegerArg:(NSUInteger)argument; 33 | + (NSInvocation *)invocationWithFloatArg:(float)argument; 34 | + (NSInvocation *)invocationWithDoubleArg:(double)argument; 35 | + (NSInvocation *)invocationWithObjectArg1:(__unsafe_unretained id)argument1 objectArg2:(__unsafe_unretained id)argument2; 36 | + (NSInvocation *)invocationWithObjectArg:(__unsafe_unretained id)argument1 intArg:(int)argument2; 37 | + (NSInvocation *)invocationWithIntArg:(int)argument1 floatArg:(float)argument2; 38 | 39 | @end 40 | 41 | 42 | MKTInvocation *wrappedInvocation(NSInvocation *invocation); 43 | MKTInvocation *wrappedInvocationWithLocation(NSInvocation *invocation, MKTLocation *location); 44 | MKTInvocationMatcher *matcherForInvocation(NSInvocation *invocation); 45 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyAndStubTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by David Ferrai 5 | 6 | #import 7 | #import 8 | 9 | #import "MockTestCase.h" 10 | @import XCTest; 11 | 12 | /* 13 | A --(useC:)--> B --(processStringFromC:)--> C 14 | */ 15 | 16 | @interface C: NSObject 17 | @property (nonatomic, copy) NSString *text; 18 | @end 19 | 20 | @implementation C 21 | @end 22 | 23 | @interface B: NSObject 24 | - (void)processStringFromC:(NSString *)string; 25 | @end 26 | 27 | @implementation B 28 | - (void)processStringFromC:(NSString *)string { } 29 | @end 30 | 31 | 32 | @interface A: NSObject 33 | 34 | - (void)useC:(C *)c; 35 | 36 | @property (nonatomic, strong, readonly) B *b; // always uninitialized 37 | 38 | @end 39 | 40 | @implementation A 41 | 42 | - (void)useC:(C *)c 43 | { 44 | [self.b processStringFromC:c.text]; 45 | } 46 | 47 | @end 48 | 49 | @interface VerifyAndStubTests : XCTestCase 50 | @end 51 | 52 | @implementation VerifyAndStubTests 53 | { 54 | MockTestCase *mockTestCase; 55 | } 56 | 57 | - (void)setUp 58 | { 59 | [super setUp]; 60 | mockTestCase = [[MockTestCase alloc] init]; 61 | } 62 | 63 | - (void)testStub_whileVerify 64 | { 65 | B *b = mock(B.class); 66 | C *c = mock(C.class); 67 | [given(c.text) willReturn:@"test"]; 68 | 69 | [b processStringFromC:c.text]; 70 | 71 | [verify(b) processStringFromC:c.text]; 72 | } 73 | 74 | - (void)testVerify_whileNotStubbing_ShouldFail 75 | { 76 | A *a = [[A alloc] init]; // A is not initialized with B 77 | B *b = mock(B.class); // not used at all 78 | C *c = [[C alloc] init]; // not stubbing 79 | 80 | [a useC:c]; 81 | 82 | [verifyWithMockTestCase(b, mockTestCase) processStringFromC:c.text]; 83 | assertThat(@(mockTestCase.failureCount), is(@1)); 84 | } 85 | 86 | - (void)testVerify_whileStubbing_ShouldFail 87 | { 88 | A *a = [[A alloc] init]; // A is not initialized with B 89 | B *b = mock(B.class); // not used at all 90 | C *c = mock(C.class); // stubbing 91 | 92 | [a useC:c]; 93 | 94 | [verifyWithMockTestCase(b, mockTestCase) processStringFromC:c.text]; 95 | assertThat(@(mockTestCase.failureCount), is(@1)); 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /Sources/OCMockito/Mocking/MKTProtocolMock.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTProtocolMock.h" 6 | 7 | #import 8 | 9 | 10 | @interface MKTProtocolMock () 11 | @property (nonatomic, assign, readonly) BOOL includeOptionalMethods; 12 | @end 13 | 14 | @implementation MKTProtocolMock 15 | 16 | - (instancetype)initWithProtocol:(Protocol *)aProtocol 17 | includeOptionalMethods:(BOOL)includeOptionalMethods 18 | { 19 | self = [super init]; 20 | if (self) 21 | { 22 | _mockedProtocol = aProtocol; 23 | _includeOptionalMethods = includeOptionalMethods; 24 | } 25 | return self; 26 | } 27 | 28 | - (NSString *)description 29 | { 30 | return [NSString stringWithFormat:@"mock implementer of %@ protocol", 31 | NSStringFromProtocol(self.mockedProtocol)]; 32 | } 33 | 34 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 35 | { 36 | struct objc_method_description methodDescription = 37 | protocol_getMethodDescription(self.mockedProtocol, aSelector, YES, YES); 38 | if (!methodDescription.name && self.includeOptionalMethods) 39 | methodDescription = protocol_getMethodDescription(self.mockedProtocol, aSelector, NO, YES); 40 | if (!methodDescription.name) 41 | methodDescription = protocol_getMethodDescription(self.mockedProtocol, aSelector, YES, NO); 42 | if (!methodDescription.name && self.includeOptionalMethods) 43 | methodDescription = protocol_getMethodDescription(self.mockedProtocol, aSelector, NO, NO); 44 | if (!methodDescription.name) 45 | return nil; 46 | return [NSMethodSignature signatureWithObjCTypes:methodDescription.types]; 47 | } 48 | 49 | #pragma mark - NSObject protocol 50 | 51 | - (BOOL)conformsToProtocol:(Protocol *)aProtocol 52 | { 53 | return protocol_conformsToProtocol(self.mockedProtocol, aProtocol); 54 | } 55 | 56 | - (BOOL)respondsToSelector:(SEL)aSelector 57 | { 58 | return [self methodSignatureForSelector:aSelector] != nil; 59 | } 60 | 61 | #pragma mark - Support being called as isEqual: argument 62 | 63 | - (BOOL)isNSArray__ { return NO; } 64 | - (BOOL)isNSData__ { return NO; } 65 | - (BOOL)isNSDictionary__ { return NO; } 66 | - (BOOL)isNSNumber__ { return NO; } 67 | - (BOOL)isNSString__ { return NO; } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyProtocolTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import 6 | #import 7 | 8 | #import "MockTestCase.h" 9 | @import XCTest; 10 | 11 | 12 | @interface VerifyProtocolTests : XCTestCase 13 | @end 14 | 15 | @implementation VerifyProtocolTests 16 | { 17 | id mockLock; 18 | id mockDelegate; 19 | MockTestCase *mockTestCase; 20 | NSKeyedArchiver *archiver; 21 | } 22 | 23 | - (void)setUp 24 | { 25 | [super setUp]; 26 | mockLock = mockProtocol(@protocol(NSLocking)); 27 | mockDelegate = mockProtocol(@protocol(NSKeyedArchiverDelegate)); 28 | mockTestCase = [[MockTestCase alloc] init]; 29 | #pragma clang diagnostic push 30 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 31 | archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:[NSMutableData data]]; 32 | #pragma clang diagnostic pop 33 | } 34 | 35 | - (void)tearDown 36 | { 37 | [archiver finishEncoding]; 38 | mockLock = nil; 39 | mockDelegate = nil; 40 | mockTestCase = nil; 41 | archiver = nil; 42 | [super tearDown]; 43 | } 44 | 45 | - (void)testInvokingMethod_ShouldPassVerify 46 | { 47 | [mockLock lock]; 48 | 49 | [verify(mockLock) lock]; 50 | } 51 | 52 | - (void)testNotInvokingMethod_ShouldFailVerify 53 | { 54 | [verifyWithMockTestCase(mockLock, mockTestCase) lock]; 55 | 56 | assertThat(@(mockTestCase.failureCount), is(@1)); 57 | } 58 | 59 | - (void)testInvokingWithEqualObjectArguments_ShouldPassVerify 60 | { 61 | [mockDelegate archiver:archiver willEncodeObject:@"same"]; 62 | 63 | [verify(mockDelegate) archiver:archiver willEncodeObject:@"same"]; 64 | } 65 | 66 | - (void)testInvokingWithDifferentObjectArguments_ShouldFailVerify 67 | { 68 | [mockDelegate archiver:archiver willEncodeObject:@"same"]; 69 | 70 | [verifyWithMockTestCase(mockDelegate, mockTestCase) archiver:archiver willEncodeObject:@"different"]; 71 | 72 | assertThat(@(mockTestCase.failureCount), is(@1)); 73 | } 74 | 75 | - (void)testInvokingWithArgumentMatcherSatisfied_ShouldPassVerify 76 | { 77 | [mockDelegate archiver:archiver willEncodeObject:@"same"]; 78 | 79 | [verify(mockDelegate) archiver:archiver willEncodeObject:equalTo(@"same")]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/MKTParseCallStackTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTParseCallStack.h" 6 | 7 | #import 8 | @import XCTest; 9 | 10 | 11 | @interface MKTParseCallStackTests : XCTestCase 12 | @end 13 | 14 | @implementation MKTParseCallStackTests 15 | 16 | - (void)testShouldParseModuleNames_WithShortAndLongNames 17 | { 18 | NSString *ordinary = 19 | @"3 ExampleTests 0x0000000118446bee -[MKTBaseMockObject forwardInvocation:] + 91"; 20 | NSString *longModuleName = 21 | @"3 ThisIsAMuchLongerModuleName 0x0000000118446bee -[MKTBaseMockObject forwardInvocation:] + 91"; 22 | 23 | NSArray *result = MKTParseCallStack(@[ ordinary, longModuleName ]); 24 | 25 | assertThat(result, containsIn(@[ 26 | hasProperty(@"moduleName", @"ExampleTests"), 27 | hasProperty(@"moduleName", @"ThisIsAMuchLongerModuleName"), 28 | ])); 29 | } 30 | 31 | - (void)testShouldParseInstructions_SkippingOver64BitAddresses_FromFunctionsAndMethods 32 | { 33 | NSString *function = 34 | @"5 CoreFoundation 0x000000010e9f9a98 _CF_forwarding_prep_0 + 120"; 35 | NSString *method = 36 | @"6 ExampleTests 0x0000000118430edc -[ExampleTests testVerifyWithMatcherForPrimitive] + 92"; 37 | 38 | NSArray *result = MKTParseCallStack(@[ function, method ]); 39 | 40 | assertThat(result, containsIn(@[ 41 | hasProperty(@"instruction", @"_CF_forwarding_prep_0 + 120"), 42 | hasProperty(@"instruction", @"-[ExampleTests testVerifyWithMatcherForPrimitive] + 92"), 43 | ])); 44 | } 45 | 46 | - (void)testShouldParseInstructions_SkippingOver32BitAddresses_FromFunctionsAndMethods 47 | { 48 | NSString *function = 49 | @"5 CoreFoundation 0x0e9f9a98 _CF_forwarding_prep_0 + 120"; 50 | NSString *method = 51 | @"6 ExampleTests 0x18430edc -[ExampleTests testVerifyWithMatcherForPrimitive] + 92"; 52 | 53 | NSArray *result = MKTParseCallStack(@[ function, method ]); 54 | 55 | assertThat(result, containsIn(@[ 56 | hasProperty(@"instruction", @"_CF_forwarding_prep_0 + 120"), 57 | hasProperty(@"instruction", @"-[ExampleTests testVerifyWithMatcherForPrimitive] + 92"), 58 | ])); 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Sources/OCMockito/Stubbing/MKTInvocationContainer.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTInvocationContainer.h" 6 | 7 | #import "MKTStubbedInvocationMatcher.h" 8 | #import "NSInvocation+OCMockito.h" 9 | #import "MKTInvocation.h" 10 | 11 | 12 | @interface MKTInvocationContainer () 13 | @property (nonatomic, strong, readonly) NSMutableArray *mutableRegisteredInvocations; 14 | @property (nonatomic, strong) MKTStubbedInvocationMatcher *invocationForStubbing; 15 | @property (nonatomic, strong, readonly) NSMutableArray *stubbed; 16 | @end 17 | 18 | @implementation MKTInvocationContainer 19 | 20 | 21 | - (instancetype)init 22 | { 23 | self = [super init]; 24 | if (self) 25 | { 26 | _mutableRegisteredInvocations = [[NSMutableArray alloc] init]; 27 | _stubbed = [[NSMutableArray alloc] init]; 28 | } 29 | return self; 30 | } 31 | 32 | - (NSArray *)registeredInvocations 33 | { 34 | return self.mutableRegisteredInvocations; 35 | } 36 | 37 | - (void)setInvocationForPotentialStubbing:(NSInvocation *)invocation 38 | { 39 | [invocation mkt_retainArgumentsWithWeakTarget]; 40 | MKTInvocation *wrappedInvocation = [[MKTInvocation alloc] initWithInvocation:invocation]; 41 | [self.mutableRegisteredInvocations addObject:wrappedInvocation]; 42 | 43 | MKTStubbedInvocationMatcher *s = [[MKTStubbedInvocationMatcher alloc] init]; 44 | [s setExpectedInvocation:invocation]; 45 | self.invocationForStubbing = s; 46 | } 47 | 48 | - (void)setMatcher:(id )matcher atIndex:(NSUInteger)argumentIndex 49 | { 50 | [self.invocationForStubbing setMatcher:matcher atIndex:argumentIndex]; 51 | } 52 | 53 | - (void)addAnswer:(id )answer 54 | { 55 | [self.mutableRegisteredInvocations removeLastObject]; 56 | 57 | [self.invocationForStubbing addAnswer:answer]; 58 | [self.stubbed insertObject:self.invocationForStubbing atIndex:0]; 59 | } 60 | 61 | - (nullable MKTStubbedInvocationMatcher *)findAnswerFor:(NSInvocation *)invocation 62 | { 63 | for (MKTStubbedInvocationMatcher *s in [self.stubbed copy]) 64 | if ([s matches:invocation]) 65 | return s; 66 | return nil; 67 | } 68 | 69 | - (BOOL)isStubbingCopyMethod 70 | { 71 | return self.registeredInvocations.count > 0 && 72 | [self.registeredInvocations[0] invocation].selector == @selector(copy); 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Tests/OCMockitoTests/VerifyCountAtLeastTimesTests.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | // Contribution by Markus Gasser 5 | 6 | #import 7 | #import 8 | 9 | #import "MockTestCase.h" 10 | @import XCTest; 11 | 12 | 13 | @interface VerifyCountAtLeastTimesTests : XCTestCase 14 | @end 15 | 16 | @implementation VerifyCountAtLeastTimesTests 17 | { 18 | NSMutableArray *mockArray; 19 | MockTestCase *mockTestCase; 20 | } 21 | 22 | - (void)setUp 23 | { 24 | [super setUp]; 25 | mockArray = mock([NSMutableArray class]); 26 | mockTestCase = [[MockTestCase alloc] init]; 27 | } 28 | 29 | - (void)tearDown 30 | { 31 | mockArray = nil; 32 | mockTestCase = nil; 33 | [super tearDown]; 34 | } 35 | 36 | - (void)callRemoveAllObjectsTimes:(int)count 37 | { 38 | for (int i = 0; i < count; ++i) 39 | [mockArray removeAllObjects]; 40 | } 41 | 42 | - (void)testAtLeast_WithTooFewInvocations_ShouldFail 43 | { 44 | [self callRemoveAllObjectsTimes:1]; 45 | 46 | [verifyCountWithMockTestCase(mockArray, atLeast(2), mockTestCase) removeAllObjects]; 47 | 48 | assertThat(@(mockTestCase.failureCount), is(@1)); 49 | } 50 | 51 | - (void)testAtLeast_WithExactCount_ShouldPass 52 | { 53 | [self callRemoveAllObjectsTimes:1]; 54 | 55 | [verifyCount(mockArray, atLeast(1)) removeAllObjects]; 56 | } 57 | 58 | - (void)testAtLeast_WithMoreInvocations_ShouldPass 59 | { 60 | [self callRemoveAllObjectsTimes:3]; 61 | 62 | [verifyCount(mockArray, atLeast(2)) removeAllObjects]; 63 | } 64 | 65 | - (void)testAtLeastOnce_WithTooFewInvocations_ShouldFail 66 | { 67 | [self callRemoveAllObjectsTimes:0]; 68 | 69 | [verifyCountWithMockTestCase(mockArray, atLeastOnce(), mockTestCase) removeAllObjects]; 70 | 71 | assertThat(@(mockTestCase.failureCount), is(@1)); 72 | } 73 | 74 | - (void)testAtLeastOnce_WithExactCount_ShouldPass 75 | { 76 | [self callRemoveAllObjectsTimes:1]; 77 | 78 | [verifyCount(mockArray, atLeastOnce()) removeAllObjects]; 79 | } 80 | 81 | - (void)testAtLeastOnce_WithMoreInvocations_ShouldPass 82 | { 83 | [self callRemoveAllObjectsTimes:2]; 84 | 85 | [verifyCount(mockArray, atLeastOnce()) removeAllObjects]; 86 | } 87 | 88 | - (void)testAtLastTwoFailure_ShouldStateExpectedNumberOfInvocations 89 | { 90 | [self callRemoveAllObjectsTimes:1]; 91 | 92 | [verifyCountWithMockTestCase(mockArray, atLeast(2), mockTestCase) removeAllObjects]; 93 | 94 | assertThat(mockTestCase.failureDescription, 95 | startsWith(@"Wanted at least 2 times but was called 1 time.")); 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /Sources/OCMockito/Helpers/ReturnValueSetters/MKTReturnValueSetterChain.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTReturnValueSetterChain.h" 6 | 7 | #import "MKTObjectReturnSetter.h" 8 | #import "MKTClassReturnSetter.h" 9 | #import "MKTCharReturnSetter.h" 10 | #import "MKTBoolReturnSetter.h" 11 | #import "MKTLongLongReturnSetter.h" 12 | #import "MKTIntReturnSetter.h" 13 | #import "MKTShortReturnSetter.h" 14 | #import "MKTLongReturnSetter.h" 15 | #import "MKTUnsignedCharReturnSetter.h" 16 | #import "MKTUnsignedIntReturnSetter.h" 17 | #import "MKTUnsignedShortReturnSetter.h" 18 | #import "MKTUnsignedLongReturnSetter.h" 19 | #import "MKTUnsignedLongLongReturnSetter.h" 20 | #import "MKTFloatReturnSetter.h" 21 | #import "MKTDoubleReturnSetter.h" 22 | #import "MKTStructReturnSetter.h" 23 | 24 | 25 | MKTReturnValueSetter *MKTReturnValueSetterChain(void) 26 | { 27 | static MKTReturnValueSetter *chain = nil; 28 | if (!chain) 29 | { 30 | MKTReturnValueSetter *structSetter = [[MKTStructReturnSetter alloc] initWithSuccessor:nil]; 31 | MKTReturnValueSetter *doubleSetter = [[MKTDoubleReturnSetter alloc] initWithSuccessor:structSetter]; 32 | MKTReturnValueSetter *floatSetter = [[MKTFloatReturnSetter alloc] initWithSuccessor:doubleSetter]; 33 | MKTReturnValueSetter *uLongLongSetter = [[MKTUnsignedLongLongReturnSetter alloc] initWithSuccessor:floatSetter]; 34 | MKTReturnValueSetter *uLongSetter = [[MKTUnsignedLongReturnSetter alloc] initWithSuccessor:uLongLongSetter]; 35 | MKTReturnValueSetter *uShortSetter = [[MKTUnsignedShortReturnSetter alloc] initWithSuccessor:uLongSetter]; 36 | MKTReturnValueSetter *uIntSetter = [[MKTUnsignedIntReturnSetter alloc] initWithSuccessor:uShortSetter]; 37 | MKTReturnValueSetter *uCharSetter = [[MKTUnsignedCharReturnSetter alloc] initWithSuccessor:uIntSetter]; 38 | MKTReturnValueSetter *longLongSetter = [[MKTLongLongReturnSetter alloc] initWithSuccessor:uCharSetter]; 39 | MKTReturnValueSetter *longSetter = [[MKTLongReturnSetter alloc] initWithSuccessor:longLongSetter]; 40 | MKTReturnValueSetter *shortSetter = [[MKTShortReturnSetter alloc] initWithSuccessor:longSetter]; 41 | MKTReturnValueSetter *intSetter = [[MKTIntReturnSetter alloc] initWithSuccessor:shortSetter]; 42 | MKTReturnValueSetter *boolSetter = [[MKTBoolReturnSetter alloc] initWithSuccessor:intSetter]; 43 | MKTReturnValueSetter *charSetter = [[MKTCharReturnSetter alloc] initWithSuccessor:boolSetter]; 44 | MKTReturnValueSetter *classSetter = [[MKTClassReturnSetter alloc] initWithSuccessor:charSetter]; 45 | MKTReturnValueSetter *objectSetter = [[MKTObjectReturnSetter alloc] initWithSuccessor:classSetter]; 46 | chain = objectSetter; 47 | } 48 | return chain; 49 | } 50 | -------------------------------------------------------------------------------- /Sources/OCMockito/Core/MKTMockingProgress.m: -------------------------------------------------------------------------------- 1 | // OCMockito by Jon Reid, https://qualitycoding.org 2 | // Copyright 2011 Jonathan M. Reid. https://github.com/jonreid/OCMockito/blob/main/LICENSE.txt 3 | // SPDX-License-Identifier: MIT 4 | 5 | #import "MKTMockingProgress.h" 6 | 7 | #import "MKTInvocationMatcher.h" 8 | #import "MKTOngoingStubbing.h" 9 | #import "MKTVerificationMode.h" 10 | #import "MKTBaseMockObject.h" 11 | 12 | @interface MKTMockingProgress () 13 | @property (nonatomic, assign, readwrite) MKTTestLocation testLocation; 14 | @property (nonatomic, strong) MKTInvocationMatcher *invocationMatcher; 15 | @property (nonatomic, strong) id verificationMode; 16 | @property (nonatomic, strong) MKTBaseMockObject *verificationModeMockObject; 17 | 18 | @property (nonatomic, strong) MKTOngoingStubbing *ongoingStubbing; 19 | @end 20 | 21 | @implementation MKTMockingProgress 22 | 23 | + (instancetype)sharedProgress 24 | { 25 | static id sharedProgress = nil; 26 | if (!sharedProgress) 27 | sharedProgress = [[self alloc] init]; 28 | return sharedProgress; 29 | } 30 | 31 | - (void)reset 32 | { 33 | self.invocationMatcher = nil; 34 | self.verificationMode = nil; 35 | self.ongoingStubbing = nil; 36 | } 37 | 38 | - (void)stubbingStartedAtLocation:(MKTTestLocation)location 39 | { 40 | [self setTestLocation:location]; 41 | } 42 | 43 | - (void)reportOngoingStubbing:(MKTOngoingStubbing *)ongoingStubbing 44 | { 45 | self.ongoingStubbing = ongoingStubbing; 46 | } 47 | 48 | - (MKTOngoingStubbing *)pullOngoingStubbing 49 | { 50 | MKTOngoingStubbing *result = self.ongoingStubbing; 51 | self.ongoingStubbing = nil; 52 | return result; 53 | } 54 | 55 | - (void)verificationStarted:(id )mode atLocation:(MKTTestLocation)location withMock:(MKTBaseMockObject *)mock 56 | { 57 | self.verificationMode = mode; 58 | self.verificationModeMockObject = mock; 59 | [self setTestLocation:location]; 60 | } 61 | 62 | - (nullable id )pullVerificationModeWithMock:(MKTBaseMockObject *)mock 63 | { 64 | if (self.verificationMode != nil && [mock isEqual:self.verificationModeMockObject]) { 65 | id result = self.verificationMode; 66 | self.verificationMode = nil; 67 | return result; 68 | } else { 69 | return nil; 70 | } 71 | } 72 | 73 | - (void)setMatcher:(id )matcher forArgument:(NSUInteger)index 74 | { 75 | if (!self.invocationMatcher) 76 | self.invocationMatcher = [[MKTInvocationMatcher alloc] init]; 77 | [self.invocationMatcher setMatcher:matcher atIndex:index]; 78 | } 79 | 80 | - (MKTInvocationMatcher *)pullInvocationMatcher 81 | { 82 | MKTInvocationMatcher *result = self.invocationMatcher; 83 | self.invocationMatcher = nil; 84 | return result; 85 | } 86 | 87 | - (void)setOngoingStubbing:(MKTOngoingStubbing *)ongoingStubbing 88 | { 89 | @synchronized (self) 90 | { 91 | _ongoingStubbing = ongoingStubbing; 92 | } 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /OCMockito.xcodeproj/xcshareddata/xcschemes/OCMockito.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 54 | 55 | 61 | 62 | 63 | 64 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | --------------------------------------------------------------------------------