-
-
Save ydzheng/1d96c907c693de143da0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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