Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
- (void) testAnimation {
id mockGestureRecognizer = [OCMockObject mockForClass:[UIPanGestureRecognizer class]];
CGPoint expectedPoint = CGPointMake(-10.0f, 20.0f); //velocity is in CGPoint unit
[(UIPanGestureRecognizer *)[[mockGestureRecognizer expect] andReturnValue:OCMOCK_VALUE(expectedPoint)] velocityInView:v];
id partialMockPinView = [OCMockObject partialMockForObject:v];
[[partialMockPinView expect] updateSliderColor:delta];
NSTimeInterval expectedAnimationDuration = fabs(expectedPoint.x) * 0.002 * 0.2;
id mockView = [OCMockObject mockForClass:[UIView class]];
[[[mockView expect] andDo:^(NSInvocation *i) {
void (^animation)(void) = nil;
void (^completion)(void) = nil;
[i getArgument:&animation atIndex:3];
[i getArgument:&completion atIndex:4];
if(completion) {
}] animateWithDuration:expectedAnimationDuration
animations:[OCMArg isNotNil]
__block BOOL finished = NO;
[v animateLockWithGestureRecognizer:mockGestureRecognizer
finished = YES;
XCTAssertTrue(finished == YES, @"Should finished");
XCTAssertTrue(CGRectEqualToRect(expectedRect, v.lockImageView.frame), @”Wrong frame”);
[mockGestureRecognizer verify];
[partialMockPinView verify]; [partialMockPinView stopMocking];
[mockView verify]; [mockView stopMocking];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment