I find mocking pointers (specifically NSError’s) a bit of a pain in OCMockito. But here is a way I get things working if I just want to set an expectation, and have it return NULL.


@interface Handler : NSObject
- (BOOL)playTrack:(NSString *)track error:(NSError **)errorPtr;


#import <XCTest/XCTest.h>

#import <OCHamcrestIOS/OCHamcrestIOS.h>
#import <OCMockitoIOS/OCMockitoIOS.h>

#import "Player.h"

@interface PlayerTest : XCTestCase
@property (nonatomic, strong) Player *player;
@property (nonatomic, strong) Handler *mockHandler;

@implementation PlayerTest

- (void)setUp {
    [super setUp];
    self.mockHandler = mock([Handler class]);

    self.player = [[Player alloc] initWithHandler:self.mockHandler];

- (void)testPlayTrack {

    // given
    [[given([self.mockHandler playTrack:anything() error:NULL]) withMatcher:anything() forArgument:1] willReturnBool:YES];

    // when
    [self.player playURL:@"spotify.track.xxx" error:NULL];

    // then
    [verify(self.mockHandler) playTrack:anything() error:NULL];