Skip to content

Commit 6f340a9

Browse files
authored
Update GIDSignInTest to correctly setUp and tearDown NSUserDefaults (#527)
1 parent 594f8b7 commit 6f340a9

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

GoogleSignIn/Tests/Unit/GIDSignInTest.m

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ @interface GIDSignInTest : XCTestCase {
268268
// Status returned by saveAuthorization:toKeychainForName:
269269
BOOL _saveAuthorizationReturnValue;
270270

271-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
272271
// Test userDefaults for use with `GIDAppCheck`
273272
NSUserDefaults *_testUserDefaults;
274-
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
275273
}
276274
@end
277275

@@ -337,15 +335,12 @@ - (void)setUp {
337335
[_fakeMainBundle fakeAllSchemesSupported];
338336

339337
// Object under test
340-
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasRunBeforeKey];
338+
_testUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultsSuiteName];
339+
[_testUserDefaults setBool:YES forKey:kAppHasRunBeforeKey];
341340

342341
_signIn = [[GIDSignIn alloc] initWithKeychainStore:_keychainStore];
343342
_hint = nil;
344343

345-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
346-
_testUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultsSuiteName];
347-
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
348-
349344
__weak GIDSignInTest *weakSelf = self;
350345
_completion = ^(GIDSignInResult *_Nullable signInResult, NSError * _Nullable error) {
351346
GIDSignInTest *strongSelf = weakSelf;
@@ -372,11 +367,7 @@ - (void)tearDown {
372367
OCMVerifyAll(_presentingWindow);
373368
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
374369

375-
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kAppHasRunBeforeKey];
376-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
377-
[_testUserDefaults removeObjectForKey:kGIDAppCheckPreparedKey];
378-
[_testUserDefaults removeSuiteNamed:kUserDefaultsSuiteName];
379-
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
370+
[_testUserDefaults removePersistentDomainForName:kUserDefaultsSuiteName];
380371

381372
[_fakeMainBundle stopFaking];
382373
[super tearDown];

0 commit comments

Comments
 (0)