Mocking yourself
func testRequestAccessWithAuthzCodeFlow() {
let expectation = expectationWithDescription("AccessRequestWithAuthzFlow");
let googleConfig = . . .
var mock = OAuth2ModulePartialMock(config: googleConfig,
session: MockOAuth2Session())
mock.requestAccess { (response: AnyObject?, error:NSError?) -> Void in
XCTAssertTrue("ACCESS_TOKEN" == response as String,
“response with access token")
expectation.fulfill()
}
waitForExpectationsWithTimeout(10, handler: nil)
}
class OAuth2ModulePartialMock: OAuth2Module {
override func refreshAccessToken(
completionHandler:(AnyObject?, NSError?) -> ()) {
completionHandler("NEW_ACCESS_TOKEN", nil)
}
override func requestAuthorizationCode(
completionHandler: (AnyObject?, NSError?) -> ()) {
completionHandler("ACCESS_TOKEN", nil)
}
}
aerogear-ios-oauth2