Skip to content

Commit cb86001

Browse files
Cleanup bad uses of andDo blocks (#7584)
1 parent 4e6a31b commit cb86001

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

Example/InstanceID/Tests/FIRInstanceIDTest.m

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ - (void)testTokenShouldBeRefreshedIfCacheTokenNeedsToBeRefreshed {
187187
[[[self.mockInstanceID stub] andReturn:kToken] cachedTokenIfAvailable];
188188
[[[self.mockTokenManager stub] andReturnValue:@(YES)]
189189
checkTokenRefreshPolicyWithIID:[OCMArg any]];
190-
[[[self.mockInstanceID stub] andDo:^(NSInvocation *invocation){
191-
}] tokenWithAuthorizedEntity:[OCMArg any]
192-
scope:[OCMArg any]
193-
options:[OCMArg any]
194-
handler:[OCMArg any]];
190+
[[self.mockInstanceID stub] tokenWithAuthorizedEntity:[OCMArg any]
191+
scope:[OCMArg any]
192+
options:[OCMArg any]
193+
handler:[OCMArg any]];
195194
[self expectInstallationsInstallationIDWithFID:kToken error:nil];
196195

197196
[self.mockInstanceID didCompleteConfigure];
@@ -202,11 +201,10 @@ - (void)testTokenShouldBeRefreshedIfCacheTokenNeedsToBeRefreshed {
202201
- (void)testTokenShouldBeRefreshedIfNoCacheTokenButAutoInitAllowed {
203202
[[[self.mockInstanceID stub] andReturn:nil] cachedTokenIfAvailable];
204203
[[[self.mockInstanceID stub] andReturnValue:@(YES)] isFCMAutoInitEnabled];
205-
[[[self.mockInstanceID stub] andDo:^(NSInvocation *invocation){
206-
}] tokenWithAuthorizedEntity:[OCMArg any]
207-
scope:[OCMArg any]
208-
options:[OCMArg any]
209-
handler:[OCMArg any]];
204+
[[self.mockInstanceID stub] tokenWithAuthorizedEntity:[OCMArg any]
205+
scope:[OCMArg any]
206+
options:[OCMArg any]
207+
handler:[OCMArg any]];
210208

211209
[self.mockInstanceID didCompleteConfigure];
212210

@@ -254,11 +252,10 @@ - (void)testTokenShouldBeRefreshedIfIIDAndTokenAreNotConsistent {
254252

255253
- (void)testTokenIsDeletedAlongWithIdentity {
256254
[[[self.mockInstanceID stub] andReturnValue:@(YES)] isFCMAutoInitEnabled];
257-
[[[self.mockInstanceID stub] andDo:^(NSInvocation *invocation){
258-
}] tokenWithAuthorizedEntity:[OCMArg any]
259-
scope:[OCMArg any]
260-
options:[OCMArg any]
261-
handler:[OCMArg any]];
255+
[[self.mockInstanceID stub] tokenWithAuthorizedEntity:[OCMArg any]
256+
scope:[OCMArg any]
257+
options:[OCMArg any]
258+
handler:[OCMArg any]];
262259

263260
[self.mockInstanceID deleteIdentityWithHandler:^(NSError *_Nullable error) {
264261
XCTAssertNil([self.mockInstanceID token]);
@@ -452,17 +449,17 @@ - (void)testAPNSTokenIsPrefixedCorrectlyForServerType {
452449
serverTypeKey : @(NO),
453450
};
454451

455-
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation){
456-
}] fetchNewTokenWithAuthorizedEntity:kAuthorizedEntity
457-
scope:kScope
458-
instanceID:[OCMArg any]
459-
options:[OCMArg checkWithBlock:^BOOL(id obj) {
460-
NSDictionary *options = (NSDictionary *)obj;
461-
XCTAssertTrue([options[APNSKey] hasPrefix:@"p_"]);
462-
XCTAssertFalse([options[serverTypeKey] boolValue]);
463-
return YES;
464-
}]
465-
handler:OCMOCK_ANY];
452+
[[self.mockTokenManager stub]
453+
fetchNewTokenWithAuthorizedEntity:kAuthorizedEntity
454+
scope:kScope
455+
instanceID:[OCMArg any]
456+
options:[OCMArg checkWithBlock:^BOOL(id obj) {
457+
NSDictionary *options = (NSDictionary *)obj;
458+
XCTAssertTrue([options[APNSKey] hasPrefix:@"p_"]);
459+
XCTAssertFalse([options[serverTypeKey] boolValue]);
460+
return YES;
461+
}]
462+
handler:OCMOCK_ANY];
466463

467464
[self.instanceID tokenWithAuthorizedEntity:kAuthorizedEntity
468465
scope:kScope
@@ -638,7 +635,8 @@ - (void)testDefaultToken_callbackInvokedForUnchangedToken {
638635
// will change. Normal stubbing will always return the initial pointer,
639636
// which in this case is 0x0 (nil).
640637
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
641-
[invocation setReturnValue:&cachedTokenInfo];
638+
__autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
639+
[invocation setReturnValue:&tokenInfo];
642640
}] cachedTokenInfoWithAuthorizedEntity:kAuthorizedEntity scope:kFIRInstanceIDDefaultTokenScope];
643641

644642
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
@@ -705,7 +703,8 @@ - (void)testDefaultTokenFetch_returnValidToken {
705703
// will change. Normal stubbing will always return the initial pointer,
706704
// which in this case is 0x0 (nil).
707705
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
708-
[invocation setReturnValue:&cachedTokenInfo];
706+
__autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
707+
[invocation setReturnValue:&tokenInfo];
709708
}] cachedTokenInfoWithAuthorizedEntity:kAuthorizedEntity scope:kFIRInstanceIDDefaultTokenScope];
710709

711710
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
@@ -764,7 +763,8 @@ - (void)testDefaultTokenFetch_retryFetchToken {
764763
// will change. Normal stubbing will always return the initial pointer,
765764
// which in this case is 0x0 (nil).
766765
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
767-
[invocation setReturnValue:&cachedTokenInfo];
766+
__autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
767+
[invocation setReturnValue:&tokenInfo];
768768
}] cachedTokenInfoWithAuthorizedEntity:kAuthorizedEntity scope:kFIRInstanceIDDefaultTokenScope];
769769

