Skip to content

Commit

Permalink
Remove unnecessary availability checks (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Jun 7, 2024
1 parent fe0ef88 commit bf6cc82
Showing 1 changed file with 62 additions and 66 deletions.
128 changes: 62 additions & 66 deletions GoogleUtilities/Tests/Unit/Swizzler/GULAppDelegateSwizzlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -615,76 +615,72 @@ - (void)testAppDelegateInstance {
#if TARGET_OS_IOS || TARGET_OS_TV
/** Tests that application:openURL:options: is invoked on the interceptor if it exists. */
- (void)testApplicationOpenURLOptionsIsInvokedOnInterceptors {
if (@available(iOS 10, *)) {
id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);

id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor2 application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);

NSURL *testURL = [[NSURL alloc] initWithString:@"https://www.google.com"];
NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @"test"};

GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init];
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate);

[GULAppDelegateSwizzler proxyOriginalDelegate];
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor];
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor2];

[testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
OCMVerifyAll(interceptor);
OCMVerifyAll(interceptor2);

// Check that original implementation was called with proper parameters
XCTAssertEqual(testAppDelegate.application, [GULApplication sharedApplication]);
XCTAssertEqual(testAppDelegate.url, testURL);
}
id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);

id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor2 application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);

NSURL *testURL = [[NSURL alloc] initWithString:@"https://www.google.com"];
NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @"test"};

GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init];
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate);

[GULAppDelegateSwizzler proxyOriginalDelegate];
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor];
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor2];

[testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
OCMVerifyAll(interceptor);
OCMVerifyAll(interceptor2);

// Check that original implementation was called with proper parameters
XCTAssertEqual(testAppDelegate.application, [GULApplication sharedApplication]);
XCTAssertEqual(testAppDelegate.url, testURL);
}

/** Tests that the result of application:openURL:options: from all interceptors is ORed. */
- (void)testResultOfApplicationOpenURLOptionsIsORed {
if (@available(iOS 10, *)) {
NSURL *testURL = [[NSURL alloc] initWithString:@"https://www.google.com"];
NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @"test"};

GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init];
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate);
[GULAppDelegateSwizzler proxyOriginalDelegate];

BOOL shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that the original app delegate returns NO.
XCTAssertFalse(shouldOpen);

id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor];
shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that if the only interceptor returns NO, the value is still NO.
XCTAssertFalse(shouldOpen);

id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor2 application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(YES);
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor2];

OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);
shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that if one of the two interceptors returns YES, the value is YES.
XCTAssertTrue(shouldOpen);
}
NSURL *testURL = [[NSURL alloc] initWithString:@"https://www.google.com"];
NSDictionary *testOpenURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly : @"test"};

GULTestAppDelegate *testAppDelegate = [[GULTestAppDelegate alloc] init];
OCMStub([self.mockSharedApplication delegate]).andReturn(testAppDelegate);
[GULAppDelegateSwizzler proxyOriginalDelegate];

BOOL shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that the original app delegate returns NO.
XCTAssertFalse(shouldOpen);

id interceptor = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor];
shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that if the only interceptor returns NO, the value is still NO.
XCTAssertFalse(shouldOpen);

id interceptor2 = OCMProtocolMock(@protocol(GULApplicationDelegate));
OCMExpect([interceptor2 application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(YES);
[GULAppDelegateSwizzler registerAppDelegateInterceptor:interceptor2];

OCMExpect([interceptor application:OCMOCK_ANY openURL:OCMOCK_ANY options:OCMOCK_ANY])
.andReturn(NO);
shouldOpen = [testAppDelegate application:[GULApplication sharedApplication]
openURL:testURL
options:testOpenURLOptions];
// Verify that if one of the two interceptors returns YES, the value is YES.
XCTAssertTrue(shouldOpen);
}
#endif // TARGET_OS_IOS || TARGET_OS_TV

Expand Down

0 comments on commit bf6cc82

Please sign in to comment.