Fix crash when switching to fragment with null name.
Check for null fragment name before trying to launch the fragment. Change-Id: Ibee6f7a1f27f7bc7d556a600c7e43fd30c2f1d6c Fix: 35203478 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -16,18 +16,47 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SettingsActivityTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
private SettingsActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
final FakeFeatureFactory factory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryTextChange_shouldUpdate() {
|
||||
final String testQuery = "abc";
|
||||
@@ -42,4 +71,16 @@ public class SettingsActivityTest {
|
||||
|
||||
assertThat(mActivity.mSearchQuery).isEqualTo(testQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
|
||||
throws ClassNotFoundException {
|
||||
mActivity = spy(new SettingsActivity());
|
||||
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
|
||||
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
|
||||
|
||||
doReturn(RuntimeEnvironment.application.getClassLoader()).when(mActivity).getClassLoader();
|
||||
|
||||
mActivity.launchSettingFragment(null, true, mock(Intent.class));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user