#import #import #import #import #import "RNNTestRootViewCreator.h" #import #import #import #import #import "RNNLayoutManager.h" @interface MockUIApplication : NSObject -(UIWindow *)keyWindow; @end @implementation MockUIApplication - (UIWindow *)keyWindow { return [UIWindow new]; } @end @interface MockUINavigationController : RNNStackController @property (nonatomic, strong) NSArray* willReturnVCs; @end @implementation MockUINavigationController -(NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated { return self.willReturnVCs; } -(NSArray *)popToRootViewControllerAnimated:(BOOL)animated { return self.willReturnVCs; } @end @interface RNNCommandsHandlerTest : XCTestCase @property (nonatomic, strong) RNNCommandsHandler* uut; @property (nonatomic, strong) id modalManager; @property (nonatomic, strong) RNNComponentViewController* vc1; @property (nonatomic, strong) RNNComponentViewController* vc2; @property (nonatomic, strong) RNNComponentViewController* vc3; @property (nonatomic, strong) MockUINavigationController* nvc; @property (nonatomic, strong) id mainWindow; @property (nonatomic, strong) id sharedApplication; @property (nonatomic, strong) id controllerFactory; @property (nonatomic, strong) id overlayManager; @property (nonatomic, strong) id eventEmmiter; @end @implementation RNNCommandsHandlerTest - (void)setUp { [super setUp]; self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]]; self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]]; self.overlayManager = [OCMockObject partialMockForObject:[RNNOverlayManager new]]; self.modalManager = [OCMockObject partialMockForObject:[RNNModalManager new]]; self.controllerFactory = [OCMockObject partialMockForObject:[[RNNControllerFactory alloc] initWithRootViewCreator:nil eventEmitter:self.eventEmmiter store:nil componentRegistry:nil andBridge:nil]]; self.uut = [[RNNCommandsHandler alloc] initWithControllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:self.modalManager overlayManager:self.overlayManager mainWindow:_mainWindow]; self.vc1 = [RNNComponentViewController new]; self.vc2 = [RNNComponentViewController new]; self.vc3 = [RNNComponentViewController new]; _nvc = [[MockUINavigationController alloc] init]; [_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]]; OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow); } - (void)testAssertReadyForEachMethodThrowsExceptoins { NSArray* methods = [self getPublicMethodNamesForObject:self.uut]; [self.uut setReadyToReceiveCommands:false]; for (NSString* methodName in methods) { SEL s = NSSelectorFromString(methodName); IMP imp = [self.uut methodForSelector:s]; void (*func)(id, SEL, id, id, id, id, id) = (void *)imp; XCTAssertThrowsSpecificNamed(func(self.uut,s, nil, nil, nil, nil, nil), NSException, @"BridgeNotLoadedError"); } } -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{ NSMutableArray* skipMethods = [NSMutableArray new]; [skipMethods addObject:@"initWithControllerFactory:eventEmitter:stackManager:modalManager:overlayManager:mainWindow:"]; [skipMethods addObject:@"assertReady"]; [skipMethods addObject:@"setReadyToReceiveCommands:"]; [skipMethods addObject:@"readyToReceiveCommands"]; [skipMethods addObject:@".cxx_destruct"]; [skipMethods addObject:@"dismissedModal:"]; [skipMethods addObject:@"dismissedMultipleModals:"]; NSMutableArray* result = [NSMutableArray new]; // count and names: int i=0; unsigned int mc = 0; Method * mlist = class_copyMethodList(object_getClass(obj), &mc); for(i=0; i