|
44 | 44 | import org.gnucash.android.test.unit.testutil.ShadowCrashlytics; |
45 | 45 | import org.gnucash.android.test.unit.testutil.ShadowUserVoice; |
46 | 46 | import org.joda.time.DateTime; |
| 47 | +import org.joda.time.LocalDateTime; |
47 | 48 | import org.joda.time.Weeks; |
48 | 49 | import org.junit.After; |
49 | 50 | import org.junit.Before; |
@@ -304,6 +305,36 @@ public void scheduledBackups_shouldRunOnlyOnce(){ |
304 | 305 | assertThat(backupFiles[0]).exists().hasExtension("gnca"); |
305 | 306 | } |
306 | 307 |
|
| 308 | + /** |
| 309 | + * Tests that a scheduled backup isn't executed before the next scheduled |
| 310 | + * execution according to its recurrence. |
| 311 | + * |
| 312 | + * <p>Tests for bug https://github.com/codinguser/gnucash-android/issues/583</p> |
| 313 | + */ |
| 314 | + @Test |
| 315 | + public void scheduledBackups_shouldNotRunBeforeNextScheduledExecution(){ |
| 316 | + ScheduledAction scheduledBackup = new ScheduledAction(ScheduledAction.ActionType.BACKUP); |
| 317 | + scheduledBackup.setStartTime(LocalDateTime.now().minusDays(2).toDate().getTime()); |
| 318 | + scheduledBackup.setExecutionCount(1); |
| 319 | + scheduledBackup.setRecurrence(PeriodType.WEEK, 1); |
| 320 | + |
| 321 | + ExportParams backupParams = new ExportParams(ExportFormat.XML); |
| 322 | + backupParams.setExportTarget(ExportParams.ExportTarget.SD_CARD); |
| 323 | + scheduledBackup.setTag(backupParams.toCsv()); |
| 324 | + |
| 325 | + File backupFolder = new File( |
| 326 | + Exporter.getExportFolderPath(BooksDbAdapter.getInstance().getActiveBookUID())); |
| 327 | + assertThat(backupFolder).exists(); |
| 328 | + assertThat(backupFolder.listFiles()).isEmpty(); |
| 329 | + |
| 330 | + List<ScheduledAction> actions = new ArrayList<>(); |
| 331 | + actions.add(scheduledBackup); |
| 332 | + ScheduledActionService.processScheduledActions(actions, mDb); |
| 333 | + |
| 334 | + assertThat(scheduledBackup.getExecutionCount()).isEqualTo(1); |
| 335 | + assertThat(backupFolder.listFiles()).hasSize(0); |
| 336 | + } |
| 337 | + |
307 | 338 | @After |
308 | 339 | public void tearDown(){ |
309 | 340 | TransactionsDbAdapter.getInstance().deleteAllRecords(); |
|
0 commit comments