@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
@Test(expected = AuthFailureError.class) public void resultContainsIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
@Test(expected = AuthFailureError.class) public void missingAuthToken() throws Exception { Bundle bundle = new Bundle(); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test(expected = AuthFailureError.class) public void resultContainsIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test public void goodToken() throws Exception { Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTHTOKEN, "monkey"); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); Assert.assertEquals("monkey", mAuthenticator.getAuthToken()); }
@Test(expected = AuthFailureError.class) public void missingAuthToken() throws Exception { Bundle bundle = new Bundle(); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
@Test public void goodToken() throws Exception { Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTHTOKEN, "monkey"); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); Assert.assertEquals("monkey", mAuthenticator.getAuthToken()); }
@Test(expected = AuthFailureError.class) public void resultContainsIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test(expected = AuthFailureError.class) public void resultContainsIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test(expected = AuthFailureError.class) public void resultContainsIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
@Test(expected = AuthFailureError.class) public void missingAuthToken() throws Exception { Bundle bundle = new Bundle(); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test(expected = AuthFailureError.class) public void missingAuthToken() throws Exception { Bundle bundle = new Bundle(); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test public void goodToken() throws Exception { Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTHTOKEN, "monkey"); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); Assert.assertEquals("monkey", mAuthenticator.getAuthToken()); }
@Test(expected = AuthFailureError.class) public void missingAuthToken() throws Exception { Bundle bundle = new Bundle(); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); mAuthenticator.getAuthToken(); }
@Test public void goodToken() throws Exception { Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTHTOKEN, "monkey"); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); Assert.assertEquals("monkey", mAuthenticator.getAuthToken()); }
@Test public void goodToken() throws Exception { Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTHTOKEN, "monkey"); when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture); when(mFuture.getResult()).thenReturn(bundle); when(mFuture.isDone()).thenReturn(true); when(mFuture.isCancelled()).thenReturn(false); Assert.assertEquals("monkey", mAuthenticator.getAuthToken()); }