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:
James Lemieux
2018-02-26 00:51:42 -08:00
parent 229a6a2bc4
commit 22a39c2b93
752 changed files with 5096 additions and 9182 deletions

View File

@@ -5,7 +5,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -14,10 +13,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppLocationPermissionPreferenceControllerTest {
private AppLocationPermissionPreferenceController mController;
@@ -35,8 +32,7 @@ public class AppLocationPermissionPreferenceControllerTest {
@Test
public void isAvailable_noLocationLinkPermission_shouldReturnFalse() {
Settings.System.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
0);
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 0);
assertThat(mController.isAvailable()).isFalse();
}
@@ -44,8 +40,7 @@ public class AppLocationPermissionPreferenceControllerTest {
@Test
public void displayPreference_hasLocationLinkPermission_shouldReturnTrue() {
Settings.System.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
1);
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1);
assertThat(mController.isAvailable()).isTrue();
}

View File

@@ -16,15 +16,14 @@
package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.ContentResolver;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.support.v14.preference.SwitchPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -33,30 +32,27 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothScanningPreferenceControllerTest {
@Mock
private SwitchPreference mPreference;
private Context mContext;
private ContentResolver mContentResolver;
private BluetoothScanningPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new BluetoothScanningPreferenceController(mContext);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
mController = new BluetoothScanningPreferenceController(RuntimeEnvironment.application);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void updateState_bluetoothScanningEnabled_shouldCheckedPreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(mContentResolver, Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
mController.updateState(mPreference);
@@ -65,8 +61,7 @@ public class BluetoothScanningPreferenceControllerTest {
@Test
public void updateState_bluetoothScanningDisabled_shouldUncheckedPreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
Settings.Global.putInt(mContentResolver, Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(mPreference);
@@ -79,9 +74,8 @@ public class BluetoothScanningPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0)).isEqualTo(1);
final int btScanning = Global.getInt(mContentResolver, Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
assertThat(btScanning).isEqualTo(1);
}
@Test
@@ -90,8 +84,7 @@ public class BluetoothScanningPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1)).isEqualTo(0);
final int btScanning = Global.getInt(mContentResolver, Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
assertThat(btScanning).isEqualTo(0);
}
}

View File

@@ -39,13 +39,12 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wrapper.LocationManagerWrapper;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,12 +56,13 @@ import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
ShadowSecureSettings.class,
LocationEnablerTest.ShadowLocationManagerWrapper.class})
@Config(shadows = {
ShadowSecureSettings.class,
LocationEnablerTest.ShadowLocationManagerWrapper.class})
public class LocationEnablerTest {
@Mock
@@ -90,7 +90,7 @@ public class LocationEnablerTest {
mEnabler.onResume();
verify(mContext).registerReceiver(eq(mEnabler.mReceiver),
eq(mEnabler.INTENT_FILTER_LOCATION_MODE_CHANGED));
eq(LocationEnabler.INTENT_FILTER_LOCATION_MODE_CHANGED));
}
@Test
@@ -150,8 +150,7 @@ public class LocationEnablerTest {
mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
verify(mListener)
.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, true);
verify(mListener).onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, true);
}
@Test

View File

@@ -39,11 +39,10 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,11 +50,11 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
/** Unit tests for {@link LocationFooterPreferenceController} */
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationFooterPreferenceControllerTest {
@Mock

View File

@@ -16,7 +16,6 @@
package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -34,7 +33,6 @@ import android.provider.Settings;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -46,14 +44,12 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationForWorkPreferenceControllerTest {
@Mock
@@ -95,8 +91,8 @@ public class LocationForWorkPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
verify(mUserManager).setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, false,
mUserHandle);
verify(mUserManager)
.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, false, mUserHandle);
verify(mPreference).setSummary(R.string.switch_on_text);
}
@@ -107,14 +103,14 @@ public class LocationForWorkPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
verify(mUserManager).setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true,
mUserHandle);
verify(mUserManager)
.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, mUserHandle);
verify(mPreference).setSummary(R.string.switch_off_text);
}
@Test
public void isAvailable_noManagedProfile_shouldReturnFalse() {
when(mUserManager.getUserProfiles()).thenReturn(new ArrayList<UserHandle>());
when(mUserManager.getUserProfiles()).thenReturn(new ArrayList<>());
assertThat(mController.isAvailable()).isFalse();
}
@@ -194,5 +190,4 @@ public class LocationForWorkPreferenceControllerTest {
when(mUserManager.getUserInfo(5))
.thenReturn(new UserInfo(5, "user 5", UserInfo.FLAG_MANAGED_PROFILE));
}
}

View File

