Search in sources :

Example 1 with TokenRefreshException

use of com.zegoggles.smssync.auth.TokenRefreshException in project sms-backup-plus by jberkel.

the class BackupTaskTest method shouldHandleAuthErrorAndTokenCannotBeRefreshed.

@Test
public void shouldHandleAuthErrorAndTokenCannotBeRefreshed() throws Exception {
    mockFetch(SMS, 1);
    when(converter.convertMessages(any(Cursor.class), notNull(DataType.class))).thenReturn(result(SMS, 1));
    XOAuth2AuthenticationFailedException exception = mock(XOAuth2AuthenticationFailedException.class);
    when(exception.getStatus()).thenReturn(400);
    when(store.getFolder(notNull(DataType.class), same(dataTypePreferences))).thenThrow(exception);
    doThrow(new TokenRefreshException("failed")).when(tokenRefresher).refreshOAuth2Token();
    task.doInBackground(config);
    verify(tokenRefresher, times(1)).refreshOAuth2Token();
    verify(service).transition(SmsSyncState.ERROR, exception);
    // make sure locks only get acquired+released once
    verify(service).acquireLocks();
    verify(service).releaseLocks();
}
Also used : TokenRefreshException(com.zegoggles.smssync.auth.TokenRefreshException) XOAuth2AuthenticationFailedException(com.fsck.k9.mail.store.imap.XOAuth2AuthenticationFailedException) DataType(com.zegoggles.smssync.mail.DataType) BackupItemsFetcher.emptyCursor(com.zegoggles.smssync.service.BackupItemsFetcher.emptyCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Aggregations

Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 XOAuth2AuthenticationFailedException (com.fsck.k9.mail.store.imap.XOAuth2AuthenticationFailedException)1 TokenRefreshException (com.zegoggles.smssync.auth.TokenRefreshException)1 DataType (com.zegoggles.smssync.mail.DataType)1 BackupItemsFetcher.emptyCursor (com.zegoggles.smssync.service.BackupItemsFetcher.emptyCursor)1 Test (org.junit.Test)1