I am attempting to test the update() method of my custom content provider. I receive a null pointer exception due to the getContext() method call within the update() method being null. To alleviate this issue I have attempted implementing http://stackoverflow.com/questions/6516441/why-does-androidtestcase-getcontext-getapplicationcontext-return-null to no avail. My test class looks like the following:
public class AddressContentProviderTest extends ProviderTestCase2<AddressContentProvider> { public void testInsert() { Uri CONTENT_URI = Uri.parse("content://" + AddressContentProvider.AUTHORITY + "/address"); AddressContentProvider addressContentProvider = new AddressContentProvider(); ContentValues initialValues = new ContentValues(); boolean isException = false; Uri returnURI = null; initialValues.put("country", "USA"); initialValues.put("region", "test"); initialValues.put("city", "Jacksonville"); initialValues.put("state", "FL"); initialValues.put("zip", "32258"); initialValues.put("province", "test"); initialValues.put("geo_location_id", ""); returnURI = addressContentProvider.insert(CONTENT_URI, initialValues); assertTrue(returnURI != null); } The insert method looks like the following: @Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db =dbHelper.getWritableDatabase(); int count; switch (sUriMatcher.match(uri)) { case ADDRESS: count = db.update(ADDRESS_TABLE_NAME, values, where, whereArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en