0

I have a class named "GeolocationManager" that handles a CLLocationManager object and delegate responses.

- (void)getGeolocationForClient:(id<GeolocationManagerDelegate>)client
{
    _delegate = client;
    _locationManager = [self createLocationManager];
    _locationManager.delegate = self;
    _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    [_locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
   // do some stuff
}

createLocationManager is a public method ready to be stubbed

- (CLLocationManager *)createLocationManager
{
    return [[CLLocationManager alloc] init];
}

What I want to achieve is to test that when user denies being geolocated the CLLocationManagerDelegate method locationManager:didFailWithError: is being called on my GeolocationManager object.

My test method below does not seem to be working

- (void)testOnUserDenial
{
    GeolocationManager *geolocationManager = [[GeolocationManager alloc] init];
    id geolocationManagerTest = [OCMockObject partialMockForObject:geolocationManager];

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    id locationManagerTest = [OCMockObject partialMockForObject:locationManager];

    [[[locationManagerTest stub] andReturnValue:@(kCLAuthorizationStatusDenied)] authorizationStatus];
    [[[geolocationManagerTest stub] andReturn:locationManagerTest] createLocationManager];

    [[geolocationManagerTest expect] locationManager:[OCMArg any] didFailWithError:[OCMArg any]];

    [geolocationManagerTest getGeolocationForClient:[OCMArg any]];

    [geolocationManagerTest verify];
}

Name: NSInternalInconsistencyException File: Unknown Line: Unknown Reason: OCPartialMockObject[GeolocationManager]: expected method was not invoked: locationManager:OCPartialMockObject[CLLocationManager] didFailWithError:

Mutawe
  • 6,464
  • 3
  • 47
  • 90
ennzhed
  • 186
  • 2
  • 13

1 Answers1

0

Have you tried using OCMOCK_VALUE(kCLAuthorizationStatusDenied) for the returnValue?

Ilea Cristian
  • 5,741
  • 1
  • 23
  • 37
  • [[[locationManagerTest stub] andReturnValue:OCMOCK_VALUE(kCLAuthorizationStatusDenied)] authorizationStatus]; Cannot build, I got : "semantic issue - address expression must be an Ivalue or a function designator". – ennzhed Dec 05 '13 at 09:06
  • Does your OCMocks version of `OCMOCK_VALUE` is the same as https://github.com/erikdoe/ocmock/blob/master/Source/OCMock/OCMArg.h ? – Ilea Cristian Dec 05 '13 at 09:14
  • My version differs. My version is 2.2.1 from http://ocmock.org/download/ With the OCMArg.h version you provided I can build but still got the same error : expected method was not invoked: locationManager: didFailWithError: – ennzhed Dec 05 '13 at 09:18