Skip to content

Commit

Permalink
adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded Betzalel authored and Oded Betzalel committed Mar 21, 2017
1 parent 857ef3c commit 412b75d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions BluemixAppIDTests/AuthorizationUIManagerTests.swift
Expand Up @@ -117,6 +117,44 @@ public class AuthorizationUIManagerTests: XCTestCase {


}

func testApplicationErr3() {
class MockRegistrationManager:RegistrationManager {
static var expectation:XCTestExpectation?
public override func clearRegistrationData() {
MockRegistrationManager.expectation?.fulfill()
}
}

class MockAuthorizationManager:BluemixAppID.AuthorizationManager {
static var expectation:XCTestExpectation?
public override func launchAuthorizationUI(accessTokenString: String?, authorizationDelegate: AuthorizationDelegate) {
XCTAssertNil(accessTokenString)
MockAuthorizationManager.expectation?.fulfill()
}
}
let expectation1 = expectation(description: "clear data")
let expectation2 = expectation(description: "invoke registration")
oauthManager.registrationManager = MockRegistrationManager(oauthManager:oauthManager)
MockRegistrationManager.expectation = expectation1
oauthManager.authorizationManager = MockAuthorizationManager(oAuthManager: oauthManager)
MockAuthorizationManager.expectation = expectation2

let manager = AuthorizationUIManager(oAuthManager: oauthManager, authorizationDelegate: delegate(exp: expectation1, errMsg: "Failed to obtain access and identity tokens"), authorizationUrl: "someurl", redirectUri: "someredirect")
manager.loginView = MockSafariView(url:URL(string: "http://www.someurl.com")!)
XCTAssertFalse(manager.application(UIApplication.shared, open: URL(string:AppIDConstants.REDIRECT_URI_VALUE.lowercased() + "?code=somecode&error=invalid_client")!, options: [:]))

waitForExpectations(timeout: 1) { error in
if let error = error {
XCTFail("err: \(error)")
}
}




}



}
2 changes: 1 addition & 1 deletion Source/BluemixAppID/internal/OAuthManager.swift
Expand Up @@ -17,7 +17,7 @@ import Foundation
public class OAuthManager {
private(set) var appId:AppID
private(set) var preferenceManager:PreferenceManager
private(set) var registrationManager:RegistrationManager?
internal var registrationManager:RegistrationManager?
internal var authorizationManager:AuthorizationManager?
internal var tokenManager:TokenManager?

Expand Down

0 comments on commit 412b75d

Please sign in to comment.