Skip to content

Commit

Permalink
Fix breaking tests
Browse files Browse the repository at this point in the history
- Incomplete scheduled transactions do not throw exceptions when processed
- Set end time for a scheduled transaction to make test reliable over time (in terms of number of created transactions)
  • Loading branch information
codinguser committed Sep 15, 2016
1 parent b70f9e7 commit dae1caf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ private static void executeScheduledEvent(ScheduledAction scheduledAction, SQLit
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_LAST_RUN, System.currentTimeMillis());
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_EXECUTION_COUNT, executionCount);
new ScheduledActionDbAdapter(db, new RecurrenceDbAdapter(db)).updateRecord(scheduledAction.getUID(), contentValues);
db.update(DatabaseSchema.ScheduledActionEntry.TABLE_NAME, contentValues,
DatabaseSchema.ScheduledActionEntry.COLUMN_UID + "=?", new String[]{scheduledAction.getUID()});

//set the values in the object because they will be checked for the next iteration in the calling loop
scheduledAction.setExecutionCount(executionCount);
//set the execution count in the object because it will be checked for the next iteration in the calling loop
scheduledAction.setExecutionCount(executionCount); //this call is important, do not remove!!
}

/**
Expand Down Expand Up @@ -191,6 +192,7 @@ private static int executeTransactions(ScheduledAction scheduledAction, SQLiteDa
try {
trxnTemplate = transactionsDbAdapter.getRecord(actionUID);
} catch (IllegalArgumentException ex){ //if the record could not be found, abort
Log.e(LOG_TAG, "Scheduled action with UID " + actionUID + " could not be found in the db with path " + db.getPath());
return executionCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.gnucash.android.test.unit.service;

import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;

import org.gnucash.android.BuildConfig;
import org.gnucash.android.R;
Expand Down Expand Up @@ -187,6 +188,9 @@ public void missedScheduledTransactions_shouldBeGenerated(){
ScheduledAction scheduledAction = new ScheduledAction(ScheduledAction.ActionType.TRANSACTION);
DateTime startTime = new DateTime(2016, 6, 6, 9, 0);
scheduledAction.setStartTime(startTime.getMillis());
DateTime endTime = new DateTime(2016, 9, 12, 8, 0); //end just before last appointment
scheduledAction.setEndTime(endTime.getMillis());

scheduledAction.setActionUID(mActionUID);

scheduledAction.setRecurrence(PeriodType.WEEK, 2);
Expand Down Expand Up @@ -257,7 +261,7 @@ public void scheduledTransactionsWithEndTimeInPast_shouldBeExecuted(){
/**
* Test that only scheduled actions with action UIDs are processed
*/
@Test(expected = IllegalArgumentException.class)
@Test //(expected = IllegalArgumentException.class)
public void recurringTransactions_shouldHaveScheduledActionUID(){
ScheduledAction scheduledAction = new ScheduledAction(ScheduledAction.ActionType.TRANSACTION);
DateTime startTime = new DateTime(2016, 7, 4, 12 ,0);
Expand All @@ -270,6 +274,9 @@ public void recurringTransactions_shouldHaveScheduledActionUID(){
List<ScheduledAction> 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
Expand Down

0 comments on commit dae1caf

Please sign in to comment.