Created
March 7, 2012 23:38
-
-
Save nwg/1997301 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @implementation ClassMockTest | |
| @synthesize mockAlert = mockAlert_; | |
| - (BOOL)shouldRunOnMainThread { return YES; } | |
| - (void)showAlert { | |
| UIAlertView *alertView = [UIAlertView alloc]; | |
| alertView = [alertView initWithTitle:nil message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; | |
| [alertView show]; | |
| } | |
| - (void)setUp { | |
| [UIAlertView startMockingClass]; | |
| self.mockAlert = [OCMockObject mockForClass:[UIAlertView class]]; | |
| } | |
| - (void)tearDown { | |
| [UIAlertView verify]; | |
| [UIAlertView stopMockingClass]; | |
| [self.mockAlert verify]; | |
| } | |
| - (void)handleException:(NSException *)exception { | |
| [ClassMockForwarder removeAllMocks]; | |
| } | |
| - (void)testSomething { | |
| // Expect an allocation | |
| [[[UIAlertView expect] andReturnFromBlock:^{ return self.mockAlert; }] alloc]; | |
| [[[self.mockAlert expect] andReturn:self.mockAlert] initWithTitle:OCMOCK_ANY message:OCMOCK_ANY delegate:OCMOCK_ANY cancelButtonTitle:OCMOCK_ANY otherButtonTitles:OCMOCK_ANY, nil]; | |
| // Alert should be shown | |
| [[self.mockAlert expect] show]; | |
| [self showAlert]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment