@Test public void getSource() { when(database.query( anyString(), any(String[].class), eq("s.remote_id=?"), eq(new String[] {"1"}), eq((String) null), eq((String) null), eq((String) null))) .thenReturn(cursor); when(cursor.moveToFirst()).thenReturn(true); assertNotNull(source.getSource(1)); }
public Source getSource(long remoteId) { Cursor cursor = database.query( SourceModel.TABLE + " s left outer join " + CategoryModel.TABLE + " c on " + "s." + SourceModel.COLUMN_CATEGORY_ID + " = " + "c." + CategoryModel.COLUMN_ID, new String[] { "s." + SourceModel.COLUMN_ID + " as s" + SourceModel.COLUMN_ID, "s." + SourceModel.COLUMN_NAME + " as s" + SourceModel.COLUMN_NAME, "s." + SourceModel.COLUMN_IMAGE_URL + " as s" + SourceModel.COLUMN_IMAGE_URL, "s." + SourceModel.COLUMN_REMOTE_ID + " as s" + SourceModel.COLUMN_REMOTE_ID, "c." + CategoryModel.COLUMN_ID + " as c" + CategoryModel.COLUMN_ID, "c." + CategoryModel.COLUMN_NAME + " as c" + CategoryModel.COLUMN_NAME }, "s." + SourceModel.COLUMN_REMOTE_ID + "=?", new String[] {Long.toString(remoteId)}, null, null, null); if (cursor.moveToFirst()) { Source source = new Source(cursor); cursor.close(); return source; } else { return null; } }
DataSource { public Source getSource(long remoteId) { Cursor cursor = database.query( SourceModel.TABLE + " s left outer join " + CategoryModel.TABLE + " c on " + "s." + SourceModel.COLUMN_CATEGORY_ID + " = " + "c." + CategoryModel.COLUMN_ID, new String[] { "s." + SourceModel.COLUMN_ID + " as s" + SourceModel.COLUMN_ID, "s." + SourceModel.COLUMN_NAME + " as s" + SourceModel.COLUMN_NAME, "s." + SourceModel.COLUMN_IMAGE_URL + " as s" + SourceModel.COLUMN_IMAGE_URL, "s." + SourceModel.COLUMN_REMOTE_ID + " as s" + SourceModel.COLUMN_REMOTE_ID, "c." + CategoryModel.COLUMN_ID + " as c" + CategoryModel.COLUMN_ID, "c." + CategoryModel.COLUMN_NAME + " as c" + CategoryModel.COLUMN_NAME }, "s." + SourceModel.COLUMN_REMOTE_ID + "=?", new String[] {Long.toString(remoteId)}, null, null, null); if (cursor.moveToFirst()) { Source source = new Source(cursor); cursor.close(); return source; } else { return null; } } }
DataSource { public Source getSource(long remoteId) { Cursor cursor = database.query( SourceModel.TABLE + " s left outer join " + CategoryModel.TABLE + " c on " + "s." + SourceModel.COLUMN_CATEGORY_ID + " = " + "c." + CategoryModel.COLUMN_ID, new String[] { "s." + SourceModel.COLUMN_ID + " as s" + SourceModel.COLUMN_ID, "s." + SourceModel.COLUMN_NAME + " as s" + SourceModel.COLUMN_NAME, "s." + SourceModel.COLUMN_IMAGE_URL + " as s" + SourceModel.COLUMN_IMAGE_URL, "s." + SourceModel.COLUMN_REMOTE_ID + " as s" + SourceModel.COLUMN_REMOTE_ID, "c." + CategoryModel.COLUMN_ID + " as c" + CategoryModel.COLUMN_ID, "c." + CategoryModel.COLUMN_NAME + " as c" + CategoryModel.COLUMN_NAME }, "s." + SourceModel.COLUMN_REMOTE_ID + "=?", new String[] {Long.toString(remoteId)}, null, null, null); if (cursor.moveToFirst()) { Source source = new Source(cursor); cursor.close(); return source; } else { return null; } } private  DataSource(Context context); @VisibleForTesting  DataSource(DatabaseSQLiteHelper helper); @VisibleForTesting  DataSource(SQLiteDatabase database); }
DataSource { public Source getSource(long remoteId) { Cursor cursor = database.query( SourceModel.TABLE + " s left outer join " + CategoryModel.TABLE + " c on " + "s." + SourceModel.COLUMN_CATEGORY_ID + " = " + "c." + CategoryModel.COLUMN_ID, new String[] { "s." + SourceModel.COLUMN_ID + " as s" + SourceModel.COLUMN_ID, "s." + SourceModel.COLUMN_NAME + " as s" + SourceModel.COLUMN_NAME, "s." + SourceModel.COLUMN_IMAGE_URL + " as s" + SourceModel.COLUMN_IMAGE_URL, "s." + SourceModel.COLUMN_REMOTE_ID + " as s" + SourceModel.COLUMN_REMOTE_ID, "c." + CategoryModel.COLUMN_ID + " as c" + CategoryModel.COLUMN_ID, "c." + CategoryModel.COLUMN_NAME + " as c" + CategoryModel.COLUMN_NAME }, "s." + SourceModel.COLUMN_REMOTE_ID + "=?", new String[] {Long.toString(remoteId)}, null, null, null); if (cursor.moveToFirst()) { Source source = new Source(cursor); cursor.close(); return source; } else { return null; } } private  DataSource(Context context); @VisibleForTesting  DataSource(DatabaseSQLiteHelper helper); @VisibleForTesting  DataSource(SQLiteDatabase database); static DataSource get(Context context); synchronized void open(); boolean isOpen(); synchronized void close(); @VisibleForTesting SQLiteDatabase getDatabase(); void clearTables(); void beginTransaction(); void execSql(String sql); Cursor rawQuery(String sql); void setTransactionSuccessful(); void endTransaction(); long insertArticle(Article article); int updateSavedArticleState(Article article); int updateArticleInsertedAtTimestamp(Article article); void updateArticleContent(Article article); Article getArticle(String url); Cursor getAllArticles(); Cursor getSavedArticles(); Cursor getArticlesForSource(long remoteSourceId); void deleteArticle(Article article); void deleteArticle(long articleId); long insertCategory(String categoryName); void insertSource(Source source); void deleteSource(String name); List<Source> getSources(); Source getSource(long remoteId); CategoryCounts getCategoryCounts(long timestamp); }
DataSource { public Source getSource(long remoteId) { Cursor cursor = database.query( SourceModel.TABLE + " s left outer join " + CategoryModel.TABLE + " c on " + "s." + SourceModel.COLUMN_CATEGORY_ID + " = " + "c." + CategoryModel.COLUMN_ID, new String[] { "s." + SourceModel.COLUMN_ID + " as s" + SourceModel.COLUMN_ID, "s." + SourceModel.COLUMN_NAME + " as s" + SourceModel.COLUMN_NAME, "s." + SourceModel.COLUMN_IMAGE_URL + " as s" + SourceModel.COLUMN_IMAGE_URL, "s." + SourceModel.COLUMN_REMOTE_ID + " as s" + SourceModel.COLUMN_REMOTE_ID, "c." + CategoryModel.COLUMN_ID + " as c" + CategoryModel.COLUMN_ID, "c." + CategoryModel.COLUMN_NAME + " as c" + CategoryModel.COLUMN_NAME }, "s." + SourceModel.COLUMN_REMOTE_ID + "=?", new String[] {Long.toString(remoteId)}, null, null, null); if (cursor.moveToFirst()) { Source source = new Source(cursor); cursor.close(); return source; } else { return null; } } private  DataSource(Context context); @VisibleForTesting  DataSource(DatabaseSQLiteHelper helper); @VisibleForTesting  DataSource(SQLiteDatabase database); static DataSource get(Context context); synchronized void open(); boolean isOpen(); synchronized void close(); @VisibleForTesting SQLiteDatabase getDatabase(); void clearTables(); void beginTransaction(); void execSql(String sql); Cursor rawQuery(String sql); void setTransactionSuccessful(); void endTransaction(); long insertArticle(Article article); int updateSavedArticleState(Article article); int updateArticleInsertedAtTimestamp(Article article); void updateArticleContent(Article article); Article getArticle(String url); Cursor getAllArticles(); Cursor getSavedArticles(); Cursor getArticlesForSource(long remoteSourceId); void deleteArticle(Article article); void deleteArticle(long articleId); long insertCategory(String categoryName); void insertSource(Source source); void deleteSource(String name); List<Source> getSources(); Source getSource(long remoteId); CategoryCounts getCategoryCounts(long timestamp);  }