Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import "Presenter.h"
#import "ViewController.h"
@interface ViewControllerTest : XCTestCase {
id mockPresenter_;
ViewController *viewController_;
}
@end
@implementation ViewControllerTest
- (void)setUp {
[super setUp];
mockPresenter_ = OCMStrictClassMock([Presenter class]);
OCMExpect([mockPresenter_ setViewController:OCMOCK_ANY]);
viewController_ = [[ViewController alloc] initWithPresenter:mockPresenter_];
}
- (void)tearDown {
[mockPresenter_ verify];
[super tearDown];
}
- (void)testInit {
OCMVerify([mockPresenter_ setViewController:viewController_]);
}
- (void)testViewDidLoad {
OCMExpect([mockPresenter_ leftNavigationButtons]);
OCMExpect([mockPresenter_ rightNavigationButtons]);
OCMExpect([mockPresenter_ viewLoaded]);
[viewController_ viewDidLoad];
OCMVerify([mockPresenter_ leftNavigationButtons]);
OCMVerify([mockPresenter_ rightNavigationButtons]);
OCMVerify([mockPresenter_ viewLoaded]);
}
- (void)testDismissViewController {
id mockNavigationController = OCMStrictClassMock([UINavigationController class]);
id mockViewController = [OCMockObject partialMockForObject:viewController_];
[[[mockViewController expect] andReturn:mockNavigationController] navigationController];
OCMExpect([mockNavigationController dismissViewControllerAnimated:YES completion:nil]);
[viewController_ dismissViewControllerAnimated:YES withCompletionBlock:nil];
OCMVerify([mockNavigationController dismissViewControllerAnimated:YES completion:nil]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment