2222import org .gnucash .android .db .DatabaseHelper ;
2323import org .gnucash .android .db .adapter .AccountsDbAdapter ;
2424import org .gnucash .android .db .adapter .BooksDbAdapter ;
25+ import org .gnucash .android .db .adapter .RecurrenceDbAdapter ;
26+ import org .gnucash .android .db .adapter .ScheduledActionDbAdapter ;
2527import org .gnucash .android .db .adapter .SplitsDbAdapter ;
2628import org .gnucash .android .db .adapter .TransactionsDbAdapter ;
2729import org .gnucash .android .export .xml .GncXmlHelper ;
2830import org .gnucash .android .importer .GncXmlHandler ;
2931import org .gnucash .android .model .Account ;
3032import org .gnucash .android .model .AccountType ;
3133import org .gnucash .android .model .Money ;
34+ import org .gnucash .android .model .ScheduledAction ;
3235import org .gnucash .android .model .Split ;
3336import org .gnucash .android .model .Transaction ;
3437import org .gnucash .android .model .TransactionType ;
4750import java .io .IOException ;
4851import java .io .InputStream ;
4952import java .text .ParseException ;
53+ import java .util .Calendar ;
54+ import java .util .Date ;
5055
5156import javax .xml .parsers .ParserConfigurationException ;
5257import javax .xml .parsers .SAXParser ;
@@ -64,6 +69,7 @@ public class GncXmlHandlerTest {
6469 private BooksDbAdapter mBooksDbAdapter ;
6570 private TransactionsDbAdapter mTransactionsDbAdapter ;
6671 private AccountsDbAdapter mAccountsDbAdapter ;
72+ private ScheduledActionDbAdapter mScheduledActionDbAdapter ;
6773
6874 @ Before
6975 public void setUp () throws Exception {
@@ -95,6 +101,8 @@ private void setUpDbAdapters(String bookUID) {
95101 SQLiteDatabase mainDb = databaseHelper .getReadableDatabase ();
96102 mTransactionsDbAdapter = new TransactionsDbAdapter (mainDb , new SplitsDbAdapter (mainDb ));
97103 mAccountsDbAdapter = new AccountsDbAdapter (mainDb , mTransactionsDbAdapter );
104+ RecurrenceDbAdapter recurrenceDbAdapter = new RecurrenceDbAdapter (mainDb );
105+ mScheduledActionDbAdapter = new ScheduledActionDbAdapter (mainDb , recurrenceDbAdapter );
98106 }
99107
100108 /**
@@ -334,6 +342,31 @@ public void simpleScheduledTransactionImport() throws ParseException {
334342 assertThat (split2 .isPairOf (split1 )).isTrue ();
335343 }
336344
345+ /**
346+ * Tests that importing a weekly scheduled action sets the days of the
347+ * week of the recursion.
348+ */
349+ @ Test
350+ public void importingScheduledAction_shouldSetByDays () throws ParseException {
351+ String bookUID = importGnuCashXml ("importingScheduledAction_shouldSetByDays.xml" );
352+ setUpDbAdapters (bookUID );
353+
354+ ScheduledAction scheduledTransaction =
355+ mScheduledActionDbAdapter .getRecord ("b5a13acb5a9459ebed10d06b75bbad10" );
356+
357+ // There are 3 byDays but, for now, getting one is enough to ensure it is executed
358+ assertThat (scheduledTransaction .getRecurrence ().getByDays ().size ()).isGreaterThanOrEqualTo (1 );
359+
360+ // Until we implement parsing of days of the week for scheduled actions,
361+ // we'll just use the day of the week of the start time.
362+ int dayOfWeekFromByDays = scheduledTransaction .getRecurrence ().getByDays ().get (0 );
363+ Date startTime = new Date (scheduledTransaction .getStartTime ());
364+ Calendar calendar = Calendar .getInstance ();
365+ calendar .setTime (startTime );
366+ int dayOfWeekFromStartTime = calendar .get (Calendar .DAY_OF_WEEK );
367+ assertThat (dayOfWeekFromByDays ).isEqualTo (dayOfWeekFromStartTime );
368+ }
369+
337370 /**
338371 * Checks for bug 562 - Scheduled transaction imported with imbalanced splits.
339372 *
0 commit comments