diff options
author | Akos Ludanyi <ludanyi@google.com> | 2014-09-04 14:08:49 +0200 |
---|---|---|
committer | Akos Ludanyi <ludanyi@google.com> | 2014-09-05 10:17:53 +0200 |
commit | 9189c4c2f05bc3f044f8a9c78339d0bfedb3dd8b (patch) | |
tree | 5740386ed30380e62f8672c49aba9d9cb624a338 /test-runner/src/android/test | |
parent | ae62d71d36022a7a62e00abc447c680f6d3ee83f (diff) | |
download | frameworks_base-9189c4c2f05bc3f044f8a9c78339d0bfedb3dd8b.zip frameworks_base-9189c4c2f05bc3f044f8a9c78339d0bfedb3dd8b.tar.gz frameworks_base-9189c4c2f05bc3f044f8a9c78339d0bfedb3dd8b.tar.bz2 |
Fix ProviderTestCase2 broken by ag/519661:
Problem:
1. ProviderTestCase2 passes a null as a ProviderInfo to the ContentProvider
2. mAuthority and mAuthorities will be null during the test
3. ContentProvider.matchesOurAuthorities will throw an NPE.
Fix:
Supply a ProviderInfo with authority.
Example bug:
b/17379295
Change-Id: Ia533313c0994727ef81f337a4e31a57ae7ec3c15
Diffstat (limited to 'test-runner/src/android/test')
-rw-r--r-- | test-runner/src/android/test/ProviderTestCase.java | 8 | ||||
-rw-r--r-- | test-runner/src/android/test/ProviderTestCase2.java | 22 |
2 files changed, 19 insertions, 11 deletions
diff --git a/test-runner/src/android/test/ProviderTestCase.java b/test-runner/src/android/test/ProviderTestCase.java index 1b323cf..4108f34 100644 --- a/test-runner/src/android/test/ProviderTestCase.java +++ b/test-runner/src/android/test/ProviderTestCase.java @@ -67,9 +67,8 @@ public abstract class ProviderTestCase<T extends ContentProvider> filenamePrefix); mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); - mProvider = mProviderClass.newInstance(); - mProvider.attachInfoForTesting(mProviderContext, null); - assertNotNull(mProvider); + mProvider = ProviderTestCase2.createProviderForTest( + mProviderContext, mProviderClass, mProviderAuthority); mResolver.addProvider(mProviderAuthority, getProvider()); } @@ -107,8 +106,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> resolver, targetContextWrapper); DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); - T provider = providerClass.newInstance(); - provider.attachInfoForTesting(context, null); + T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority); resolver.addProvider(authority, provider); return resolver; diff --git a/test-runner/src/android/test/ProviderTestCase2.java b/test-runner/src/android/test/ProviderTestCase2.java index dcd089d..1fa633e 100644 --- a/test-runner/src/android/test/ProviderTestCase2.java +++ b/test-runner/src/android/test/ProviderTestCase2.java @@ -19,6 +19,7 @@ package android.test; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.Context; +import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.test.mock.MockContext; import android.test.mock.MockContentResolver; @@ -138,14 +139,24 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro getContext(), // The context that file methods are delegated to filenamePrefix); mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); - - mProvider = mProviderClass.newInstance(); - mProvider.attachInfoForTesting(mProviderContext, null); - assertNotNull(mProvider); + mProvider = createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority); mResolver.addProvider(mProviderAuthority, getProvider()); } /** + * Creates and sets up a new instance of the provider. + */ + static <T extends ContentProvider> T createProviderForTest( + Context context, Class<T> providerClass, String authority) + throws IllegalAccessException, InstantiationException { + T instance = providerClass.newInstance(); + ProviderInfo providerInfo = new ProviderInfo(); + providerInfo.authority = authority; + instance.attachInfoForTesting(context, providerInfo); + return instance; + } + + /** * Tears down the environment for the test fixture. * <p> * Calls {@link android.content.ContentProvider#shutdown()} on the @@ -218,8 +229,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro Context context = new IsolatedContext(resolver, targetContextWrapper); DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); - T provider = providerClass.newInstance(); - provider.attachInfoForTesting(context, null); + T provider = createProviderForTest(context, providerClass, authority); resolver.addProvider(authority, provider); return resolver; |