/* This test uses the database directly to insert and then uses the ContentProvider to read out the data. Uncomment this test to see if your location queries are performing correctly. */ public void testBasicLocationQueries() { // insert our test records into the database WeatherDatabaseHelper dbHelper = new WeatherDatabaseHelper(mContext); SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues testValues = TestUtilities.createNorthPoleLocationValues(); long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext); // Test the basic content provider query Cursor locationCursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null); // Make sure we get the correct cursor out of the database TestUtilities.validateCursor( "testBasicLocationQueries, location query", locationCursor, testValues); // Has the NotificationUri been set correctly? --- we can only test this easily against API // level 19 or greater because getNotificationUri was added in API level 19. if (Build.VERSION.SDK_INT >= 19) { assertEquals( "Error: Location Query did not properly set NotificationUri", locationCursor.getNotificationUri(), LocationEntry.CONTENT_URI); } }
/* This test uses the database directly to insert and then uses the ContentProvider to read out the data. Uncomment this test to see if the basic weather query functionality given in the ContentProvider is working correctly. */ public void testBasicWeatherQuery() { // insert our test records into the database WeatherDatabaseHelper dbHelper = new WeatherDatabaseHelper(mContext); SQLiteDatabase db = dbHelper.getWritableDatabase(); long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext); // Fantastic. Now that we have a location, add some weather! ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId); long weatherRowId = db.insert(WeatherEntry.TABLE_NAME, null, weatherValues); assertTrue("Unable to Insert WeatherEntry into the Database", weatherRowId != -1); db.close(); // Test the basic content provider query Cursor weatherCursor = mContext.getContentResolver().query(WeatherEntry.CONTENT_URI, null, null, null, null); // Make sure we get the correct cursor out of the database TestUtilities.validateCursor("testBasicWeatherQuery", weatherCursor, weatherValues); }