FileDocCategorySizeDatePackage
DatabaseTestUtils.javaAPI DocAndroid 1.5 API1890Wed May 06 22:42:02 BST 2009android.test

DatabaseTestUtils

public class DatabaseTestUtils extends Object
A collection of utilities for writing unit tests for database code.
hide
pending API council approval

Fields Summary
Constructors Summary
Methods Summary
public static voidassertSchemaEquals(android.database.sqlite.SQLiteDatabase expectedDb, android.database.sqlite.SQLiteDatabase db)
Compares the schema of two databases and asserts that they are equal.

param
expectedDb the db that is known to have the correct schema
param
db the db whose schema should be checked

        Set<String> expectedSchema = getSchemaSet(expectedDb);
        Set<String> schema = getSchemaSet(db);
        MoreAsserts.assertEquals(expectedSchema, schema);
    
private static java.util.SetgetSchemaSet(android.database.sqlite.SQLiteDatabase db)

        Set<String> schemaSet = Sets.newHashSet();

        Cursor entityCursor = db.rawQuery("SELECT sql FROM sqlite_master", null);
        try {
            while (entityCursor.moveToNext()) {
                String sql = entityCursor.getString(0);
                schemaSet.add(sql);
            }
        } finally {
            entityCursor.close();
        }
        return schemaSet;