Skip to content

Instantly share code, notes, and snippets.

@ydzheng
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydzheng/1d96c907c693de143da0 to your computer and use it in GitHub Desktop.
Save ydzheng/1d96c907c693de143da0 to your computer and use it in GitHub Desktop.
- (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];
animation();
if(completion) {
completion();
}
}] animateWithDuration:expectedAnimationDuration
animations:[OCMArg isNotNil]
completion:OCMOCK_ANY];
__block BOOL finished = NO;
[v animateLockWithGestureRecognizer:mockGestureRecognizer
completion:^{
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