Convert SettingsLib Lifecycle to Flatfoot
Bug: 69257739 Test: m -j RunSettingsRoboTests Change-Id: I27e7850c39afb9c09297007e8cc352f410665653
This commit is contained in:
@@ -66,13 +66,15 @@ public class LocationEnablerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationEnabler mEnabler;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mEnabler = spy(new LocationEnabler(mContext, mListener, new Lifecycle()));
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mEnabler = spy(new LocationEnabler(mContext, mListener, mLifecycle));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -68,13 +68,15 @@ public class LocationForWorkPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationForWorkPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = spy(new LocationForWorkPreferenceController(mContext, new Lifecycle()));
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = spy(new LocationForWorkPreferenceController(mContext, mLifecycle));
|
||||
mockManagedProfile();
|
||||
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -34,11 +35,17 @@ import org.robolectric.annotation.Config;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class LocationModeBatterySavingPreferenceControllerTest {
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLocationMode_shouldReturnModeBatterySaving() {
|
||||
final LocationModeBatterySavingPreferenceController controller =
|
||||
new LocationModeBatterySavingPreferenceController(mock(Context.class),
|
||||
new Lifecycle());
|
||||
new LocationModeBatterySavingPreferenceController(mock(Context.class), mLifecycle);
|
||||
|
||||
assertThat(controller.getLocationMode())
|
||||
.isEqualTo(Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -34,11 +35,17 @@ import org.robolectric.annotation.Config;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class LocationModeHighAccuracyPreferenceControllerTest {
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLocationMode_shouldReturnModeHighAccuracy() {
|
||||
final LocationModeHighAccuracyPreferenceController controller =
|
||||
new LocationModeHighAccuracyPreferenceController(mock(Context.class),
|
||||
new Lifecycle());
|
||||
new LocationModeHighAccuracyPreferenceController(mock(Context.class), mLifecycle);
|
||||
|
||||
assertThat(controller.getLocationMode())
|
||||
.isEqualTo(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
|
||||
|
||||
@@ -59,13 +59,15 @@ public class LocationModePreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationModePreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = new LocationModePreferenceController(mContext, mFragment, new Lifecycle());
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = new LocationModePreferenceController(mContext, mFragment, mLifecycle);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@@ -48,12 +48,14 @@ public class LocationModeRadioButtonPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationModeRadioButtonPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new LocationModeRadioButtonPreferenceControllerTestable(mContext);
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = new LocationModeRadioButtonPreferenceControllerTestable(mContext, mLifecycle);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@@ -116,8 +118,9 @@ public class LocationModeRadioButtonPreferenceControllerTest {
|
||||
private class LocationModeRadioButtonPreferenceControllerTestable
|
||||
extends LocationModeRadioButtonPreferenceController {
|
||||
|
||||
public LocationModeRadioButtonPreferenceControllerTestable(Context context) {
|
||||
super(context, new Lifecycle());
|
||||
public LocationModeRadioButtonPreferenceControllerTestable(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -34,11 +35,17 @@ import org.robolectric.annotation.Config;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class LocationModeSensorsOnlyPreferenceControllerTest {
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLocationMode_shouldReturnModeSensorsOnly() {
|
||||
final LocationModeSensorsOnlyPreferenceController controller =
|
||||
new LocationModeSensorsOnlyPreferenceController(mock(Context.class),
|
||||
new Lifecycle());
|
||||
new LocationModeSensorsOnlyPreferenceController(mock(Context.class), mLifecycle);
|
||||
|
||||
assertThat(controller.getLocationMode())
|
||||
.isEqualTo(Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
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;
|
||||
@@ -67,7 +71,7 @@ public class LocationPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycle = new Lifecycle();
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = new LocationPreferenceController(mContext, mLifecycle);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
@@ -145,13 +149,14 @@ public class LocationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onResume_shouldRegisterObserver() {
|
||||
mLifecycle.onResume();
|
||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUnregisterObserver() {
|
||||
mLifecycle.onPause();
|
||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||
mLifecycle.handleLifecycleEvent(ON_PAUSE);
|
||||
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,13 +62,15 @@ public class LocationServicePreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationServicePreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = spy(new LocationServicePreferenceController(
|
||||
mContext, mFragment, new Lifecycle(), mSettingsInjector));
|
||||
mContext, mFragment, mLifecycle, mSettingsInjector));
|
||||
final String key = mController.getPreferenceKey();
|
||||
when(mScreen.findPreference(key)).thenReturn(mCategory);
|
||||
when(mCategory.getKey()).thenReturn(key);
|
||||
|
||||
@@ -54,14 +54,16 @@ public class LocationSwitchBarControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private LocationSwitchBarController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
ReflectionHelpers.setField(mSwitchBar, "mSwitch", mSwitch);
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = spy(new LocationSwitchBarController(
|
||||
mContext, mSwitchBar, new Lifecycle()));
|
||||
mContext, mSwitchBar, mLifecycle));
|
||||
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,13 +73,15 @@ public class RecentLocationRequestPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private RecentLocationRequestPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController = spy(new RecentLocationRequestPreferenceController(
|
||||
mContext, mFragment, new Lifecycle(), mRecentLocationApps));
|
||||
mContext, mFragment, mLifecycle, mRecentLocationApps));
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mCategory);
|
||||
final String key = mController.getPreferenceKey();
|
||||
when(mCategory.getKey()).thenReturn(key);
|
||||
|
||||
Reference in New Issue
Block a user