Skip to content

Instantly share code, notes, and snippets.

@ydzheng
Last active Aug 29, 2015
Embed
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];
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