@Test public void onCreateWithOneContentWritesSQLCorrectly() { final DatabaseHelper databaseHelper = new DatabaseHelper(mContext, "TEST_DB", 1) { @Override public List<Content> getContent(Context context) { final Content mockContent = new MockContent("EMIR"); return Lists.newArrayList(mockContent); } }; databaseHelper.onCreate(mSqLiteDatabase); verify(mSqLiteDatabase).execSQL("CREATE TABLE EMIR;"); }
@Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { final ContentVersionTable contentVersionTable = new ContentVersionTable(); final String contentVersionTableCreate = contentVersionTable.getCreate(mContext); sqLiteDatabase.execSQL(contentVersionTableCreate); final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(create); final int newVersion = content.getVersion(mContext); final String contentName = content.getName(mContext); final Uri uri = UriUtilities.getUri(ContentResolver.SCHEME_CONTENT, AUTHORITY, ContentVersionTable.Paths.PATH, contentName); final ContentValues contentValues = new ContentValues(); contentValues.put(ContentVersionTable.Columns.VERSION, newVersion); final Uri insertUri = contentVersionTable.insert(mContext, sqLiteDatabase, ContentVersionTable.Paths.PATH, uri, contentValues); } }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { final ContentVersionTable contentVersionTable = new ContentVersionTable(); final String contentVersionTableCreate = contentVersionTable.getCreate(mContext); sqLiteDatabase.execSQL(contentVersionTableCreate); final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(create); final int newVersion = content.getVersion(mContext); final String contentName = content.getName(mContext); final Uri uri = UriUtilities.getUri(ContentResolver.SCHEME_CONTENT, AUTHORITY, ContentVersionTable.Paths.PATH, contentName); final ContentValues contentValues = new ContentValues(); contentValues.put(ContentVersionTable.Columns.VERSION, newVersion); final Uri insertUri = contentVersionTable.insert(mContext, sqLiteDatabase, ContentVersionTable.Paths.PATH, uri, contentValues); } } }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { final ContentVersionTable contentVersionTable = new ContentVersionTable(); final String contentVersionTableCreate = contentVersionTable.getCreate(mContext); sqLiteDatabase.execSQL(contentVersionTableCreate); final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(create); final int newVersion = content.getVersion(mContext); final String contentName = content.getName(mContext); final Uri uri = UriUtilities.getUri(ContentResolver.SCHEME_CONTENT, AUTHORITY, ContentVersionTable.Paths.PATH, contentName); final ContentValues contentValues = new ContentValues(); contentValues.put(ContentVersionTable.Columns.VERSION, newVersion); final Uri insertUri = contentVersionTable.insert(mContext, sqLiteDatabase, ContentVersionTable.Paths.PATH, uri, contentValues); } } DatabaseHelper(final Context context, final String name, final int version); }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { final ContentVersionTable contentVersionTable = new ContentVersionTable(); final String contentVersionTableCreate = contentVersionTable.getCreate(mContext); sqLiteDatabase.execSQL(contentVersionTableCreate); final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(create); final int newVersion = content.getVersion(mContext); final String contentName = content.getName(mContext); final Uri uri = UriUtilities.getUri(ContentResolver.SCHEME_CONTENT, AUTHORITY, ContentVersionTable.Paths.PATH, contentName); final ContentValues contentValues = new ContentValues(); contentValues.put(ContentVersionTable.Columns.VERSION, newVersion); final Uri insertUri = contentVersionTable.insert(mContext, sqLiteDatabase, ContentVersionTable.Paths.PATH, uri, contentValues); } } DatabaseHelper(final Context context, final String name, final int version); @Override SQLiteDatabase getWritableDatabase(); abstract List<Content> getContent(final Context context); @Override void onOpen(final SQLiteDatabase sqLiteDatabase); @Override void onCreate(final SQLiteDatabase sqLiteDatabase); @Override void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion); }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { final ContentVersionTable contentVersionTable = new ContentVersionTable(); final String contentVersionTableCreate = contentVersionTable.getCreate(mContext); sqLiteDatabase.execSQL(contentVersionTableCreate); final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(create); final int newVersion = content.getVersion(mContext); final String contentName = content.getName(mContext); final Uri uri = UriUtilities.getUri(ContentResolver.SCHEME_CONTENT, AUTHORITY, ContentVersionTable.Paths.PATH, contentName); final ContentValues contentValues = new ContentValues(); contentValues.put(ContentVersionTable.Columns.VERSION, newVersion); final Uri insertUri = contentVersionTable.insert(mContext, sqLiteDatabase, ContentVersionTable.Paths.PATH, uri, contentValues); } } DatabaseHelper(final Context context, final String name, final int version); @Override SQLiteDatabase getWritableDatabase(); abstract List<Content> getContent(final Context context); @Override void onOpen(final SQLiteDatabase sqLiteDatabase); @Override void onCreate(final SQLiteDatabase sqLiteDatabase); @Override void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion);  }