Fix NPE of AccessibilityShortcutPreferenceFragmentTest.

Add the mock FragmentActivity into to avoid NPE.

Bug: 218974847
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityShortcutPreferenceFragmentTest
Change-Id: Ia58484d9b09bd091513da04dff8659ce651acb8d
This commit is contained in:
Peter_Liang
2022-02-11 15:21:05 +08:00
parent e6bb6730aa
commit f7c1d39f27

View File

@@ -40,6 +40,7 @@ import android.widget.PopupWindow;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -53,6 +54,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers; import org.mockito.Answers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow; import org.robolectric.shadow.api.Shadow;
@@ -92,6 +94,7 @@ public class AccessibilityShortcutPreferenceFragmentTest {
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager); when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext); when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext); when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getActivity()).thenReturn(Robolectric.setupActivity(FragmentActivity.class));
mScreen = spy(new PreferenceScreen(mContext, null)); mScreen = spy(new PreferenceScreen(mContext, null));
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager); when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(mScreen).when(mFragment).getPreferenceScreen(); doReturn(mScreen).when(mFragment).getPreferenceScreen();