/**
  * Confirm that the test below is functional (and non-destructive) when there are prexisting
  * (non-test) accounts in the account manager.
  */
 public void testTestReconcileAccounts() {
   Account firstAccount = null;
   final String TEST_USER_ACCOUNT = "__user_account_test_1";
   Context context = getContext();
   try {
     // Note:  Unlike calls to setupProviderAndAccountManagerAccount(), we are creating
     // *real* accounts here (not in the mock provider)
     createAccountManagerAccount(TEST_USER_ACCOUNT + TEST_ACCOUNT_SUFFIX);
     firstAccount = ProviderTestUtils.setupAccount(TEST_USER_ACCOUNT, true, context);
     // Now run the test with the "user" accounts in place
     testReconcileAccounts();
   } finally {
     if (firstAccount != null) {
       boolean firstAccountFound = false;
       // delete the provider account
       context.getContentResolver().delete(firstAccount.getUri(), null, null);
       // delete the account manager account
       android.accounts.Account[] accountManagerAccounts =
           AccountManager.get(context).getAccountsByType(Email.EXCHANGE_ACCOUNT_MANAGER_TYPE);
       for (android.accounts.Account accountManagerAccount : accountManagerAccounts) {
         if ((TEST_USER_ACCOUNT + TEST_ACCOUNT_SUFFIX).equals(accountManagerAccount.name)) {
           deleteAccountManagerAccount(accountManagerAccount);
           firstAccountFound = true;
         }
       }
       assertTrue(firstAccountFound);
     }
   }
 }
  public void testReleaseSyncHolds() {
    Context context = mMockContext;
    SyncManager syncManager = new SyncManager();
    SyncError securityErrorAccount1 =
        syncManager.new SyncError(AbstractSyncService.EXIT_SECURITY_FAILURE, false);
    SyncError ioError = syncManager.new SyncError(AbstractSyncService.EXIT_IO_ERROR, false);
    SyncError securityErrorAccount2 =
        syncManager.new SyncError(AbstractSyncService.EXIT_SECURITY_FAILURE, false);
    // Create account and two mailboxes
    Account acct1 = ProviderTestUtils.setupAccount("acct1", true, context);
    Mailbox box1 = ProviderTestUtils.setupMailbox("box1", acct1.mId, true, context);
    Mailbox box2 = ProviderTestUtils.setupMailbox("box2", acct1.mId, true, context);
    Account acct2 = ProviderTestUtils.setupAccount("acct2", true, context);
    Mailbox box3 = ProviderTestUtils.setupMailbox("box3", acct2.mId, true, context);
    Mailbox box4 = ProviderTestUtils.setupMailbox("box4", acct2.mId, true, context);

    HashMap<Long, SyncError> errorMap = syncManager.mSyncErrorMap;
    // Add errors into the map
    errorMap.put(box1.mId, securityErrorAccount1);
    errorMap.put(box2.mId, ioError);
    errorMap.put(box3.mId, securityErrorAccount2);
    errorMap.put(box4.mId, securityErrorAccount2);
    // We should have 4
    assertEquals(4, errorMap.keySet().size());
    // Release the holds on acct2 (there are two of them)
    syncManager.releaseSyncHolds(context, AbstractSyncService.EXIT_SECURITY_FAILURE, acct2);
    // There should be two left
    assertEquals(2, errorMap.keySet().size());
    // And these are the two...
    assertNotNull(errorMap.get(box2.mId));
    assertNotNull(errorMap.get(box1.mId));

    // Put the two back
    errorMap.put(box3.mId, securityErrorAccount2);
    errorMap.put(box4.mId, securityErrorAccount2);
    // We should have 4 again
    assertEquals(4, errorMap.keySet().size());
    // Release all of the security holds
    syncManager.releaseSyncHolds(context, AbstractSyncService.EXIT_SECURITY_FAILURE, null);
    // There should be one left
    assertEquals(1, errorMap.keySet().size());
    // And this is the one
    assertNotNull(errorMap.get(box2.mId));

    // Release the i/o holds on account 2 (there aren't any)
    syncManager.releaseSyncHolds(context, AbstractSyncService.EXIT_IO_ERROR, acct2);
    // There should still be one left
    assertEquals(1, errorMap.keySet().size());

    // Release the i/o holds on account 1 (there's one)
    syncManager.releaseSyncHolds(context, AbstractSyncService.EXIT_IO_ERROR, acct1);
    // There should still be one left
    assertEquals(0, errorMap.keySet().size());
  }