Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created April 19, 2015 04:40
Show Gist options
  • Save AdamMc331/c696791cc558e7ce5cdb to your computer and use it in GitHub Desktop.
Save AdamMc331/c696791cc558e7ce5cdb to your computer and use it in GitHub Desktop.
private void validateCursor(Cursor valueCursor, ContentValues expectedValues){
assertTrue(valueCursor.moveToFirst());
Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
for(Map.Entry<String, Object> entry : valueSet){
String columnName = entry.getKey();
int idx = valueCursor.getColumnIndex(columnName);
assertFalse(idx == -1);
switch(columnName){
case AccountEntry.COLUMN_BALANCE:
case AccountEntry.COLUMN_ALLOWANCE:
case TransactionEntry.COLUMN_AMOUNT: // Doubles
assertEquals(entry.getValue(), valueCursor.getDouble(idx));
break;
case AccountEntry.COLUMN_SPENDING_PERIOD: // Ints
assertEquals(entry.getValue(), valueCursor.getInt(idx));
break;
default: // Strings
assertEquals(entry.getValue().toString(), valueCursor.getString(idx));
break;
}
}
valueCursor.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment