@Test public void insertArticle() { source.insertArticle(new Article()); verify(database).insert(eq("article"), eq((String) null), any(ContentValues.class)); verify(database).insert(eq("content"), eq((String) null), any(ContentValues.class)); verifyNoMoreInteractions(database); }
public long insertArticle(Article article) { article.url = ArticleUtils.removeUrlParameters(article.url); ContentValues values = new ContentValues(11); values.put(ArticleModel.COLUMN_ALIAS, article.alias); values.put(ArticleModel.COLUMN_URL, article.url); values.put(ArticleModel.COLUMN_TITLE, article.title); values.put(ArticleModel.COLUMN_DESCRIPTION, article.description); values.put(ArticleModel.COLUMN_IMAGE, article.image); values.put(ArticleModel.COLUMN_AUTHOR, article.author); values.put(ArticleModel.COLUMN_SOURCE, article.source); values.put(ArticleModel.COLUMN_DOMAIN, article.domain); values.put(ArticleModel.COLUMN_DURATION, article.duration); values.put(ArticleModel.COLUMN_IS_ARTICLE, article.isArticle); values.put(ArticleModel.COLUMN_SAVED, article.saved); values.put(ArticleModel.COLUMN_SOURCE_ID, article.sourceId); if (article.insertedAt == 0) { values.put(ArticleModel.COLUMN_INSERTED_AT, System.currentTimeMillis()); } else { values.put(ArticleModel.COLUMN_INSERTED_AT, article.insertedAt); } long id = database.insert(ArticleModel.TABLE, null, values); values = new ContentValues(2); values.put(ContentModel.COLUMN_ARTICLE_ID, id); values.put(ContentModel.COLUMN_CONTENT, article.content); database.insert(ContentModel.TABLE, null, values); return id; }
DataSource { public long insertArticle(Article article) { article.url = ArticleUtils.removeUrlParameters(article.url); ContentValues values = new ContentValues(11); values.put(ArticleModel.COLUMN_ALIAS, article.alias); values.put(ArticleModel.COLUMN_URL, article.url); values.put(ArticleModel.COLUMN_TITLE, article.title); values.put(ArticleModel.COLUMN_DESCRIPTION, article.description); values.put(ArticleModel.COLUMN_IMAGE, article.image); values.put(ArticleModel.COLUMN_AUTHOR, article.author); values.put(ArticleModel.COLUMN_SOURCE, article.source); values.put(ArticleModel.COLUMN_DOMAIN, article.domain); values.put(ArticleModel.COLUMN_DURATION, article.duration); values.put(ArticleModel.COLUMN_IS_ARTICLE, article.isArticle); values.put(ArticleModel.COLUMN_SAVED, article.saved); values.put(ArticleModel.COLUMN_SOURCE_ID, article.sourceId); if (article.insertedAt == 0) { values.put(ArticleModel.COLUMN_INSERTED_AT, System.currentTimeMillis()); } else { values.put(ArticleModel.COLUMN_INSERTED_AT, article.insertedAt); } long id = database.insert(ArticleModel.TABLE, null, values); values = new ContentValues(2); values.put(ContentModel.COLUMN_ARTICLE_ID, id); values.put(ContentModel.COLUMN_CONTENT, article.content); database.insert(ContentModel.TABLE, null, values); return id; } }
DataSource { public long insertArticle(Article article) { article.url = ArticleUtils.removeUrlParameters(article.url); ContentValues values = new ContentValues(11); values.put(ArticleModel.COLUMN_ALIAS, article.alias); values.put(ArticleModel.COLUMN_URL, article.url); values.put(ArticleModel.COLUMN_TITLE, article.title); values.put(ArticleModel.COLUMN_DESCRIPTION, article.description); values.put(ArticleModel.COLUMN_IMAGE, article.image); values.put(ArticleModel.COLUMN_AUTHOR, article.author); values.put(ArticleModel.COLUMN_SOURCE, article.source); values.put(ArticleModel.COLUMN_DOMAIN, article.domain); values.put(ArticleModel.COLUMN_DURATION, article.duration); values.put(ArticleModel.COLUMN_IS_ARTICLE, article.isArticle); values.put(ArticleModel.COLUMN_SAVED, article.saved); values.put(ArticleModel.COLUMN_SOURCE_ID, article.sourceId); if (article.insertedAt == 0) { values.put(ArticleModel.COLUMN_INSERTED_AT, System.currentTimeMillis()); } else { values.put(ArticleModel.COLUMN_INSERTED_AT, article.insertedAt); } long id = database.insert(ArticleModel.TABLE, null, values); values = new ContentValues(2); values.put(ContentModel.COLUMN_ARTICLE_ID, id); values.put(ContentModel.COLUMN_CONTENT, article.content); database.insert(ContentModel.TABLE, null, values); return id; } private  DataSource(Context context); @VisibleForTesting  DataSource(DatabaseSQLiteHelper helper); @VisibleForTesting  DataSource(SQLiteDatabase database); }
DataSource { public long insertArticle(Article article) { article.url = ArticleUtils.removeUrlParameters(article.url); ContentValues values = new ContentValues(11); values.put(ArticleModel.COLUMN_ALIAS, article.alias); values.put(ArticleModel.COLUMN_URL, article.url); values.put(ArticleModel.COLUMN_TITLE, article.title); values.put(ArticleModel.COLUMN_DESCRIPTION, article.description); values.put(ArticleModel.COLUMN_IMAGE, article.image); values.put(ArticleModel.COLUMN_AUTHOR, article.author); values.put(ArticleModel.COLUMN_SOURCE, article.source); values.put(ArticleModel.COLUMN_DOMAIN, article.domain); values.put(ArticleModel.COLUMN_DURATION, article.duration); values.put(ArticleModel.COLUMN_IS_ARTICLE, article.isArticle); values.put(ArticleModel.COLUMN_SAVED, article.saved); values.put(ArticleModel.COLUMN_SOURCE_ID, article.sourceId); if (article.insertedAt == 0) { values.put(ArticleModel.COLUMN_INSERTED_AT, System.currentTimeMillis()); } else { values.put(ArticleModel.COLUMN_INSERTED_AT, article.insertedAt); } long id = database.insert(ArticleModel.TABLE, null, values); values = new ContentValues(2); values.put(ContentModel.COLUMN_ARTICLE_ID, id); values.put(ContentModel.COLUMN_CONTENT, article.content); database.insert(ContentModel.TABLE, null, values); return id; } 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 long insertArticle(Article article) { article.url = ArticleUtils.removeUrlParameters(article.url); ContentValues values = new ContentValues(11); values.put(ArticleModel.COLUMN_ALIAS, article.alias); values.put(ArticleModel.COLUMN_URL, article.url); values.put(ArticleModel.COLUMN_TITLE, article.title); values.put(ArticleModel.COLUMN_DESCRIPTION, article.description); values.put(ArticleModel.COLUMN_IMAGE, article.image); values.put(ArticleModel.COLUMN_AUTHOR, article.author); values.put(ArticleModel.COLUMN_SOURCE, article.source); values.put(ArticleModel.COLUMN_DOMAIN, article.domain); values.put(ArticleModel.COLUMN_DURATION, article.duration); values.put(ArticleModel.COLUMN_IS_ARTICLE, article.isArticle); values.put(ArticleModel.COLUMN_SAVED, article.saved); values.put(ArticleModel.COLUMN_SOURCE_ID, article.sourceId); if (article.insertedAt == 0) { values.put(ArticleModel.COLUMN_INSERTED_AT, System.currentTimeMillis()); } else { values.put(ArticleModel.COLUMN_INSERTED_AT, article.insertedAt); } long id = database.insert(ArticleModel.TABLE, null, values); values = new ContentValues(2); values.put(ContentModel.COLUMN_ARTICLE_ID, id); values.put(ContentModel.COLUMN_CONTENT, article.content); database.insert(ContentModel.TABLE, null, values); return id; } 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);  }