validate Cursor by asset statement - Android App

Android examples for App:Assets

Description

validate Cursor by asset statement

Demo Code


import android.content.ContentValues;
import android.database.Cursor;
import android.test.AndroidTestCase;
import java.util.Map;
import java.util.Set;

public class Main{
    public static 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);/* w  ww .  jav a 2  s. c  o  m*/
            String expectedValue = entry.getValue().toString();
            assertEquals(expectedValue, valueCursor.getString(idx));
        }
        valueCursor.close();
    }
}

Related Tutorials