770770
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
@@ -841,7 +841,8 @@ - (void)testDefaultToken_multipleInvocations {
841841
// will change. Normal stubbing will always return the initial pointer,
842842
// which in this case is 0x0 (nil).
843843
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
844-
[invocation setReturnValue:&cachedTokenInfo];
844+
__autoreleasing FIRInstanceIDTokenInfo *tokenInfo = cachedTokenInfo;
845+
[invocation setReturnValue:&tokenInfo];
845846
}] cachedTokenInfoWithAuthorizedEntity:kAuthorizedEntity scope:kFIRInstanceIDDefaultTokenScope];
846847

847848
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
@@ -949,7 +950,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_Success {
949950
__block FIRInstanceIDTokenHandler tokenHandler;
950951

951952
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
952-
[invocation getArgument:&tokenHandler atIndex:6];
953+
__unsafe_unretained FIRInstanceIDTokenHandler handler;
954+
[invocation getArgument:&handler atIndex:6];
955+
tokenHandler = handler;
953956
[fetchNewTokenExpectation fulfill];
954957
}] fetchNewTokenWithAuthorizedEntity:kAuthorizedEntity
955958
scope:kFIRInstanceIDDefaultTokenScope
@@ -1005,7 +1008,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_RetrySuccess {
10051008
__block FIRInstanceIDTokenHandler tokenHandler;
10061009

10071010
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
1008-
[invocation getArgument:&tokenHandler atIndex:6];
1011+
__unsafe_unretained FIRInstanceIDTokenHandler handler;
1012+
[invocation getArgument:&handler atIndex:6];
1013+
tokenHandler = handler;
10091014
[fetchNewTokenExpectations[fetchNewTokenCallCount] fulfill];
10101015
fetchNewTokenCallCount += 1;
10111016
}] fetchNewTokenWithAuthorizedEntity:kAuthorizedEntity
@@ -1070,7 +1075,9 @@ - (void)testInstanceIDWithHandler_WhileRequesting_RetryFailure {
10701075
__block FIRInstanceIDTokenHandler tokenHandler;
10711076

10721077
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
1073-
[invocation getArgument:&tokenHandler atIndex:6];
1078+
__unsafe_unretained FIRInstanceIDTokenHandler handler;
1079+
[invocation getArgument:&handler atIndex:6];
1080+
tokenHandler = handler;
10741081
[fetchNewTokenExpectations[fetchNewTokenCallCount] fulfill];
10751082
fetchNewTokenCallCount += 1;
10761083
}] fetchNewTokenWithAuthorizedEntity:kAuthorizedEntity
@@ -1166,7 +1173,7 @@ - (void)testTokenFetchAPNSServerTypeIsIncludedIfAPNSTokenProvided {
11661173

11671174
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
11681175
// Inspect
1169-
NSDictionary *options;
1176+
__unsafe_unretained NSDictionary *options;
11701177
[invocation getArgument:&options atIndex:5];
11711178
if (options[kFIRInstanceIDTokenOptionsAPNSIsSandboxKey] != nil) {
11721179
[apnsServerTypeExpectation fulfill];
@@ -1205,12 +1212,6 @@ - (void)testTokenFetch_ignoresCacheIfAPNSInfoDifferent {
12051212
// This token is |kToken|, but we will simulate that a fetch will return another token
12061213
NSString *oldCachedToken = kToken;
12071214
NSString *fetchedToken = @"abcd123_newtoken";
1208-
__block FIRInstanceIDTokenInfo *cachedTokenInfo =
1209-
[[FIRInstanceIDTokenInfo alloc] initWithAuthorizedEntity:kAuthorizedEntity
1210-
scope:kFIRInstanceIDDefaultTokenScope
1211-
token:oldCachedToken
1212-
appVersion:@"1.0"
1213-
firebaseAppID:@"firebaseAppID"];
12141215

12151216
[self stubInstallationsToReturnValidID];
12161217

@@ -1223,7 +1224,13 @@ - (void)testTokenFetch_ignoresCacheIfAPNSInfoDifferent {
12231224
// will change. Normal stubbing will always return the initial pointer,
12241225
// which in this case is 0x0 (nil).
12251226
[[[self.mockTokenManager stub] andDo:^(NSInvocation *invocation) {
1226-
[invocation setReturnValue:&cachedTokenInfo];
1227+
__autoreleasing FIRInstanceIDTokenInfo *tokenInfo =
1228+
[[FIRInstanceIDTokenInfo alloc] initWithAuthorizedEntity:kAuthorizedEntity
1229+
scope:kFIRInstanceIDDefaultTokenScope
1230+
token:oldCachedToken
1231+
appVersion:@"1.0"
1232+
firebaseAppID:@"firebaseAppID"];
1233+
[invocation setReturnValue:&tokenInfo];
12271234
}] cachedTokenInfoWithAuthorizedEntity:kAuthorizedEntity scope:kFIRInstanceIDDefaultTokenScope];
12281235

12291236
// Mock the network request to return |fetchedToken|, so we can clearly see if the token is

FirebaseMessaging/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 2021-02 -- v7.7.0
2-
- [fixed] Fixed an issue that when checking storage size before writing to the disk, the client was checking the document folder that is no longer used. (#7480)
2+
- [fixed] Fixed an issue in which, when checking storage size before writing to disk, the client was checking document folders that were no longer used. (#7480)
33

44
# 2021-02 -- v7.6.0
55
- [fixed] Fixed build warnings introduced with Xcode 12.5. (#7433)

0 commit comments

Comments
 (0)