Bläddra i källkod

GIDFakeSignIn is no longer needed.

Peter Andrews 4 år sedan
förälder
incheckning
c2e915ff9e

+ 0 - 29
GoogleSignIn/Tests/Unit/GIDFakeSignIn.h

@@ -1,29 +0,0 @@
-/*
- * Copyright 2021 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import <Foundation/Foundation.h>
-
-#import "GoogleSignIn/Sources/GIDSignIn_Private.h"
-
-@interface GIDFakeSignIn : GIDSignIn
-
-- (instancetype)init;
-
-- (void)startMocking;
-
-- (void)stopMocking;
-
-@end

+ 0 - 59
GoogleSignIn/Tests/Unit/GIDFakeSignIn.m

@@ -1,59 +0,0 @@
-// Copyright 2021 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#import "GoogleSignIn/Tests/Unit/GIDFakeSignIn.h"
-
-#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
-
-#import "GoogleSignIn/Sources/GIDSignIn_Private.h"
-
-#import <GoogleUtilities/GULSwizzler.h>
-#import <GoogleUtilities/GULSwizzler+Unswizzle.h>
-
-static NSString * const kClientId = @"FakeClientID";
-static NSString * const kScope = @"FakeScope";
-
-@implementation GIDFakeSignIn
-
-- (instancetype) init {
-  self = [super initPrivate];
-  if (self) {
-    self.clientID = kClientId;
-    self.scopes = [NSArray arrayWithObject:kScope];
-  }
-  return self;
-}
-
-- (void)startMocking {
-  __weak id weakSelf = self;
-  [GULSwizzler swizzleClass:[GIDSignIn class]
-                   selector:@selector(sharedInstance)
-            isClassSelector:YES
-                  withBlock:^{ return weakSelf; }];
-  [[NSNotificationCenter defaultCenter] addObserver:self
-                                           selector:@selector(applicationDidBecomeActive:)
-                                               name:UIApplicationDidBecomeActiveNotification
-                                             object:nil];
-}
-
-- (void)stopMocking {
-  [GULSwizzler unswizzleClass:[GIDSignIn class]
-                     selector:@selector(sharedInstance)
-              isClassSelector:YES];
-  [[NSNotificationCenter defaultCenter] removeObserver:self
-                                                  name:UIApplicationDidBecomeActiveNotification
-                                                object:nil];
-}
-
-@end

+ 1 - 13
GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m

@@ -17,7 +17,6 @@
 
 #import "GoogleSignIn/Sources/GIDSignInButton_Private.h"
 #import "GoogleSignIn/Sources/GIDSignIn_Private.h"
-#import "GoogleSignIn/Tests/Unit/GIDFakeSignIn.h"
 
 #ifdef SWIFT_PACKAGE
 @import OCMock;
@@ -42,18 +41,7 @@ static NSString * const kAppBundleId = @"FakeBundleID";
 
 @end
 
-@implementation GIDSignInButtonTest {
-  GIDFakeSignIn *_signIn;
-}
-
-- (void)setUp {
-  _signIn = [[GIDFakeSignIn alloc] init];
-  [_signIn startMocking];
-}
-
-- (void)tearDown {
-  [_signIn stopMocking];
-}
+@implementation GIDSignInButtonTest
 
 #pragma mark - Tests
 

+ 4 - 11
GoogleSignIn/Tests/Unit/GIDSignInTest.m

@@ -29,7 +29,6 @@
 #import "GoogleSignIn/Tests/Unit/GIDFakeFetcher.h"
 #import "GoogleSignIn/Tests/Unit/GIDFakeFetcherService.h"
 #import "GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h"
-#import "GoogleSignIn/Tests/Unit/GIDFakeSignIn.h"
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
 
@@ -210,7 +209,7 @@ static void *kTestObserverContext = &kTestObserverContext;
   BOOL _keychainRemoved;
 
   // The |GIDSignIn| object being tested.
-  GIDFakeSignIn *_signIn;
+  GIDSignIn *_signIn;
 
   // The saved authorization request.
   OIDAuthorizationRequest *_savedAuthorizationRequest;
@@ -251,7 +250,6 @@ static void *kTestObserverContext = &kTestObserverContext;
   _changedKeyPaths = [[NSMutableSet alloc] init];
 
   // Mocks
-  // TODO(b/136089202): Prefer fakes over mocks.
   _presentingViewController = OCMStrictClassMock([UIViewController class]);
   _authState = OCMStrictClassMock([OIDAuthState class]);
   OCMStub([_authState alloc]).andReturn(_authState);
@@ -291,7 +289,9 @@ static void *kTestObserverContext = &kTestObserverContext;
   [[NSUserDefaults standardUserDefaults] setBool:YES
                                           forKey:kAppHasRunBeforeKey];
 
-  _signIn = [[GIDFakeSignIn alloc] init];
+  _signIn = [[GIDSignIn alloc] initPrivate];
+  _signIn.clientID = kClientId;
+  _signIn.scopes = [NSArray arrayWithObject:kScope];
   _signIn.delegate = self;
   _signIn.presentingViewController = _presentingViewController;
 
@@ -303,8 +303,6 @@ static void *kTestObserverContext = &kTestObserverContext;
             forKeyPath:NSStringFromSelector(@selector(currentUser))
                options:0
                context:kTestObserverContext];
-
-  [_signIn startMocking];
 }
 
 - (void)tearDown {
@@ -318,7 +316,6 @@ static void *kTestObserverContext = &kTestObserverContext;
   OCMVerifyAll(_oidAuthorizationService);
 
   [_fakeMainBundle stopFaking];
-  [_signIn stopMocking];
   _signIn.delegate = nil;
   _signIn.presentingViewController = nil;
   [super tearDown];
@@ -340,13 +337,9 @@ static void *kTestObserverContext = &kTestObserverContext;
 }
 
 - (void)testDefaultScope {
-  // Stop mocking |[GIDSignIn sharedInstance]|, since we are testing the default scopes,
-  // which is modified in GIDFakeSignIn.
-  [_signIn stopMocking];
   GIDSignIn *signIn = [GIDSignIn sharedInstance];
   XCTAssertTrue([[signIn scopes] count] == 0,
                 @"there should be no default scope");
-  [_signIn startMocking];
 }
 
 - (void)testRestoredGoogleUserFromPreviousSignIn_hasPreviousUser {