BackupReminderTooltipManager implements TooltipManager { public Maybe<Integer> needToShowBackupReminder() { return Maybe.fromCallable(() -> { int prolongationsCount = backupReminderTooltipStorage.getProlongationsCount(); int receiptsLimit = NEW_RECEIPTS_LIMIT + NEW_RECEIPTS_LIMIT * prolongationsCount; int daysLimit = DAYS_WITHOUT_BACKUP_LIMIT + DAYS_WITHOUT_BACKUP_LIMIT * prolongationsCount; if (backupProvidersManager.getSyncProvider() == SyncProvider.None && backupReminderTooltipStorage.getReceiptsCountWithoutBackup() >= receiptsLimit) { long lastManualBackupTime = backupReminderTooltipStorage.getLastManualBackupDate().getTime(); if (lastManualBackupTime == 0) { return NO_PREVIOUS_BACKUPS_DAY; } else { int daysSinceLastManualBackup = (int) TimeUnit.MILLISECONDS.toDays(Math.abs(lastManualBackupTime - System.currentTimeMillis())); return daysSinceLastManualBackup >= daysLimit ? daysSinceLastManualBackup : null; } } else { return null; } }) .subscribeOn(Schedulers.io()); } @Inject  BackupReminderTooltipManager(@NonNull BackupProvidersManager backupProvidersManager,
                                        @NonNull BackupReminderTooltipStorage backupReminderTooltipStorage); Maybe<Integer> needToShowBackupReminder(); @Override void tooltipWasDismissed();  }
@Test public void getEmptyIfAutoBackupsEnabled() { when(backupProvidersManager.getSyncProvider()).thenReturn(SyncProvider.GoogleDrive); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertNoErrors() .assertNoValues(); }
@Test public void getEmptyIfFewReceiptsAndFewDays() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_FEW); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_FEW))); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertNoValues(); }
@Test public void getEmptyIfFewNewReceipts() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_FEW); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_LOT))); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertNoValues(); }
@Test public void getEmptyIfFewDays() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_LOT); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_FEW))); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertNoValues(); }
@Test public void getDays() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_LOT); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_LOT))); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertValue(days -> days == DAYS_LOT); }
@Test public void getEmptyBecauseOfProlongation() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_LOT); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_LOT))); when(storage.getProlongationsCount()).thenReturn(1); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertNoValues(); }
@Test public void getDaysAfterProlongation() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_LOT * 2); when(storage.getLastManualBackupDate()).thenReturn(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(DAYS_LOT) * 2)); when(storage.getProlongationsCount()).thenReturn(1); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertValue(days -> days == DAYS_LOT * 2); }
@Test public void getMessageIfLotReceiptsAndNoDays() { when(storage.getReceiptsCountWithoutBackup()).thenReturn(RECEIPTS_LOT); when(storage.getLastManualBackupDate()).thenReturn(new Date(0)); final TestObserver<Integer> testObserver = manager.needToShowBackupReminder().test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete() .assertComplete() .assertNoErrors() .assertValue(days -> days == NO_PREVIOUS_BACKUPS); }