FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m [101:152]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication);
  OCMExpect([mockAuthentication accessToken]).andReturn(testAccessToken);

  // mock idToken
  OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication);
  OCMExpect([mockAuthentication idToken]).andReturn(testIdToken);

  OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn);

  // forward call to signIn delegate
  OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any]
                       presentingViewController:[OCMArg any]
                                           hint:[OCMArg any]
                                       callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) {
    void (^callback)(GIDGoogleUser *, NSError *) = nil;
    [invocation getArgument:&callback atIndex:5];
    callback(mockGoogleUser, nil);
  });

  XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"];

  [_mockProvider signInWithDefaultValue:nil
               presentingViewController:nil
                             completion:^(FIRAuthCredential *_Nullable credential,
                                          NSError *_Nullable error,
                                          FIRAuthResultCallback _Nullable result,
                                          NSDictionary *_Nullable userInfo) {
    XCTAssertNil(error);
    XCTAssertNotNil(result);
    XCTAssertNotNil(credential);
    FIRAuthCredential *expectedCredential =
        [FIRGoogleAuthProvider credentialWithIDToken:testIdToken accessToken:testAccessToken];
    XCTAssertEqualObjects(credential.provider, expectedCredential.provider);

    [expectation fulfill];
    // We can't compare result and resultCallback. Thus verifying with expectation that result
    // is called.
    result(mockGoogleUser, error);
  }];
  [self waitForExpectationsWithTimeout:0.1 handler:^(NSError *_Nullable error) {
    XCTAssertNil(error);
  }];
  
  OCMVerifyAll(_mockProvider);
  OCMVerifyAll(mockSignInDelegate);
  OCMVerifyAll(mockGoogleUser);

  //verify that we are doing actual sign in
  OCMVerifyAll(mockSignIn);
  //verify that we are using token from server
  OCMVerifyAll(mockAuthentication);
  OCMVerify(never(), [self.mockOAuthProvider getCredentialWithUIDelegate:nil completion:OCMOCK_ANY]);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m [171:222]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication);
  OCMExpect([mockAuthentication accessToken]).andReturn(testAccessToken);

  // mock idToken
  OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication);
  OCMExpect([mockAuthentication idToken]).andReturn(testIdToken);

  OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn);

  // forward call to signIn delegate
  OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any]
                       presentingViewController:[OCMArg any]
                                           hint:[OCMArg any]
                                       callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) {
    void (^callback)(GIDGoogleUser *, NSError *) = nil;
    [invocation getArgument:&callback atIndex:5];
    callback(mockGoogleUser, nil);
  });

  XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"];

  [_mockProvider signInWithDefaultValue:nil
               presentingViewController:nil
                             completion:^(FIRAuthCredential *_Nullable credential,
                                          NSError *_Nullable error,
                                          FIRAuthResultCallback _Nullable result,
                                          NSDictionary *_Nullable userInfo) {
    XCTAssertNil(error);
    XCTAssertNotNil(result);
    XCTAssertNotNil(credential);
    FIRAuthCredential *expectedCredential =
        [FIRGoogleAuthProvider credentialWithIDToken:testIdToken accessToken:testAccessToken];
    XCTAssertEqualObjects(credential.provider, expectedCredential.provider);

    [expectation fulfill];
    // We can't compare result and resultCallback. Thus verifying with expectation that result
    // is called.
    result(mockGoogleUser, error);
  }];
  [self waitForExpectationsWithTimeout:0.1 handler:^(NSError *_Nullable error) {
    XCTAssertNil(error);
  }];

  OCMVerifyAll(_mockProvider);
  OCMVerifyAll(mockSignInDelegate);
  OCMVerifyAll(mockGoogleUser);

  //verify that we are doing actual sign in
  OCMVerifyAll(mockSignIn);
  //verify that we are using token from server
  OCMVerifyAll(mockAuthentication);
  OCMVerify(never(), [self.mockOAuthProvider getCredentialWithUIDelegate:nil completion:OCMOCK_ANY]);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



