private void checkCredentials() throws RequiresLoginException { if (!getAuthPreferences().isLoginInformationSet()) { throw new RequiresLoginException(); } }
private void mockScheduled() { when(authPreferences.isLoginInformationSet()).thenReturn(true); when(preferences.isAutoBackupEnabled()).thenReturn(true); when(preferences.isFirstBackup()).thenReturn(false); when(preferences.isUseOldScheduler()).thenReturn(true); } }
@Test public void shouldNotScheduleIfLoginInformationIsNotSet() throws Exception { mockScheduled(); when(authPreferences.isLoginInformationSet()).thenReturn(false); receiver.onReceive(context, new Intent().setAction("android.provider.Telephony.SMS_RECEIVED")); verifyZeroInteractions(backupJobs); }
@Test public void shouldCheckForLoginCredentials() throws Exception { Intent intent = new Intent(); when(authPreferences.isLoginInformationSet()).thenReturn(false); shadowConnectivityManager.setBackgroundDataSetting(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresLoginException.class); }
@Test public void shouldCheckForEnabledDataTypes() throws Exception { when(dataTypePreferences.enabled()).thenReturn(EnumSet.noneOf(DataType.class)); Intent intent = new Intent(); when(authPreferences.isLoginInformationSet()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(BackupDisabledException.class); assertThat(service.getState().state).isEqualTo(SmsSyncState.FINISHED_BACKUP); }
private String getConnectedSummary(TwoStatePreference connected) { final String username = authPreferences.getOauth2Username(); if (connected.isEnabled()) { return connected.isChecked() && !TextUtils.isEmpty(username) ? getString(R.string.gmail_already_connected, username) : getString(R.string.gmail_needs_connecting); } else if (authPreferences.isLoginInformationSet()) { return getString(R.string.custom_imap, authPreferences.getImapUsername() + "@" + authPreferences.getServername()); } else { return getString(R.string.custom_imap_not_configured); } }
private boolean shouldSchedule(Context context) { final Preferences preferences = getPreferences(context); final boolean autoBackupEnabled = preferences.isAutoBackupEnabled(); final boolean loginInformationSet = getAuthPreferences(context).isLoginInformationSet(); final boolean firstBackup = preferences.isFirstBackup(); final boolean schedule = (autoBackupEnabled && loginInformationSet && !firstBackup); if (!schedule) { final String message = "Not set up to back up. " + "autoBackup=" + autoBackupEnabled + ", loginInfoSet=" + loginInformationSet + ", firstBackup=" + firstBackup; log(context, message, preferences.isAppLogDebug()); } return schedule; }
@Before public void before() { initMocks(this); sentNotifications = new ArrayList<NotificationCompat.Builder>(); service = new SmsBackupService() { @Override public Context getApplicationContext() { return RuntimeEnvironment.application; } @Override public Resources getResources() { return getApplicationContext().getResources(); } @Override protected BackupTask getBackupTask() { return backupTask; } @Override protected BackupJobs getBackupJobs() { return backupJobs; } @Override protected Preferences getPreferences() { return preferences; } @Override public int checkPermission(String permission, int pid, int uid) { return PERMISSION_GRANTED; } @Override protected AuthPreferences getAuthPreferences() { return authPreferences; } @Override protected void notifyUser(int icon, NotificationCompat.Builder builder) { sentNotifications.add(builder); } }; shadowConnectivityManager = shadowOf(service.getConnectivityManager()); shadowWifiManager = shadowOf(service.getWifiManager()); service.onCreate(); when(authPreferences.getStoreUri()).thenReturn("imap+ssl+://xoauth:foooo@imap.gmail.com:993"); when(authPreferences.isLoginInformationSet()).thenReturn(true); when(preferences.getBackupContactGroup()).thenReturn(ContactGroup.EVERYBODY); when(preferences.isUseOldScheduler()).thenReturn(true); when(preferences.getDataTypePreferences()).thenReturn(dataTypePreferences); when(dataTypePreferences.enabled()).thenReturn(EnumSet.of(DataType.SMS)); }
@Subscribe public void performAction(PerformAction action) { if (authPreferences.isLoginInformationSet()) { if (action.confirm) { showDialog(CONFIRM_ACTION, new BundleBuilder().putString(ACTION, action.action.name()).build()); } else if (preferences.isFirstBackup() && action.action == Backup) { showDialog(FIRST_SYNC); } else { doPerform(action.action); } } else { showDialog(MISSING_CREDENTIALS); } }