                 return
         }
 
-        guard let savedItem1 = Keychain.sharedInstance.addToken(token1),
-            let savedItem2 = Keychain.sharedInstance.addToken(token2),
-            let savedItem3 = Keychain.sharedInstance.addToken(token3) else {
+        guard let savedItem1 = keychain.addToken(token1),
+            let savedItem2 = keychain.addToken(token2),
+            let savedItem3 = keychain.addToken(token3) else {
                 XCTFail("Failed to save tokens")
                 return
         }
 
-        let allItems = Keychain.sharedInstance.allTokenItems()
+        let allItems = keychain.allTokenItems()
 
         XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem1.persistentRef),
             "Token not recovered from keychain: \(token1)")


let kValidTokenURL = NSURL(string: "otpauth://totp/L%C3%A9on?algorithm=SHA256&digits=8&period=45&secret=AAAQEAYEAUDAOCAJBIFQYDIOB4")!

class OTPTokenPersistenceTests: XCTestCase {
    func testTokenWithKeychainItemRef() {
        // Create a token
        guard let token = Token.URLSerializer.deserialize(kValidTokenURL) else {

        XCTAssertEqual(savedItem2, fetchedItem2)

        // Remove the first token from the keychain
        let delete1success = keychain.deleteTokenItem(savedItem1)
        XCTAssertTrue(delete1success, "Failed to remove from keychain: \(token1)")

        let checkItem1 = keychain.tokenItemForPersistentRef(savedItem1.persistentRef)
        XCTAssertNil(checkItem1, "Token should not be in keychain: \(token1)")
        let checkItem2 = keychain.tokenItemForPersistentRef(savedItem2.persistentRef)
        XCTAssertNotNil(checkItem2, "Token should be in keychain: \(token2)")

        // Remove the second token from the keychain
        let delete2success = keychain.deleteTokenItem(savedItem2)
        XCTAssertTrue(delete2success, "Failed to remove from keychain: \(token2)")

        let recheckItem1 = keychain.tokenItemForPersistentRef(savedItem1.persistentRef)
        XCTAssertNil(recheckItem1, "Token should not be in keychain: \(token1)")
        let recheckItem2 = keychain.tokenItemForPersistentRef(savedItem2.persistentRef)
        XCTAssertNil(recheckItem2, "Token should not be in keychain: \(token2)")

        // Try to remove both tokens from the keychain again
        let redelete1success = keychain.deleteTokenItem(savedItem1)
        XCTAssertFalse(redelete1success, "Removing again should fail: \(token1)")
        let redelete2success = keychain.deleteTokenItem(savedItem2)
        XCTAssertFalse(redelete2success, "Removing again should fail: \(token2)")
    }

