SaveCredentialTask extends GoogleApiClientConnectTask { @Override void onConnected(final SmartLock smartLock, final Activity activity) { getCredentialsApi().save(smartLock.getCredentialClient(), getCredential()).setResultCallback(new ResultCallback<com.google.android.gms.common.api.Status>() { @Override public void onResult(com.google.android.gms.common.api.Status status) { if (resolveStatus(status, activity, smartLock)) { smartLock.clearCredentialStoreCallback(); } } private boolean resolveStatus(com.google.android.gms.common.api.Status status, Activity activity, SmartLock smartLock) { final CredentialStoreCallback callback = smartLock.getCallback(); if (status.isSuccess()) { Log.d(TAG, "Saved user's credentials in Smart Lock"); callback.onSuccess(); return true; } if (status.hasResolution()) { try { status.startResolutionForResult(activity, SmartLock.SMART_LOCK_SAVE); return false; } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Couldn't resolve Smart Lock save issues", e); callback.onError(CredentialStoreCallback.CREDENTIAL_STORE_SAVE_FAILED, e); } } else { callback.onError(CredentialStoreCallback.CREDENTIAL_STORE_SAVE_CANCELLED, null); } return true; } }); } SaveCredentialTask(Activity activity, Credential credential);   }
@Test public void shouldRequestSave() throws Exception { task.onConnected(smartLock, activity); verify(credentialsApi).save(eq(googleApiClient), eq(credential)); }
@Test public void shouldSetResultCallback() throws Exception { task.onConnected(smartLock, activity); verify(pendingResult).setResultCallback(Matchers.<ResultCallback<Status>>any()); }