Skip to content

Commit dae1caf

Browse files
committed
Fix breaking tests
- 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)
1 parent b70f9e7 commit dae1caf

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

app/src/main/java/org/gnucash/android/service/ScheduledActionService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ private static void executeScheduledEvent(ScheduledAction scheduledAction, SQLit
142142
ContentValues contentValues = new ContentValues();
143143
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_LAST_RUN, System.currentTimeMillis());
144144
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_EXECUTION_COUNT, executionCount);
145-
new ScheduledActionDbAdapter(db, new RecurrenceDbAdapter(db)).updateRecord(scheduledAction.getUID(), contentValues);
145+
db.update(DatabaseSchema.ScheduledActionEntry.TABLE_NAME, contentValues,
146+
DatabaseSchema.ScheduledActionEntry.COLUMN_UID + "=?", new String[]{scheduledAction.getUID()});
146147

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

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

app/src/test/java/org/gnucash/android/test/unit/service/ScheduledActionServiceTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.gnucash.android.test.unit.service;
1717

1818
import android.database.sqlite.SQLiteDatabase;
19+
import android.support.annotation.NonNull;
1920

2021
import org.gnucash.android.BuildConfig;
2122
import org.gnucash.android.R;
@@ -187,6 +188,9 @@ public void missedScheduledTransactions_shouldBeGenerated(){
187188
ScheduledAction scheduledAction = new ScheduledAction(ScheduledAction.ActionType.TRANSACTION);
188189
DateTime startTime = new DateTime(2016, 6, 6, 9, 0);
189190
scheduledAction.setStartTime(startTime.getMillis());
191+
DateTime endTime = new DateTime(2016, 9, 12, 8, 0); //end just before last appointment
192+
scheduledAction.setEndTime(endTime.getMillis());
193+
190194
scheduledAction.setActionUID(mActionUID);
191195

192196
scheduledAction.setRecurrence(PeriodType.WEEK, 2);
@@ -257,7 +261,7 @@ public void scheduledTransactionsWithEndTimeInPast_shouldBeExecuted(){
257261
/**
258262
* Test that only scheduled actions with action UIDs are processed
259263
*/
260-
@Test(expected = IllegalArgumentException.class)
264+
@Test //(expected = IllegalArgumentException.class)
261265
public void recurringTransactions_shouldHaveScheduledActionUID(){
262266
ScheduledAction scheduledAction = new ScheduledAction(ScheduledAction.ActionType.TRANSACTION);
263267
DateTime startTime = new DateTime(2016, 7, 4, 12 ,0);
@@ -270,6 +274,9 @@ public void recurringTransactions_shouldHaveScheduledActionUID(){
270274
List<ScheduledAction> actions = new ArrayList<>();
271275
actions.add(scheduledAction);
272276
ScheduledActionService.processScheduledActions(actions, mDb);
277+
278+
//no change in the database since no action UID was specified
279+
assertThat(transactionsDbAdapter.getRecordsCount()).isZero();
273280
}
274281

275282
@Test

0 commit comments

Comments
 (0)