If you are testing that your code responds properly to the UIPanGestureRecognizer
, write the test around the target method of the gesture recognizer.
// If you have this...
UIPanGestureRecognizer *pgr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
[self.scrollView addGestureRecognizer:pgr];
// With this...
- (void)didPan:(UIPanGestureRecognizer *)pgr
{
switch (pgr.state):
{
case UIGestureRecognizerStateEnded:
[self doSomething];
break;
default:
}
}
// Then you could do this
id gestureMock = [OCMockObject mockForClass:[UIPanGestureRecognizer class]];
[[[gestureMock stub] andReturn:UIPanGestureRecognizerStateEnded] state];
id objectUnderTest = [OCMockObject partialMockForObject:[MyClass new]];
[[objectUnderTest expect] doSomething];
// Make the call
[objectUnderTest didPan:gestureMock];
[objectUnderTest verify];