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,22 +17,17 @@
|
||||
package com.android.settings.backup;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.backup.BackupManager;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -45,17 +40,15 @@ import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {BackupSettingsActivityPreferenceControllerTest.ShadowBackupManager.class})
|
||||
@Config(shadows = BackupSettingsActivityPreferenceControllerTest.ShadowBackupManager.class)
|
||||
public class BackupSettingsActivityPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_BACKUP_SETTINGS = "backup_settings";
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Preference mBackupPreference;
|
||||
|
||||
@@ -64,7 +57,7 @@ public class BackupSettingsActivityPreferenceControllerTest {
|
||||
private static boolean mBackupEnabled;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
@@ -73,7 +66,7 @@ public class BackupSettingsActivityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_backupOn() throws RemoteException {
|
||||
public void updateState_backupOn() {
|
||||
mBackupEnabled = true;
|
||||
|
||||
mController.updateState(mBackupPreference);
|
||||
@@ -82,7 +75,7 @@ public class BackupSettingsActivityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_backupOff() throws RemoteException {
|
||||
public void updateState_backupOff() {
|
||||
mBackupEnabled = false;
|
||||
|
||||
mController.updateState(mBackupPreference);
|
||||
|
@@ -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
|
||||
|
@@ -35,7 +35,6 @@ import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -49,8 +48,7 @@ import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {BackupSettingsHelperTest.ShadowBackupManagerStub.class})
|
||||
@Config(shadows = BackupSettingsHelperTest.ShadowBackupManagerStub.class)
|
||||
public class BackupSettingsHelperTest {
|
||||
|
||||
private static final String DEFAULT_SETTINGS_CLASSNAME =
|
||||
@@ -89,6 +87,8 @@ public class BackupSettingsHelperTest {
|
||||
|
||||
Intent backupIntent = mBackupSettingsHelper.getIntentForBackupSettingsFromTransport();
|
||||
|
||||
assertThat(backupIntent).isEqualTo(intent);
|
||||
|
||||
verify(mBackupManager).getDataManagementIntent(anyString());
|
||||
}
|
||||
|
||||
@@ -260,8 +260,8 @@ public class BackupSettingsHelperTest {
|
||||
|
||||
Intent backupIntent = mBackupSettingsHelper.getIntentForBackupSettings();
|
||||
|
||||
assertThat(backupIntent.getComponent().getClassName()).isEqualTo(
|
||||
DEFAULT_SETTINGS_CLASSNAME);
|
||||
assertThat(backupIntent.getComponent().getClassName())
|
||||
.isEqualTo(DEFAULT_SETTINGS_CLASSNAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,8 +16,17 @@
|
||||
|
||||
package com.android.settings.backup;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -29,28 +38,25 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {BackupSettingsPreferenceControllerTest.ShadowBackupSettingsHelper.class})
|
||||
@Config(shadows = BackupSettingsPreferenceControllerTest.ShadowBackupSettingsHelper.class)
|
||||
public class BackupSettingsPreferenceControllerTest {
|
||||
|
||||
private static final String BACKUP_SETTINGS = "backup_settings";
|
||||
private static final String MANUFACTURER_SETTINGS = "manufacturer_backup";
|
||||
|
||||
private Context mContext;
|
||||
private static final String sBackupLabel = "Test Backup Label";
|
||||
private static final String sBackupSummary = "Test Backup Summary";
|
||||
private static final String sManufacturerLabel = "Test Manufacturer Label";
|
||||
|
||||
@Mock
|
||||
private BackupSettingsHelper mBackupHelper;
|
||||
private static Intent sBackupIntent;
|
||||
|
||||
@Mock
|
||||
private static Intent sManufacturerIntent;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
@@ -58,22 +64,12 @@ public class BackupSettingsPreferenceControllerTest {
|
||||
@Mock
|
||||
private Preference mManufacturerPreference;
|
||||
|
||||
@Mock
|
||||
private static Intent mBackupIntent;
|
||||
|
||||
private static String mBackupLabel = "Test Backup Label";
|
||||
private static String mBackupSummary = "Test Backup Summary";
|
||||
private static String mManufacturerLabel = "Test Manufacturer Label";
|
||||
|
||||
@Mock
|
||||
private static Intent mManufacturerIntent;
|
||||
|
||||
private BackupSettingsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new BackupSettingsPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@@ -84,11 +80,11 @@ public class BackupSettingsPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mBackupPreference).setIntent(mBackupIntent);
|
||||
verify(mBackupPreference).setTitle(mBackupLabel);
|
||||
verify(mBackupPreference).setSummary(mBackupSummary);
|
||||
verify(mManufacturerPreference).setIntent(mManufacturerIntent);
|
||||
verify(mManufacturerPreference).setTitle(mManufacturerLabel);
|
||||
verify(mBackupPreference).setIntent(sBackupIntent);
|
||||
verify(mBackupPreference).setTitle(sBackupLabel);
|
||||
verify(mBackupPreference).setSummary(sBackupSummary);
|
||||
verify(mManufacturerPreference).setIntent(sManufacturerIntent);
|
||||
verify(mManufacturerPreference).setTitle(sManufacturerLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,27 +102,27 @@ public class BackupSettingsPreferenceControllerTest {
|
||||
|
||||
@Implementation
|
||||
public Intent getIntentForBackupSettings() {
|
||||
return mBackupIntent;
|
||||
return sBackupIntent;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String getLabelForBackupSettings() {
|
||||
return mBackupLabel;
|
||||
return sBackupLabel;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String getSummaryForBackupSettings() {
|
||||
return mBackupSummary;
|
||||
return sBackupSummary;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public Intent getIntentProvidedByManufacturer() {
|
||||
return mManufacturerIntent;
|
||||
return sManufacturerIntent;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String getLabelProvidedByManufacturer() {
|
||||
return mManufacturerLabel;
|
||||
return sManufacturerLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user