actions = new ArrayList<>();
actions.add(scheduledAction);
ScheduledActionService.processScheduledActions(actions, mDb);
+
+ //no change in the database since no action UID was specified
+ assertThat(transactionsDbAdapter.getRecordsCount()).isZero();
}
@Test
@@ -297,6 +305,36 @@ public void scheduledBackups_shouldRunOnlyOnce(){
assertThat(backupFiles[0]).exists().hasExtension("gnca");
}
+ /**
+ * Tests that a scheduled backup isn't executed before the next scheduled
+ * execution according to its recurrence.
+ *
+ * Tests for bug https://github.com/codinguser/gnucash-android/issues/583
+ */
+ @Test
+ public void scheduledBackups_shouldNotRunBeforeNextScheduledExecution(){
+ ScheduledAction scheduledBackup = new ScheduledAction(ScheduledAction.ActionType.BACKUP);
+ scheduledBackup.setStartTime(LocalDateTime.now().minusDays(2).toDate().getTime());
+ scheduledBackup.setExecutionCount(1);
+ scheduledBackup.setRecurrence(PeriodType.WEEK, 1);
+
+ ExportParams backupParams = new ExportParams(ExportFormat.XML);
+ backupParams.setExportTarget(ExportParams.ExportTarget.SD_CARD);
+ scheduledBackup.setTag(backupParams.toCsv());
+
+ File backupFolder = new File(
+ Exporter.getExportFolderPath(BooksDbAdapter.getInstance().getActiveBookUID()));
+ assertThat(backupFolder).exists();
+ assertThat(backupFolder.listFiles()).isEmpty();
+
+ List actions = new ArrayList<>();
+ actions.add(scheduledBackup);
+ ScheduledActionService.processScheduledActions(actions, mDb);
+
+ assertThat(scheduledBackup.getExecutionCount()).isEqualTo(1);
+ assertThat(backupFolder.listFiles()).hasSize(0);
+ }
+
@After
public void tearDown(){
TransactionsDbAdapter.getInstance().deleteAllRecords();