Просмотр исходного кода

Change GIDSignInTest strict mocks to less restrictive

This change for OIDAuthState and GTMAuthSession is a kind of shortcut to unblock testing in GIDVerifyAccountDetailTest
Matt Mathias 1 год назад
Родитель
Сommit
be3874d736

+ 2 - 2
GoogleSignIn/Tests/Unit/GIDSignInTest.m

@@ -286,12 +286,12 @@ static NSString *const kNewScope = @"newScope";
 #elif TARGET_OS_OSX
   _presentingWindow = OCMStrictClassMock([NSWindow class]);
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
-  _authState = OCMStrictClassMock([OIDAuthState class]);
+  _authState = OCMClassMock([OIDAuthState class]);
   OCMStub([_authState alloc]).andReturn(_authState);
   OCMStub([_authState initWithAuthorizationResponse:OCMOCK_ANY]).andReturn(_authState);
   _tokenResponse = OCMStrictClassMock([OIDTokenResponse class]);
   _tokenRequest = OCMStrictClassMock([OIDTokenRequest class]);
-  _authorization = OCMStrictClassMock([GTMAuthSession class]);
+  _authorization = OCMClassMock([GTMAuthSession class]);
   _keychainStore = OCMStrictClassMock([GTMKeychainStore class]);
   OCMStub(
     [_keychainStore retrieveAuthSessionWithItemName:OCMOCK_ANY error:OCMArg.anyObjectRef]

+ 44 - 28
GoogleSignIn/Tests/Unit/GIDVerifyAccountDetailTest.m

@@ -25,6 +25,16 @@
 #import "GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h"
 #import "GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h"
 
+// Exception Reasons
+static NSString * const kSchemesNotSupportedExceptionReason =
+    @"Your app is missing support for the following URL schemes: fakeclientid";
+static NSString * const kClientIDMissingExceptionReason =
+    @"You must specify |clientID| in |GIDConfiguration|";
+static NSString * const kMissingCurrentUserExceptionReason =
+    @"|currentUser| must be set to verify.";
+static NSString * const kMissingPresentingViewControllerExceptionReason =
+    @"|presentingViewController| must be set.";
+
 static NSString * const kClientId = @"FakeClientID";
 static NSString * const kServerClientId = @"FakeServerClientID";
 static NSString * const kOpenIDRealm = @"FakeRealm";
@@ -55,9 +65,8 @@ static NSString * const kFakeHostedDomain = @"fakehosteddomain.com";
 
   _verifyAccountDetail = [[GIDVerifyAccountDetail alloc] init];
 
-  GIDVerifiableAccountDetail *ageOver18Detail = [[GIDVerifiableAccountDetail alloc]
-                                                 initWithAccountDetailType:
-                                                   GIDAccountDetailTypeAgeOver18];
+  GIDVerifiableAccountDetail *ageOver18Detail =
+      [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
   _verifiableAccountDetails = @[ageOver18Detail];
 
   _fakeMainBundle = [[GIDFakeMainBundle alloc] init];
@@ -144,12 +153,14 @@ static NSString * const kFakeHostedDomain = @"fakehosteddomain.com";
   OIDAuthState *authState = [OIDAuthState testInstance];
   GIDSignIn.sharedInstance.currentUser = nil;
 
-  XCTAssertThrowsSpecificNamed([_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
-                                                 presentingViewController:_presentingViewController
-                                                               completion:nil],
-                               NSException,
-                               NSInvalidArgumentException,
-                               @"|currentUser| must be set to verify.");
+  @try {
+    [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                      presentingViewController:_presentingViewController
+                                    completion:nil];
+  } @catch (NSException *exception) {
+    XCTAssertEqual(exception.name, NSInvalidArgumentException);
+    XCTAssertEqualObjects(exception.reason, kMissingCurrentUserExceptionReason);
+  }
 }
 
 - (void)testPresentingViewControllerException {
@@ -163,12 +174,14 @@ static NSString * const kFakeHostedDomain = @"fakehosteddomain.com";
   GIDSignIn.sharedInstance.currentUser = [[GIDGoogleUser alloc] initWithAuthState:authState
                                                                       profileData:nil];
 
-  XCTAssertThrowsSpecificNamed([_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
-                                                 presentingViewController:_presentingViewController
-                                                               completion:nil],
-                               NSException,
-                               NSInvalidArgumentException,
-                               @"|presentingViewController| must be set.");
+  @try {
+    [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                      presentingViewController:_presentingViewController
+                                    completion:nil];
+  } @catch (NSException *exception) {
+    XCTAssertEqual(exception.name, NSInvalidArgumentException);
+    XCTAssertEqualObjects(exception.reason, kMissingPresentingViewControllerExceptionReason);
+  }
 }
 
 - (void)testClientIDMissingException {
@@ -181,12 +194,14 @@ static NSString * const kFakeHostedDomain = @"fakehosteddomain.com";
   GIDSignIn.sharedInstance.currentUser = [[GIDGoogleUser alloc] initWithAuthState:authState
                                                                       profileData:nil];
 
-  XCTAssertThrowsSpecificNamed([_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
-                                                 presentingViewController:_presentingViewController
-                                                               completion:nil],
-                               NSException,
-                               NSInvalidArgumentException,
-                               @"You must specify |clientID| in |GIDConfiguration|");
+  @try {
+    [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                      presentingViewController:_presentingViewController
+                                    completion:nil];
+  } @catch (NSException *exception) {
+    XCTAssertEqual(exception.name, NSInvalidArgumentException);
+    XCTAssertEqualObjects(exception.reason, kClientIDMissingExceptionReason);
+  }
 }
 
 - (void)testSchemesNotSupportedException {
@@ -199,13 +214,14 @@ static NSString * const kFakeHostedDomain = @"fakehosteddomain.com";
   GIDSignIn.sharedInstance.currentUser = [[GIDGoogleUser alloc] initWithAuthState:authState
                                                                       profileData:nil];
 
-  XCTAssertThrowsSpecificNamed([_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
-                                                 presentingViewController:_presentingViewController
-                                                               completion:nil],
-                               NSException,
-                               NSInvalidArgumentException,
-                               @"Your app is missing support for the following URL schemes: "
-                               "fakeclientid");
+  @try {
+    [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                      presentingViewController:_presentingViewController
+                                    completion:nil];
+  } @catch (NSException *exception) {
+    XCTAssertEqual(exception.name, NSInvalidArgumentException);
+    XCTAssertEqualObjects(exception.reason, kSchemesNotSupportedExceptionReason);
+  }
 }
 
 @end