Advertisement
Guest User

Untitled

a guest
Aug 8th, 2015
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. // create the value to be tested
  2. ContentValues testValues = new ContentValues();
  3. testValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, "Beijing");
  4. testValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, "Beijing");
  5. testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, 39.916);
  6. testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, 116.383);
  7.  
  8. // schema of the table
  9. final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
  10. LocationEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
  11. LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
  12. LocationEntry.COLUMN_COORD_LAT + " decimal(10,10) NOT NULL, " +
  13. LocationEntry.COLUMN_COORD_LONG + " decimal(10,10) NOT NULL, " +
  14. LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL " +
  15. " );";
  16.  
  17. // validation where the exception is thrown
  18. static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
  19.     Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet();
  20.     for (Map.Entry<String, Object> entry : valueSet) {
  21.         String columnName = entry.getKey();
  22.         int idx = valueCursor.getColumnIndex(columnName);
  23.         assertFalse("Column '" + columnName + "' not found. " + error, idx == -1);
  24.         String expectedValue = entry.getValue().toString();
  25.         String gotValue = valueCursor.getString(idx);
  26.         assertEquals("Value '" + entry.getValue().toString() +
  27.                 "' did not match the expected value '" +
  28.                 expectedValue + "'. " + error, expectedValue.substring(0, 6), gotValue.substring(0, 6));
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement