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

Commit 1d9ee7ae authored by felkachang's avatar felkachang Committed by Felka Chang
Browse files

Fix the flaky test that use wrong context

ClipStorageTest use wrong context and should use target context.

Fixes: 123555031
Test: atest DocumentsUITest:com.android.documentsui.clipping

Change-Id: I5095edd3c88eeef3e2d563903b2812776b971166
parent 9e14c9f5
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.annotation.MainThread;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.documentsui.testing.TestScheduledExecutorService;
@@ -46,6 +47,7 @@ import java.util.List;

@RunWith(AndroidJUnit4.class)
@SmallTest
@MainThread
public class ClipStorageTest {
    private static final String PREF_NAME = "pref";
    private static final List<Uri> TEST_URIS = createList(
@@ -63,7 +65,8 @@ public class ClipStorageTest {

    @Before
    public void setUp() {
        mPref = InstrumentationRegistry.getContext().getSharedPreferences(PREF_NAME, 0);
        mPref = InstrumentationRegistry.getInstrumentation().getTargetContext()
                .getSharedPreferences(PREF_NAME, 0);
        File clipDir = ClipStorage.prepareStorage(folder.getRoot());
        mStorage = new ClipStorage(clipDir, mPref);

+3 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.provider.DocumentsContract;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.documentsui.base.Shared;
@@ -63,7 +63,8 @@ public class UrisSupplierTest {
        mExecutor = new TestScheduledExecutorService();
        AsyncTask.setDefaultExecutor(mExecutor);

        mPref = InstrumentationRegistry.getContext().getSharedPreferences(PREF_NAME, 0);
        mPref = InstrumentationRegistry.getInstrumentation().getTargetContext()
                .getSharedPreferences(PREF_NAME, 0);
        mStorage = new ClipStorage(folder.getRoot(), mPref);
    }