8000 Remove unnecessary availability checks by paulb777 · Pull Request #181 · google/GoogleUtilities · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove unnecessary availability checks #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 62 additions & 66 deletions GoogleUtilities/Tests/Unit/Swizzler/GULAppDelegateSwizzlerTest.m
E261
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
Loading
0