SmartLock extends Lock implements CredentialStore, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { void onCredentialRetrievalError(Activity activity, Status status, int requestCode) { if (status.hasResolution() && status.getStatusCode() != CommonStatusCodes.SIGN_IN_REQUIRED) { try { status.startResolutionForResult(activity, requestCode); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Failed to send intent for Smart Lock resolution", e); startLockFromActivity(activity); } } else { Log.e(TAG, "Couldn't read the credentials using Smart Lock. Showing Lock..."); startLockFromActivity(activity); } } SmartLock(Context context, APIClient apiClient);   SmartLock(GoogleApiClient credentialClient, APIClient client); void onStart(); void onStop(); @Override void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data); @Override void saveFromActivity(Activity activity, String username, String email, String password, String pictureUrl, CredentialStoreCallback callback); @Override void loginFromActivity(Activity activity); void disableAutoSignIn(); @Override void onConnected(Bundle bundle); @Override void onConnectionSuspended(int i); @Override void onConnectionFailed(ConnectionResult connectionResult); @Override CredentialStore getCredentialStore(); static SmartLock getSmartLock(Activity activity); static final int SMART_LOCK_READ; static final int SMART_LOCK_SAVE; }
@Test public void shouldShowLockWhenFailedShowResolution() throws Exception { when(status.hasResolution()).thenReturn(true); when(status.getStatusCode()).thenReturn(CommonStatusCodes.RESOLUTION_REQUIRED); final IntentSender.SendIntentException exception = new IntentSender.SendIntentException(); doThrow(exception).when(status).startResolutionForResult(eq(activity), eq(SmartLock.SMART_LOCK_READ)); smartLock.onCredentialRetrievalError(activity, status, SmartLock.SMART_LOCK_READ); verify(status).startResolutionForResult(eq(activity), eq(SmartLock.SMART_LOCK_READ)); verifyLockStartedFromActivity(activity); }
@Test public void shouldShowResolutionDialogWhenFailedToFetchCredentials() throws Exception { when(status.hasResolution()).thenReturn(true); when(status.getStatusCode()).thenReturn(CommonStatusCodes.RESOLUTION_REQUIRED); smartLock.onCredentialRetrievalError(activity, status, SmartLock.SMART_LOCK_READ); verify(status).startResolutionForResult(eq(activity), eq(SmartLock.SMART_LOCK_READ)); }
@Test public void shouldStartLockOnUnrecoverableErrorWhenFetcingCredentials() throws Exception { when(status.hasResolution()).thenReturn(false); smartLock.onCredentialRetrievalError(activity, status, SmartLock.SMART_LOCK_READ); verify(status, never()).startResolutionForResult(eq(activity), eq(SmartLock.SMART_LOCK_READ)); verifyLockStartedFromActivity(activity); }