Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27ff8cf1 authored by Nikhil Kumar's avatar Nikhil Kumar Committed by Aditya Singh
Browse files

Added context in the TestProvider constructor

Context object was null in the TestProvider which was causing NullPointerException in ContentProvider while calling context.getUserId.
Added test context in the TestProvider to get the content in actual calls in ContentProvider.

Test: atest DocumentsUIUnitTests
Bug: 322099078
Change-Id: I80adb72800e13e9521365e6a20ffe34f570b3675
Merged-In: I80adb72800e13e9521365e6a20ffe34f570b3675
(cherry picked from commit 790214ec)
parent 0bed390a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public final class TestContext {
     */
    static Context createStorageTestContext(Context context, String authority) {
        final MockContentResolver testResolver = new MockContentResolver();
        TestDocumentsProvider provider = new TestDocumentsProvider(authority);
        TestDocumentsProvider provider = new TestDocumentsProvider(context, authority);
        testResolver.addProvider(authority, provider);

        return new ContextWrapper(context) {
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui.testing;

import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.database.MatrixCursor;
@@ -51,10 +52,10 @@ public class TestDocumentsProvider extends DocumentsProvider {
    private Cursor mNextChildDocuments;
    private Cursor mNextRecentDocuments;

    public TestDocumentsProvider(String authority) {
    public TestDocumentsProvider(Context context, String authority) {
        ProviderInfo info = new ProviderInfo();
        info.authority = authority;
        attachInfoForTesting(null, info);
        attachInfoForTesting(context, info);
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -117,7 +117,8 @@ public class TestEnv {
    private void registerProviders() {
        for (RootInfo root : providers.getRootsBlocking()) {
            if (!mockProviders.containsKey(root.authority)) {
                TestDocumentsProvider provider = new TestDocumentsProvider(root.authority);
                Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
                TestDocumentsProvider provider = new TestDocumentsProvider(context, root.authority);
                contentResolver.addProvider(root.authority, provider);
                mockProviders.put(root.authority, provider);
            }