|
48 | 48 | import org.gnucash.android.util.BookUtils; |
49 | 49 | import org.gnucash.android.util.TimestampHelper; |
50 | 50 | import org.joda.time.DateTime; |
| 51 | +import org.joda.time.DateTimeConstants; |
51 | 52 | import org.joda.time.LocalDateTime; |
52 | 53 | import org.joda.time.Weeks; |
53 | 54 | import org.junit.After; |
|
63 | 64 | import java.math.BigDecimal; |
64 | 65 | import java.sql.Timestamp; |
65 | 66 | import java.util.ArrayList; |
| 67 | +import java.util.Calendar; |
| 68 | +import java.util.Collections; |
66 | 69 | import java.util.List; |
67 | 70 |
|
68 | 71 | import javax.xml.parsers.ParserConfigurationException; |
@@ -199,8 +202,10 @@ public void missedScheduledTransactions_shouldBeGenerated(){ |
199 | 202 |
|
200 | 203 | scheduledAction.setActionUID(mActionUID); |
201 | 204 |
|
202 | | - int multiplier = 2; |
203 | | - scheduledAction.setRecurrence(PeriodType.WEEK, multiplier); |
| 205 | + Recurrence recurrence = new Recurrence(PeriodType.WEEK); |
| 206 | + recurrence.setMultiplier(2); |
| 207 | + recurrence.setByDays(Collections.singletonList(Calendar.MONDAY)); |
| 208 | + scheduledAction.setRecurrence(recurrence); |
204 | 209 | ScheduledActionDbAdapter.getInstance().addRecord(scheduledAction, DatabaseAdapter.UpdateMethod.insert); |
205 | 210 |
|
206 | 211 | TransactionsDbAdapter transactionsDbAdapter = TransactionsDbAdapter.getInstance(); |
@@ -249,7 +254,10 @@ public void scheduledTransactionsWithEndTimeInPast_shouldBeExecuted(){ |
249 | 254 | scheduledAction.setStartTime(startTime.getMillis()); |
250 | 255 | scheduledAction.setActionUID(mActionUID); |
251 | 256 |
|
252 | | - scheduledAction.setRecurrence(PeriodType.WEEK, 2); |
| 257 | + Recurrence recurrence = new Recurrence(PeriodType.WEEK); |
| 258 | + recurrence.setMultiplier(2); |
| 259 | + recurrence.setByDays(Collections.singletonList(Calendar.MONDAY)); |
| 260 | + scheduledAction.setRecurrence(recurrence); |
253 | 261 | scheduledAction.setEndTime(new DateTime(2016, 8, 8, 9, 0).getMillis()); |
254 | 262 | ScheduledActionDbAdapter.getInstance().addRecord(scheduledAction, DatabaseAdapter.UpdateMethod.insert); |
255 | 263 |
|
@@ -345,11 +353,15 @@ public void scheduledBackups_shouldRunOnlyOnce(){ |
345 | 353 | @Test |
346 | 354 | public void scheduledBackups_shouldNotRunBeforeNextScheduledExecution(){ |
347 | 355 | ScheduledAction scheduledBackup = new ScheduledAction(ScheduledAction.ActionType.BACKUP); |
348 | | - scheduledBackup.setStartTime(LocalDateTime.now().minusDays(2).toDate().getTime()); |
| 356 | + scheduledBackup.setStartTime( |
| 357 | + LocalDateTime.now().withDayOfWeek(DateTimeConstants.WEDNESDAY).toDate().getTime()); |
349 | 358 | scheduledBackup.setLastRun(scheduledBackup.getStartTime()); |
350 | 359 | long previousLastRun = scheduledBackup.getLastRunTime(); |
351 | 360 | scheduledBackup.setExecutionCount(1); |
352 | | - scheduledBackup.setRecurrence(PeriodType.WEEK, 1); |
| 361 | + Recurrence recurrence = new Recurrence(PeriodType.WEEK); |
| 362 | + recurrence.setMultiplier(1); |
| 363 | + recurrence.setByDays(Collections.singletonList(Calendar.MONDAY)); |
| 364 | + scheduledBackup.setRecurrence(recurrence); |
353 | 365 |
|
354 | 366 | ExportParams backupParams = new ExportParams(ExportFormat.XML); |
355 | 367 | backupParams.setExportTarget(ExportParams.ExportTarget.SD_CARD); |
@@ -380,7 +392,10 @@ public void scheduledBackups_shouldNotIncludeTransactionsPreviousToTheLastRun() |
380 | 392 | scheduledBackup.setLastRun(LocalDateTime.now().minusDays(8).toDate().getTime()); |
381 | 393 | long previousLastRun = scheduledBackup.getLastRunTime(); |
382 | 394 | scheduledBackup.setExecutionCount(1); |
383 | | - scheduledBackup.setRecurrence(PeriodType.WEEK, 1); |
| 395 | + Recurrence recurrence = new Recurrence(PeriodType.WEEK); |
| 396 | + recurrence.setMultiplier(1); |
| 397 | + recurrence.setByDays(Collections.singletonList(Calendar.WEDNESDAY)); |
| 398 | + scheduledBackup.setRecurrence(recurrence); |
384 | 399 | ExportParams backupParams = new ExportParams(ExportFormat.QIF); |
385 | 400 | backupParams.setExportTarget(ExportParams.ExportTarget.SD_CARD); |
386 | 401 | backupParams.setExportStartTime(new Timestamp(scheduledBackup.getStartTime())); |
@@ -438,7 +453,10 @@ public void scheduledBackups_shouldIncludeTransactionsAfterTheLastRun() { |
438 | 453 | scheduledBackup.setLastRun(LocalDateTime.now().minusDays(8).toDate().getTime()); |
439 | 454 | long previousLastRun = scheduledBackup.getLastRunTime(); |
440 | 455 | scheduledBackup.setExecutionCount(1); |
441 | | - scheduledBackup.setRecurrence(PeriodType.WEEK, 1); |
| 456 | + Recurrence recurrence = new Recurrence(PeriodType.WEEK); |
| 457 | + recurrence.setMultiplier(1); |
| 458 | + recurrence.setByDays(Collections.singletonList(Calendar.FRIDAY)); |
| 459 | + scheduledBackup.setRecurrence(recurrence); |
442 | 460 | ExportParams backupParams = new ExportParams(ExportFormat.QIF); |
443 | 461 | backupParams.setExportTarget(ExportParams.ExportTarget.SD_CARD); |
444 | 462 | backupParams.setExportStartTime(new Timestamp(scheduledBackup.getStartTime())); |
|
0 commit comments