/**
   * <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 checkInsertIntoReferenceArticlesTable() {
    ContentValues testValue = TestUtilities.createReferenceArticleValues();

    long rowId = db.insert(ArticleDatabase.Tables.REFERENCE_ARTICLES, null, testValue);

    assertTrue(rowId != -1);

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

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

    assertFalse(
        "Error: More than one record return from Reference_Articles query", cursor.moveToNext());
  }
  /**
   * Tests reference_articles_delete trigger should be created and work correctly Explains about
   * reference_articles_delete: When we delete a linked_article, reference_articles_delete trigger
   * will check if related reference_article doesn't link to any other linked_articles. It will
   * deletes that reference_article.
   */
  @Test
  public void referenceArticlesDeleteTrigger_shouldBeCreated() {
    ContentValues referenceArticlesValues = TestUtilities.createReferenceArticleValues();
    ContentValues linkedArticleValues = TestUtilities.createLinkedArticleValue();

    int referenceArticleId =
        referenceArticlesValues.getAsInteger(ArticleContract.ReferenceArticles.ARTICLE_ID);
    int referenceId = linkedArticleValues.getAsInteger(ArticleDatabase.LinkedArticles.REFERENCE_ID);

    // Insert a reference_article and a related linked_article into db
    long rowId =
        db.insert(ArticleDatabase.Tables.REFERENCE_ARTICLES, null, referenceArticlesValues);
    assertThat("Unable to Insert a reference_article into the DB", rowId != -1);
    rowId = db.insert(ArticleDatabase.Tables.LINKED_ARTICLES, null, linkedArticleValues);
    assertThat("Unable to Insert a linked_article into the DB", rowId != -1);

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

    // Query a linked_article to assert that it was already inserted in DB
    cursor =
        db.query(
            ArticleDatabase.Tables.LINKED_ARTICLES,
            null,
            ArticleDatabase.LinkedArticles.REFERENCE_ID + "=?",
            new String[] {String.valueOf(referenceId)},
            null,
            null,
            null);
    TestUtilities.validateCursor(null, cursor, linkedArticleValues);

    // Finally, delete the linked_article to check that the reference_article also deletes in behind
    int count =
        db.delete(
            ArticleDatabase.Tables.LINKED_ARTICLES,
            ArticleDatabase.LinkedArticles.REFERENCE_ID + "=?",
            new String[] {String.valueOf(referenceId)});
    assertThat(count, is(1));

    cursor =
        db.query(
            ArticleDatabase.Tables.LINKED_ARTICLES,
            null,
            ArticleDatabase.LinkedArticles.REFERENCE_ID + "=?",
            new String[] {String.valueOf(referenceId)},
            null,
            null,
            null);
    assertThat("Error: Delete an article unsuccessful", !cursor.moveToFirst());

    cursor =
        db.query(
            ArticleDatabase.Tables.REFERENCE_ARTICLES,
            null,
            ArticleContract.ReferenceArticles.ARTICLE_ID + "=?",
            new String[] {String.valueOf(referenceArticleId)},
            null,
            null,
            null);
    assertThat("Error: reference_article_delete trigger didn't work.", !cursor.moveToFirst());
  }