@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); }
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()); }
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()); } }
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); }
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(); }
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();  }