コード例 #1
0
  public void testGetType() {

    String type = mContext.getContentResolver().getType(AlexandriaContract.BookEntry.CONTENT_URI);
    assertEquals(AlexandriaContract.BookEntry.CONTENT_TYPE, type);

    type = mContext.getContentResolver().getType(AlexandriaContract.AuthorEntry.CONTENT_URI);
    assertEquals(AlexandriaContract.AuthorEntry.CONTENT_TYPE, type);

    type = mContext.getContentResolver().getType(AlexandriaContract.CategoryEntry.CONTENT_URI);
    assertEquals(AlexandriaContract.CategoryEntry.CONTENT_TYPE, type);

    long id = 9780137903955L;
    type = mContext.getContentResolver().getType(AlexandriaContract.BookEntry.buildBookUri(id));
    assertEquals(AlexandriaContract.BookEntry.CONTENT_ITEM_TYPE, type);

    type = mContext.getContentResolver().getType(AlexandriaContract.BookEntry.buildFullBookUri(id));
    assertEquals(AlexandriaContract.BookEntry.CONTENT_ITEM_TYPE, type);

    type = mContext.getContentResolver().getType(AlexandriaContract.AuthorEntry.buildAuthorUri(id));
    assertEquals(AlexandriaContract.AuthorEntry.CONTENT_ITEM_TYPE, type);

    type =
        mContext
            .getContentResolver()
            .getType(AlexandriaContract.CategoryEntry.buildCategoryUri(id));
    assertEquals(AlexandriaContract.CategoryEntry.CONTENT_ITEM_TYPE, type);
  }
コード例 #2
0
  private void insertReadCategory() {
    ContentValues categoryValues = com.ogasimli.alexandria.TestDb.getCategoryValues();

    Uri categoryUri =
        mContext
            .getContentResolver()
            .insert(AlexandriaContract.CategoryEntry.CONTENT_URI, categoryValues);
    long categoryRowId = ContentUris.parseId(categoryUri);
    assertTrue(categoryRowId != -1);
    assertEquals(categoryRowId, com.ogasimli.alexandria.TestDb.ean);

    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                AlexandriaContract.CategoryEntry.CONTENT_URI,
                null, // projection
                null, // selection
                null, // selection args
                null // sort order
                );

    com.ogasimli.alexandria.TestDb.validateCursor(cursor, categoryValues);

    cursor =
        mContext
            .getContentResolver()
            .query(
                AlexandriaContract.CategoryEntry.buildCategoryUri(categoryRowId),
                null, // projection
                null, // selection
                null, // selection args
                null // sort order
                );

    com.ogasimli.alexandria.TestDb.validateCursor(cursor, categoryValues);
  }