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()); }