Android Open Source - sqlite-provider Extended S Q Lite Open Helper Test

From Project

Back to project page sqlite-provider.


The source code is released under:

Apache License

If you think the Android project sqlite-provider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package novoda.lib.sqliteprovider.sqlite;
//from   ww w.  j  a  va2  s  .c  o  m
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.Suppress;

public class ExtendedSQLiteOpenHelperTest extends AndroidTestCase {

    private ExtendedSQLiteOpenHelper helper;

    protected void setUp() throws Exception {
        helper = new ExtendedSQLiteOpenHelper(getContext());

    protected void tearDown() throws Exception {
        for (String db : getContext().databaseList()) {

    public void testGetTableNames() throws Exception {
        helper.getWritableDatabase().execSQL("CREATE TABLE 'test'(id integer);");

        assertTrue("Table 'test' was not returned from getTables()", helper.getTables().contains("test"));

    // this should pass .. why it doesn't is an sql mystery
    public void testSettingFKFromCreateStatement() throws Exception {
        insertOne2Many("parent", "child");
        ContentValues values = new ContentValues();
        values.put("parent_id", 3);
        try {
            helper.getWritableDatabase().insert("child", null, values);
            fail("should throw an error upon insert against a one2many relationship");
        } catch (SQLiteException e) {

    private void insertOne2Many(String parentTable, String childTable) {
        SQLiteDatabase db = helper.getWritableDatabase();
        db.execSQL("CREATE TABLE '" + parentTable + "'(_id INTEGER PRIMARY KEY);");
        db.execSQL("CREATE TABLE '" + childTable + "'(_id INTEGER PRIMARY KEY, " + parentTable + "_id INTEGER, FOREIGN KEY(" + parentTable
                + "_id ) REFERENCES " + parentTable + "(_id) );");

Java Source Code List