/**
   * <em>Note:</em> This test <i>does not</i> check {@code insert} function of {@code
   * ContentProvider}. The test only asserts that all columns were created with correct data type.
   * So, in this test, we use pure {@code insert} function of {@code SQLiteDatabase}
   */
  @Test
  public void checkInsertIntoArticlesTable() {
    ContentValues testValues = TestUtilities.createArticleValues();

    long rowId = db.insert(ArticleDatabase.Tables.ARTICLES, null, testValues);

    assertTrue(rowId != -1);

    cursor =
        db.query(
            ArticleDatabase.Tables.ARTICLES,
            null, // column
            null, // selections
            null, // selection args
            null, // groupBy
            null, // having
            null); // orderBy

    assertTrue("Error: No records returned from Articles table", cursor.moveToFirst());
    TestUtilities.validateCurrentRecord(
        "Error: Article query validation failed", cursor, testValues);

    assertFalse("Error: More than one record return from Articles query", cursor.moveToNext());
  }
  /**
   * Tests articles_videos_delete trigger should be created and work correctly Explains about
   * articles_videos_delete: When we delete an article, articles_videos_delete trigger also delete
   * related videos.
   */
  @Test
  public void articlesVideosDeleteTrigger_shouldBeCreated() {
    ContentValues articleValues = TestUtilities.createArticleValues();
    ContentValues videoValues = TestUtilities.createVideoValue();

    int articleId = articleValues.getAsInteger(ArticleContract.Articles.ARTICLE_ID);
    int videoId = videoValues.getAsInteger(ArticleContract.Videos.VIDEO_ID);

    // Insert an articles and a related video into db
    long rowId = db.insert(ArticleDatabase.Tables.ARTICLES, null, articleValues);
    assertThat("Unable to Insert an article into the DB", rowId != -1);
    rowId = db.insert(ArticleDatabase.Tables.VIDEOS, null, videoValues);
    assertThat("Unable to Insert a video into the DB", rowId != -1);

    // Query an article to assert that it was already inserted in DB
    cursor =
        db.query(
            ArticleDatabase.Tables.ARTICLES,
            null,
            ArticleContract.Articles.ARTICLE_ID + "=?",
            new String[] {String.valueOf(articleId)},
            null,
            null,
            null);
    TestUtilities.validateCursor(null, cursor, articleValues);

    // Query a video to assert that it was already inserted in DB
    cursor =
        db.query(
            ArticleDatabase.Tables.VIDEOS,
            null,
            ArticleContract.Videos.VIDEO_ID + "=?",
            new String[] {String.valueOf(videoId)},
            null,
            null,
            null);
    TestUtilities.validateCursor(null, cursor, videoValues);

    // Finally, delete the article to check that the video also deletes in behind
    int count =
        db.delete(
            ArticleDatabase.Tables.ARTICLES,
            ArticleContract.Articles.ARTICLE_ID + "=?",
            new String[] {String.valueOf(articleId)});
    assertThat(count, is(1));

    cursor =
        db.query(
            ArticleDatabase.Tables.ARTICLES,
            null,
            ArticleContract.Articles.ARTICLE_ID + "=?",
            new String[] {String.valueOf(articleId)},
            null,
            null,
            null);
    assertThat("Error: Delete an article unsuccessful", !cursor.moveToFirst());

    cursor =
        db.query(
            ArticleDatabase.Tables.VIDEOS,
            null,
            ArticleContract.Videos.VIDEO_ID + "=?",
            new String[] {String.valueOf(videoId)},
            null,
            null,
            null);
    assertThat("Error: articles_videos_delete trigger didn't work.", !cursor.moveToFirst());
  }