在glkinsert 10值之后,光标仅返回1行

时间:2017-11-15 09:29:45

标签: android sqlite android-contentprovider

我创建了ContentProvider类,并且在测试时遇到了一些麻烦。

这是测试代码: public void testBulkInsert(){

    ContentValues[] bulkInsertContentValues = createBulkInsertVenueValues(VENUE_ID);

    // Register a content observer for our bulk insert.
    TestUtilities.TestContentObserver venueObserver = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(FoursquareContract.VenuesEntry.CONTENT_URI, true, venueObserver);

    int insertCount = mContext.getContentResolver().bulkInsert(FoursquareContract.VenuesEntry.CONTENT_URI, bulkInsertContentValues);

    venueObserver.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(venueObserver);

    assertEquals(insertCount, BULK_INSERT_RECORDS_TO_INSERT);

    // A cursor is your primary interface to the query results.
    Cursor cursor = mContext.getContentResolver().query(
            FoursquareContract.VenuesEntry.CONTENT_URI,
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null  // sort order == by DATE ASCENDING
    );

    // we should have as many records in the database as we've inserted
    assertEquals(cursor.getCount(), BULK_INSERT_RECORDS_TO_INSERT);

    // and let's make sure they match the ones we created
    cursor.moveToFirst();
    for ( int i = 0; i < BULK_INSERT_RECORDS_TO_INSERT; i++, cursor.moveToNext() ) {
        TestUtilities.validateCurrentRecord("testBulkInsert.  Error validating VenuesEntry " + i,
                cursor, bulkInsertContentValues[i]);
    }
    cursor.close();
}

(与预期失败:&lt; 1&gt;但是:&lt; 10&gt; 在junit.framework.Assert.fail(Assert.java:50))

指向内容提供商的链接:https://github.com/melle095/OneSquare/blob/starting/app/src/main/java/com/a_leonov/onesquare/data/VenueProvider.java

我找不到什么错误。你有什么想法吗?

0 个答案:

没有答案