@@ -642,6 +642,13 @@ - (void)testNotOverriddenMethods {
642
642
* handles it correctly.
643
643
*/
644
644
- (void )testAppDelegateInstance {
645
+ // The test logic involves using KVC on the UIApplication.delegate propery. This does not really
646
+ // work well with OCMPartialMock([GULApplication sharedApplication]) and triggers issue
647
+ // https://github.com/erikdoe/ocmock/issues/346.
648
+ // Let's stop mocking the shared application for this particular test.
649
+ [self .mockSharedApplication stopMocking ];
650
+ self.mockSharedApplication = nil ;
651
+
645
652
GULTestAppDelegate *realAppDelegate = [[GULTestAppDelegate alloc ] init ];
646
653
647
654
[GULApplication sharedApplication ].delegate = realAppDelegate;
@@ -667,72 +674,76 @@ - (void)testAppDelegateInstance {
667
674
#if TARGET_OS_IOS || TARGET_OS_TV
668
675
/* * Tests that application:openURL:options: is invoked on the interceptor if it exists. */
669
676
- (void )testApplicationOpenURLOptionsIsInvokedOnInterceptors {
670
- id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
671
- OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
672
- .andReturn (NO );
673
-
674
- id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
675
- OCMExpect ([interceptor2 application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
676
- .andReturn (NO );
677
-
678
- NSURL *testURL = [[NSURL alloc ] initWithString: @" https://www.google.com" ];
679
- NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @" test" };
680
-
681
- GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
682
- OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
683
-
684
- [GULAppDelegateSwizzler proxyOriginalDelegate ];
685
- [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
686
- [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
687
-
688
- [testAppDelegate application: [GULApplication sharedApplication ]
689
- openURL: testURL
690
- options: testOpenURLOptions];
691
- OCMVerifyAll (interceptor);
692
- OCMVerifyAll (interceptor2);
693
-
694
- // Check that original implementation was called with proper parameters
695
- XCTAssertEqual (testAppDelegate.application , [GULApplication sharedApplication ]);
696
- XCTAssertEqual (testAppDelegate.url , testURL);
677
+ if (@available (iOS 10 , *)) {
678
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
679
+ OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
680
+ .andReturn (NO );
681
+
682
+ id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
683
+ OCMExpect ([interceptor2 application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
684
+ .andReturn (NO );
685
+
686
+ NSURL *testURL = [[NSURL alloc ] initWithString: @" https://www.google.com" ];
687
+ NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @" test" };
688
+
689
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
690
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
691
+
692
+ [GULAppDelegateSwizzler proxyOriginalDelegate ];
693
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
694
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
695
+
696
+ [testAppDelegate application: [GULApplication sharedApplication ]
697
+ openURL: testURL
698
+ options: testOpenURLOptions];
699
+ OCMVerifyAll (interceptor);
700
+ OCMVerifyAll (interceptor2);
701
+
702
+ // Check that original implementation was called with proper parameters
703
+ XCTAssertEqual (testAppDelegate.application , [GULApplication sharedApplication ]);
704
+ XCTAssertEqual (testAppDelegate.url , testURL);
705
+ }
697
706
}
698
707
699
708
/* * Tests that the result of application:openURL:options: from all interceptors is ORed. */
700
709
- (void )testResultOfApplicationOpenURLOptionsIsORed {
701
- NSURL *testURL = [[NSURL alloc ] initWithString: @" https://www.google.com" ];
702
- NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @" test" };
703
-
704
- GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
705
- OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
706
- [GULAppDelegateSwizzler proxyOriginalDelegate ];
707
-
708
- BOOL shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
709
- openURL: testURL
710
- options: testOpenURLOptions];
711
- // Verify that the original app delegate returns NO.
712
- XCTAssertFalse (shouldOpen);
713
-
714
- id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
715
- OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
716
- .andReturn (NO );
717
- [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
718
- shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
719
- openURL: testURL
720
- options: testOpenURLOptions];
721
- // Verify that if the only interceptor returns NO, the value is still NO.
722
- XCTAssertFalse (shouldOpen);
723
-
724
- id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
725
- OCMExpect ([interceptor2 application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
726
- .andReturn (YES );
727
- [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
728
-
729
- OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
730
- .andReturn (NO );
731
- shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
732
- openURL: testURL
733
- options: testOpenURLOptions];
734
- // Verify that if one of the two interceptors returns YES, the value is YES.
735
- XCTAssertTrue (shouldOpen);
710
+ if (@available (iOS 10 , *)) {
711
+ NSURL *testURL = [[NSURL alloc ] initWithString: @" https://www.google.com" ];
712
+ NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @" test" };
713
+
714
+ GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc ] init ];
715
+ OCMStub ([self .mockSharedApplication delegate ]).andReturn (testAppDelegate);
716
+ [GULAppDelegateSwizzler proxyOriginalDelegate ];
717
+
718
+ BOOL shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
719
+ openURL: testURL
720
+ options: testOpenURLOptions];
721
+ // Verify that the original app delegate returns NO.
722
+ XCTAssertFalse (shouldOpen);
723
+
724
+ id interceptor = OCMProtocolMock (@protocol (GULApplicationDelegate));
725
+ OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
726
+ .andReturn (NO );
727
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor];
728
+ shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
729
+ openURL: testURL
730
+ options: testOpenURLOptions];
731
+ // Verify that if the only interceptor returns NO, the value is still NO.
732
+ XCTAssertFalse (shouldOpen);
733
+
734
+ id interceptor2 = OCMProtocolMock (@protocol (GULApplicationDelegate));
735
+ OCMExpect ([interceptor2 application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
736
+ .andReturn (YES );
737
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: interceptor2];
738
+
739
+ OCMExpect ([interceptor application: OCMOCK_ANY openURL: OCMOCK_ANY options: OCMOCK_ANY])
740
+ .andReturn (NO );
741
+ shouldOpen = [testAppDelegate application: [GULApplication sharedApplication ]
742
+ openURL: testURL
743
+ options: testOpenURLOptions];
744
+ // Verify that if one of the two interceptors returns YES, the value is YES.
745
+ XCTAssertTrue (shouldOpen);
746
+ }
736
747
}
737
748
#endif // TARGET_OS_IOS || TARGET_OS_TV
738
749
0 commit comments