Use external/robolectric-shadows/run_robotests.mk
This allows Settings to test against the latest framework changes. Also replaced TestConfig with traditional robolectric.properties. Bug: 73173204 Bug: 73892008 Test: make -j56 RunSettingsRoboTests Change-Id: I3135b4fa5f095ba79b282a76f45dd9baa2584bc7
This commit is contained in:
@@ -17,12 +17,12 @@
|
||||
package com.android.settings.backup;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Application;
|
||||
@@ -34,7 +34,6 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -56,10 +55,8 @@ import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {BackupSettingsActivityTest.ShadowBackupSettingsHelper.class,
|
||||
@Config(shadows = {BackupSettingsActivityTest.ShadowBackupSettingsHelper.class,
|
||||
BackupSettingsActivityTest.ShadowUserHandle.class})
|
||||
public class BackupSettingsActivityTest {
|
||||
private ActivityController<BackupSettingsActivity> mActivityController;
|
||||
@@ -86,7 +83,12 @@ public class BackupSettingsActivityTest {
|
||||
mActivityController = Robolectric.buildActivity(BackupSettingsActivity.class);
|
||||
mActivity = mActivityController.get();
|
||||
mPackageManager = Shadows.shadowOf(mApplication.getPackageManager());
|
||||
doReturn(mComponent).when(mIntent).getComponent();
|
||||
when(mIntent.getComponent()).thenReturn(mComponent);
|
||||
}
|
||||
|
||||
@After
|
||||
public void resetShadows() {
|
||||
ShadowUserHandle.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,14 +96,15 @@ public class BackupSettingsActivityTest {
|
||||
mIsBackupProvidedByOEM = false;
|
||||
|
||||
// Testing the scenario when the activity is disabled
|
||||
mPackageManager.setComponentEnabledSetting(mComponent,
|
||||
mApplication.getPackageManager().setComponentEnabledSetting(mComponent,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
||||
|
||||
mActivityController.create();
|
||||
|
||||
// Verify that the component to launch was enabled.
|
||||
assertThat(mPackageManager.getComponentState(mComponent).newState)
|
||||
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
|
||||
final int flags = mPackageManager.getComponentEnabledSettingFlags(mComponent);
|
||||
assertThat(flags & PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
|
||||
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
|
||||
|
||||
// Verify that the intent returned by BackupSettingsHelper.getIntentForBackupSettings()
|
||||
// was launched.
|
||||
@@ -122,21 +125,14 @@ public class BackupSettingsActivityTest {
|
||||
|
||||
assertThat(shadowOf(mApplication).getNextStartedActivity()).isNull();
|
||||
verify(mFragmentTransaction).replace(anyInt(), isA(BackupSettingsFragment.class));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_SystemUser() {
|
||||
final List<SearchIndexableRaw> indexableRaws =
|
||||
BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||
mApplication.getApplicationContext(), true);
|
||||
final List<String> nonIndexableKeys =
|
||||
BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mApplication.getApplicationContext());
|
||||
|
||||
assertThat(indexableRaws).isNotNull();
|
||||
assertThat(indexableRaws).isNotEmpty();
|
||||
assertThat(nonIndexableKeys).isEmpty();
|
||||
assertThat(BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||
mApplication, true)).isNotEmpty();
|
||||
assertThat(BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mApplication)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,21 +141,16 @@ public class BackupSettingsActivityTest {
|
||||
|
||||
final List<SearchIndexableRaw> indexableRaws =
|
||||
BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||
mApplication.getApplicationContext(), true);
|
||||
mApplication, true);
|
||||
final List<String> nonIndexableKeys =
|
||||
BackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mApplication.getApplicationContext());
|
||||
mApplication);
|
||||
|
||||
assertThat(indexableRaws).isNotNull();
|
||||
assertThat(indexableRaws).isNotEmpty();
|
||||
assertThat(nonIndexableKeys).isNotEmpty();
|
||||
}
|
||||
|
||||
@After
|
||||
public void resetShadows() {
|
||||
ShadowUserHandle.reset();
|
||||
}
|
||||
|
||||
@Implements(BackupSettingsHelper.class)
|
||||
public static class ShadowBackupSettingsHelper {
|
||||
@Implementation
|
||||
|
||||
Reference in New Issue
Block a user