@@ -17,9 +17,7 @@ package com.android.settings.location;
import static android.arch.lifecycle.Lifecycle.Event.ON_PAUSE;
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
@@ -38,7 +36,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.search.InlineListPayload;
import com.android.settings.search.InlinePayload;
import com.android.settings.search.ResultPayload;
@@ -56,7 +53,6 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationPreferenceControllerTest {
@Mock
private Preference mPreference;
@@ -101,38 +97,38 @@ public class LocationPreferenceControllerTest {
@Test
public void getLocationSummary_locationOff_shouldSetSummaryOff() {
Secure.putInt(mContext.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
final ContentResolver contentResolver = mContext.getContentResolver();
Secure.putInt(contentResolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
assertThat(mController.getLocationSummary(mContext)).isEqualTo(
mContext.getString(R.string.location_off_summary));
final String locationSummary = mController.getLocationSummary(mContext);
assertThat(locationSummary).isEqualTo(mContext.getString(R.string.location_off_summary));
}
@Test
public void getLocationSummary_sensorsOnly_shouldSetSummaryOn() {
Secure.putInt(mContext.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_SENSORS_ONLY);
final ContentResolver contentResolver = mContext.getContentResolver();
Secure.putInt(contentResolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_SENSORS_ONLY);
assertThat(mController.getLocationSummary(mContext)).isEqualTo(
mContext.getString(R.string.location_on_summary));
final String locationSummary = mController.getLocationSummary(mContext);
assertThat(locationSummary).isEqualTo(mContext.getString(R.string.location_on_summary));
}
@Test
public void getLocationSummary_highAccuracy_shouldSetSummaryOn() {
Secure.putInt(mContext.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_HIGH_ACCURACY);
final ContentResolver contentResolver = mContext.getContentResolver();
Secure.putInt(contentResolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_HIGH_ACCURACY);
assertThat(mController.getLocationSummary(mContext)).isEqualTo(
mContext.getString(R.string.location_on_summary));
final String locationSummary = mController.getLocationSummary(mContext);
assertThat(locationSummary).isEqualTo(mContext.getString(R.string.location_on_summary));
}
@Test
public void getLocationSummary_batterySaving_shouldSetSummaryOn() {
Secure.putInt(mContext.getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_BATTERY_SAVING);
final ContentResolver contentResolver = mContext.getContentResolver();
Secure.putInt(contentResolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_BATTERY_SAVING);
assertThat(mController.getLocationSummary(mContext)).isEqualTo(
mContext.getString(R.string.location_on_summary));
final String locationSummary = mController.getLocationSummary(mContext);
assertThat(locationSummary).isEqualTo(mContext.getString(R.string.location_on_summary));
}
@Test
@@ -153,9 +149,8 @@ public class LocationPreferenceControllerTest {
mController.displayPreference(mScreen);
mController.onResume();
mController.mLocationProvidersChangedReceiver.onReceive(
mContext,
new Intent().setAction(LocationManager.PROVIDERS_CHANGED_ACTION));
mController.mLocationProvidersChangedReceiver
.onReceive(mContext, new Intent(LocationManager.PROVIDERS_CHANGED_ACTION));
verify(mPreference).setSummary(any());
}
@@ -171,13 +166,13 @@ public class LocationPreferenceControllerTest {
@Test
@Config(shadows = ShadowSecureSettings.class)
public void testSetValue_updatesCorrectly() {
int newValue = Secure.LOCATION_MODE_BATTERY_SAVING;
final int newValue = Secure.LOCATION_MODE_BATTERY_SAVING;
ContentResolver resolver = mContext.getContentResolver();
Settings.Secure.putInt(resolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
int updatedValue = Settings.Secure.getInt(resolver, Secure.LOCATION_MODE,
Secure.LOCATION_MODE_OFF);
final int updatedValue =
Settings.Secure.getInt(resolver, Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
assertThat(updatedValue).isEqualTo(newValue);
}

View File

@@ -18,33 +18,22 @@ package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationScanningPreferenceControllerTest {
private Context mContext;
private LocationScanningPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new LocationScanningPreferenceController(mContext);
mController = new LocationScanningPreferenceController(RuntimeEnvironment.application);
}
@Test

View File

@@ -16,7 +16,6 @@
package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -32,7 +31,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -43,13 +41,11 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationServicePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -118,8 +114,8 @@ public class LocationServicePreferenceControllerTest {
pref2.setTitle("Title2");
preferences.add(pref1);
preferences.add(pref2);
doReturn(preferences).when(mSettingsInjector)
.getInjectedSettings(any(Context.class), anyInt());
doReturn(preferences)
.when(mSettingsInjector).getInjectedSettings(any(Context.class), anyInt());
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
mController.displayPreference(mScreen);

View File

@@ -15,24 +15,24 @@
*/
package com.android.settings.location;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.os.Bundle;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.SwitchBar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationSettingsTest {
@Mock
@@ -47,7 +47,7 @@ public class LocationSettingsTest {
MockitoAnnotations.initMocks(this);
mLocationSettings = spy(new LocationSettings());
doReturn(mActivity).when(mLocationSettings).getActivity();
doReturn(mSwitchBar).when(mActivity).getSwitchBar();
when(mActivity.getSwitchBar()).thenReturn(mSwitchBar);
}
@Test

View File

@@ -26,7 +26,6 @@ import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
@@ -39,11 +38,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationSwitchBarControllerTest {
@Mock
@@ -65,8 +62,7 @@ public class LocationSwitchBarControllerTest {
ReflectionHelpers.setField(mSwitchBar, "mSwitch", mSwitch);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new LocationSwitchBarController(
mContext, mSwitchBar, mLifecycle));
mController = spy(new LocationSwitchBarController(mContext, mSwitchBar, mLifecycle));
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
}
@@ -153,5 +149,4 @@ public class LocationSwitchBarControllerTest {
verify(mSwitch).setChecked(false);
}
}

View File

@@ -36,7 +36,6 @@ import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.AppPreference;
@@ -55,10 +54,8 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RecentLocationRequestPreferenceControllerTest {
@Mock
@@ -118,8 +115,8 @@ public class RecentLocationRequestPreferenceControllerTest {
mController.updateState(mCategory);
verify(mCategory).removeAll();
verify(mCategory).addPreference(
argThat(titleMatches(mContext.getString(R.string.location_no_recent_apps))));
final String title = mContext.getString(R.string.location_no_recent_apps);
verify(mCategory).addPreference(argThat(titleMatches(title)));
}
@Test
@@ -207,7 +204,7 @@ public class RecentLocationRequestPreferenceControllerTest {
AppPreference appPreference = mock(AppPreference.class, "AppPreference" + i);
doReturn(title).when(appPreference).getTitle();
doReturn(appPreference)
.when(mController).createAppPreference(any(Context.class), eq(req));
.when(mController).createAppPreference(any(Context.class), eq(req));
}
return requests;
}

View File

@@ -29,26 +29,25 @@ import android.content.Context;
import android.provider.Settings.Secure;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.AppPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.location.RecentLocationApps.Request;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.Collections;
/** Unit tests for {@link RecentLocationRequestSeeAllPreferenceController} */
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RecentLocationRequestSeeAllPreferenceControllerTest {
@Mock
@@ -115,7 +114,7 @@ public class RecentLocationRequestSeeAllPreferenceControllerTest {
doReturn(appPreference)
.when(mController).createAppPreference(any(Context.class), eq(request));
when(mRecentLocationApps.getAppListSorted())
.thenReturn(new ArrayList<>(Arrays.asList(request)));
.thenReturn(new ArrayList<>(Collections.singletonList(request)));
mController.displayPreference(mScreen);
mController.updateState(mCategory);

View File

@@ -22,33 +22,28 @@ import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ScanningSettingsTest {
private Context mContext;
private ScanningSettings mSettings;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSettings = new ScanningSettings();
}
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = mSettings.SEARCH_INDEX_DATA_PROVIDER
final List<SearchIndexableResource> sir = ScanningSettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true /* enabled */);
assertThat(sir).hasSize(1);

View File

@@ -16,15 +16,14 @@
package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.ContentResolver;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.support.v14.preference.SwitchPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -33,30 +32,27 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WifiScanningPreferenceControllerTest {
@Mock
private SwitchPreference mPreference;
private Context mContext;
private ContentResolver mContentResolver;
private WifiScanningPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new WifiScanningPreferenceController(mContext);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
mController = new WifiScanningPreferenceController(RuntimeEnvironment.application);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void updateState_wifiScanningEnabled_shouldCheckedPreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
mController.updateState(mPreference);
@@ -65,8 +61,7 @@ public class WifiScanningPreferenceControllerTest {
@Test
public void updateState_wifiScanningDisabled_shouldUncheckedPreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(mPreference);
@@ -79,9 +74,9 @@ public class WifiScanningPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0)).isEqualTo(1);
final int scanAlways =
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
assertThat(scanAlways).isEqualTo(1);
}
@Test
@@ -90,8 +85,8 @@ public class WifiScanningPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1)).isEqualTo(0);
final int scanAlways =
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
assertThat(scanAlways).isEqualTo(0);
}
}