SmartLock extends Lock implements CredentialStore, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { public static SmartLock getSmartLock(Activity activity) { Application application = activity.getApplication(); if (!(application instanceof LockProvider)) { throw new IllegalStateException("Android Application object must implement LockProvider interface"); } LockProvider provider = (LockProvider) application; final Lock lock = provider.getLock(); if (!(lock instanceof SmartLock)) { throw new IllegalStateException("LockProvider must return an instance of SmartLock"); } return (SmartLock) lock; } 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 shouldFetchSmartLock() throws Exception { Application application = mock(Application.class, withSettings().extraInterfaces(LockProvider.class)); when(((LockProvider)application).getLock()).thenReturn(smartLock); when(activity.getApplication()).thenReturn(application); assertThat(SmartLock.getSmartLock(activity), is(smartLock)); }
@Test public void shouldFailWhenApplicationDoesNotImplementLockProvider() throws Exception { expectedException.expect(IllegalStateException.class); Application application = mock(Application.class); when(activity.getApplication()).thenReturn(application); SmartLock.getSmartLock(activity); }
@Test public void shouldFailWhenLockIsNotSmartLock() throws Exception { expectedException.expect(IllegalStateException.class); Application application = mock(Application.class, withSettings().extraInterfaces(LockProvider.class)); when(((LockProvider)application).getLock()).thenReturn(mock(Lock.class)); when(activity.getApplication()).thenReturn(application); SmartLock.getSmartLock(activity); }