Update testcases which failed due to the SupportLibrary changed

Fragment.oncreate() causes an IllegalStateException. We use a
ShadowFragment to stop the calling sequence.

Fixes: 135086559
Test: robotest
Change-Id: I601e0f2513f826b0b7749cb2c013b7e4c0a94a33
This commit is contained in:
Sunny Shao
2019-06-13 17:06:31 +08:00
committed by Raff Tsai
parent f1c0f23510
commit 5da24591ea
14 changed files with 87 additions and 27 deletions

View File

@@ -37,6 +37,7 @@ import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.WorkOnlyCategory;
import org.junit.Before;
@@ -46,6 +47,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@@ -147,6 +149,7 @@ public class SettingsPreferenceFragmentTest {
}
@Test
@Config(shadows = ShadowFragment.class)
public void onCreate_hasExtraFragmentKey_shouldExpandPreferences() {
doReturn(mContext.getTheme()).when(mActivity).getTheme();
doReturn(mContext.getResources()).when(mFragment).getResources();
@@ -161,6 +164,7 @@ public class SettingsPreferenceFragmentTest {
}
@Test
@Config(shadows = ShadowFragment.class)
public void onCreate_noPreferenceScreen_shouldNotCrash() {
doReturn(mContext.getTheme()).when(mActivity).getTheme();
doReturn(mContext.getResources()).when(mFragment).getResources();