Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create the value to be tested
- ContentValues testValues = new ContentValues();
- testValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, "Beijing");
- testValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, "Beijing");
- testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, 39.916);
- testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, 116.383);
- // schema of the table
- final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
- LocationEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
- LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
- LocationEntry.COLUMN_COORD_LAT + " decimal(10,10) NOT NULL, " +
- LocationEntry.COLUMN_COORD_LONG + " decimal(10,10) NOT NULL, " +
- LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL " +
- " );";
- // validation where the exception is thrown
- static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) {
- 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("Column '" + columnName + "' not found. " + error, idx == -1);
- String expectedValue = entry.getValue().toString();
- String gotValue = valueCursor.getString(idx);
- assertEquals("Value '" + entry.getValue().toString() +
- "' did not match the expected value '" +
- expectedValue + "'. " + error, expectedValue.substring(0, 6), gotValue.substring(0, 6));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement