@Test public void getArticle_noMatchingUrls() { when(database.query( anyString(), any(String[].class), eq("url=?"), eq(new String[] {"http: eq((String) null), eq((String) null), eq((String) null))) .thenReturn(cursor); when(cursor.moveToFirst()).thenReturn(false); assertNull(source.getArticle("http: }
public Article getArticle(String url) { url = ArticleUtils.removeUrlParameters(url); Cursor cursor = database.query( ArticleModel.TABLE + " a left outer join " + ContentModel.TABLE + " c " + "on a." + ArticleModel.COLUMN_ID + " = c." + ContentModel.COLUMN_ARTICLE_ID, new String[] { "a." + ArticleModel.COLUMN_ID + " as " + ArticleModel.COLUMN_ID, "a." + ArticleModel.COLUMN_ALIAS + " as " + ArticleModel.COLUMN_ALIAS, "a." + ArticleModel.COLUMN_URL + " as " + ArticleModel.COLUMN_URL, "a." + ArticleModel.COLUMN_TITLE + " as " + ArticleModel.COLUMN_TITLE, "a." + ArticleModel.COLUMN_DESCRIPTION + " as " + ArticleModel.COLUMN_DESCRIPTION, "a." + ArticleModel.COLUMN_IMAGE + " as " + ArticleModel.COLUMN_IMAGE, "a." + ArticleModel.COLUMN_AUTHOR + " as " + ArticleModel.COLUMN_AUTHOR, "a." + ArticleModel.COLUMN_SOURCE + " as " + ArticleModel.COLUMN_SOURCE, "a." + ArticleModel.COLUMN_DOMAIN + " as " + ArticleModel.COLUMN_DOMAIN, "a." + ArticleModel.COLUMN_DURATION + " as " + ArticleModel.COLUMN_DURATION, "a." + ArticleModel.COLUMN_INSERTED_AT + " as " + ArticleModel.COLUMN_INSERTED_AT, "a." + ArticleModel.COLUMN_IS_ARTICLE + " as " + ArticleModel.COLUMN_IS_ARTICLE, "a." + ArticleModel.COLUMN_SAVED + " as " + ArticleModel.COLUMN_SAVED, "c." + ContentModel.COLUMN_CONTENT + " as " + ContentModel.COLUMN_CONTENT, }, ArticleModel.COLUMN_URL + "=?", new String[] { url }, null, null, null); if (cursor != null && cursor.moveToFirst()) { Article article = new Article(cursor); cursor.close(); return article; } else { return null; } }
DataSource { public Article getArticle(String url) { url = ArticleUtils.removeUrlParameters(url); Cursor cursor = database.query( ArticleModel.TABLE + " a left outer join " + ContentModel.TABLE + " c " + "on a." + ArticleModel.COLUMN_ID + " = c." + ContentModel.COLUMN_ARTICLE_ID, new String[] { "a." + ArticleModel.COLUMN_ID + " as " + ArticleModel.COLUMN_ID, "a." + ArticleModel.COLUMN_ALIAS + " as " + ArticleModel.COLUMN_ALIAS, "a." + ArticleModel.COLUMN_URL + " as " + ArticleModel.COLUMN_URL, "a." + ArticleModel.COLUMN_TITLE + " as " + ArticleModel.COLUMN_TITLE, "a." + ArticleModel.COLUMN_DESCRIPTION + " as " + ArticleModel.COLUMN_DESCRIPTION, "a." + ArticleModel.COLUMN_IMAGE + " as " + ArticleModel.COLUMN_IMAGE, "a." + ArticleModel.COLUMN_AUTHOR + " as " + ArticleModel.COLUMN_AUTHOR, "a." + ArticleModel.COLUMN_SOURCE + " as " + ArticleModel.COLUMN_SOURCE, "a." + ArticleModel.COLUMN_DOMAIN + " as " + ArticleModel.COLUMN_DOMAIN, "a." + ArticleModel.COLUMN_DURATION + " as " + ArticleModel.COLUMN_DURATION, "a." + ArticleModel.COLUMN_INSERTED_AT + " as " + ArticleModel.COLUMN_INSERTED_AT, "a." + ArticleModel.COLUMN_IS_ARTICLE + " as " + ArticleModel.COLUMN_IS_ARTICLE, "a." + ArticleModel.COLUMN_SAVED + " as " + ArticleModel.COLUMN_SAVED, "c." + ContentModel.COLUMN_CONTENT + " as " + ContentModel.COLUMN_CONTENT, }, ArticleModel.COLUMN_URL + "=?", new String[] { url }, null, null, null); if (cursor != null && cursor.moveToFirst()) { Article article = new Article(cursor); cursor.close(); return article; } else { return null; } } }
DataSource { public Article getArticle(String url) { url = ArticleUtils.removeUrlParameters(url); Cursor cursor = database.query( ArticleModel.TABLE + " a left outer join " + ContentModel.TABLE + " c " + "on a." + ArticleModel.COLUMN_ID + " = c." + ContentModel.COLUMN_ARTICLE_ID, new String[] { "a." + ArticleModel.COLUMN_ID + " as " + ArticleModel.COLUMN_ID, "a." + ArticleModel.COLUMN_ALIAS + " as " + ArticleModel.COLUMN_ALIAS, "a." + ArticleModel.COLUMN_URL + " as " + ArticleModel.COLUMN_URL, "a." + ArticleModel.COLUMN_TITLE + " as " + ArticleModel.COLUMN_TITLE, "a." + ArticleModel.COLUMN_DESCRIPTION + " as " + ArticleModel.COLUMN_DESCRIPTION, "a." + ArticleModel.COLUMN_IMAGE + " as " + ArticleModel.COLUMN_IMAGE, "a." + ArticleModel.COLUMN_AUTHOR + " as " + ArticleModel.COLUMN_AUTHOR, "a." + ArticleModel.COLUMN_SOURCE + " as " + ArticleModel.COLUMN_SOURCE, "a." + ArticleModel.COLUMN_DOMAIN + " as " + ArticleModel.COLUMN_DOMAIN, "a." + ArticleModel.COLUMN_DURATION + " as " + ArticleModel.COLUMN_DURATION, "a." + ArticleModel.COLUMN_INSERTED_AT + " as " + ArticleModel.COLUMN_INSERTED_AT, "a." + ArticleModel.COLUMN_IS_ARTICLE + " as " + ArticleModel.COLUMN_IS_ARTICLE, "a." + ArticleModel.COLUMN_SAVED + " as " + ArticleModel.COLUMN_SAVED, "c." + ContentModel.COLUMN_CONTENT + " as " + ContentModel.COLUMN_CONTENT, }, ArticleModel.COLUMN_URL + "=?", new String[] { url }, null, null, null); if (cursor != null && cursor.moveToFirst()) { Article article = new Article(cursor); cursor.close(); return article; } else { return null; } } private  DataSource(Context context); @VisibleForTesting  DataSource(DatabaseSQLiteHelper helper); @VisibleForTesting  DataSource(SQLiteDatabase database); }
DataSource { public Article getArticle(String url) { url = ArticleUtils.removeUrlParameters(url); Cursor cursor = database.query( ArticleModel.TABLE + " a left outer join " + ContentModel.TABLE + " c " + "on a." + ArticleModel.COLUMN_ID + " = c." + ContentModel.COLUMN_ARTICLE_ID, new String[] { "a." + ArticleModel.COLUMN_ID + " as " + ArticleModel.COLUMN_ID, "a." + ArticleModel.COLUMN_ALIAS + " as " + ArticleModel.COLUMN_ALIAS, "a." + ArticleModel.COLUMN_URL + " as " + ArticleModel.COLUMN_URL, "a." + ArticleModel.COLUMN_TITLE + " as " + ArticleModel.COLUMN_TITLE, "a." + ArticleModel.COLUMN_DESCRIPTION + " as " + ArticleModel.COLUMN_DESCRIPTION, "a." + ArticleModel.COLUMN_IMAGE + " as " + ArticleModel.COLUMN_IMAGE, "a." + ArticleModel.COLUMN_AUTHOR + " as " + ArticleModel.COLUMN_AUTHOR, "a." + ArticleModel.COLUMN_SOURCE + " as " + ArticleModel.COLUMN_SOURCE, "a." + ArticleModel.COLUMN_DOMAIN + " as " + ArticleModel.COLUMN_DOMAIN, "a." + ArticleModel.COLUMN_DURATION + " as " + ArticleModel.COLUMN_DURATION, "a." + ArticleModel.COLUMN_INSERTED_AT + " as " + ArticleModel.COLUMN_INSERTED_AT, "a." + ArticleModel.COLUMN_IS_ARTICLE + " as " + ArticleModel.COLUMN_IS_ARTICLE, "a." + ArticleModel.COLUMN_SAVED + " as " + ArticleModel.COLUMN_SAVED, "c." + ContentModel.COLUMN_CONTENT + " as " + ContentModel.COLUMN_CONTENT, }, ArticleModel.COLUMN_URL + "=?", new String[] { url }, null, null, null); if (cursor != null && cursor.moveToFirst()) { Article article = new Article(cursor); cursor.close(); return article; } 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 Article getArticle(String url) { url = ArticleUtils.removeUrlParameters(url); Cursor cursor = database.query( ArticleModel.TABLE + " a left outer join " + ContentModel.TABLE + " c " + "on a." + ArticleModel.COLUMN_ID + " = c." + ContentModel.COLUMN_ARTICLE_ID, new String[] { "a." + ArticleModel.COLUMN_ID + " as " + ArticleModel.COLUMN_ID, "a." + ArticleModel.COLUMN_ALIAS + " as " + ArticleModel.COLUMN_ALIAS, "a." + ArticleModel.COLUMN_URL + " as " + ArticleModel.COLUMN_URL, "a." + ArticleModel.COLUMN_TITLE + " as " + ArticleModel.COLUMN_TITLE, "a." + ArticleModel.COLUMN_DESCRIPTION + " as " + ArticleModel.COLUMN_DESCRIPTION, "a." + ArticleModel.COLUMN_IMAGE + " as " + ArticleModel.COLUMN_IMAGE, "a." + ArticleModel.COLUMN_AUTHOR + " as " + ArticleModel.COLUMN_AUTHOR, "a." + ArticleModel.COLUMN_SOURCE + " as " + ArticleModel.COLUMN_SOURCE, "a." + ArticleModel.COLUMN_DOMAIN + " as " + ArticleModel.COLUMN_DOMAIN, "a." + ArticleModel.COLUMN_DURATION + " as " + ArticleModel.COLUMN_DURATION, "a." + ArticleModel.COLUMN_INSERTED_AT + " as " + ArticleModel.COLUMN_INSERTED_AT, "a." + ArticleModel.COLUMN_IS_ARTICLE + " as " + ArticleModel.COLUMN_IS_ARTICLE, "a." + ArticleModel.COLUMN_SAVED + " as " + ArticleModel.COLUMN_SAVED, "c." + ContentModel.COLUMN_CONTENT + " as " + ContentModel.COLUMN_CONTENT, }, ArticleModel.COLUMN_URL + "=?", new String[] { url }, null, null, null); if (cursor != null && cursor.moveToFirst()) { Article article = new Article(cursor); cursor.close(); return article; } 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);  }