Merge "Refactor Date & Time Settings" into main
This commit is contained in:
@@ -53,13 +53,13 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mApplication = ShadowApplication.getInstance();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, "test_key");
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey("test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_24HourSet_shouldCheckPreference() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||
TimeFormatPreferenceController.HOURS_24);
|
||||
|
||||
@@ -70,9 +70,6 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_12HourSet_shouldCheckPreference() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||
TimeFormatPreferenceController.HOURS_12);
|
||||
|
||||
@@ -83,9 +80,6 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoSet_shouldNotCheckPreference() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
@@ -95,14 +89,7 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_autoSet_shouldSendIntent_12HourLocale() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mPreference.setChecked(false);
|
||||
|
||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
mController.setChecked(false);
|
||||
|
||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||
assertThat(intentsFired.size()).isEqualTo(1);
|
||||
@@ -114,15 +101,9 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_autoSet_shouldSendIntent_24HourLocale() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mPreference.setChecked(false);
|
||||
|
||||
mController.setIs24HourLocale(true);
|
||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
mController.setChecked(false);
|
||||
|
||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||
assertThat(intentsFired.size()).isEqualTo(1);
|
||||
@@ -134,15 +115,9 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_24HourSet_shouldSendIntent() {
|
||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mPreference.setChecked(true);
|
||||
|
||||
mController.setIs24HourLocale(false);
|
||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
mController.setChecked(true);
|
||||
|
||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||
assertThat(intentsFired.size()).isEqualTo(1);
|
||||
@@ -161,9 +136,8 @@ public class AutoTimeFormatPreferenceControllerTest {
|
||||
|
||||
private boolean is24HourLocale = false;
|
||||
|
||||
private TestAutoTimeFormatPreferenceController(Context context,
|
||||
UpdateTimeAndDateCallback callback) {
|
||||
super(context, callback);
|
||||
TestAutoTimeFormatPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
void setIs24HourLocale(boolean value) {
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.datetime;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -59,7 +61,8 @@ public class AutoTimePreferenceControllerTest {
|
||||
mPreference = new Preference(mContext);
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
|
||||
mController = new AutoTimePreferenceController(mContext, mCallback);
|
||||
mController = new AutoTimePreferenceController(mContext, "test_key");
|
||||
mController.setDateAndTimeCallback(mCallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +71,7 @@ public class AutoTimePreferenceControllerTest {
|
||||
/* autoSupported= */false, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,24 +84,23 @@ public class AutoTimePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEnabled_shouldReadFromTimeManagerConfig() {
|
||||
{
|
||||
// Disabled
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
|
||||
// Disabled
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
{
|
||||
// Enabled
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
@Test
|
||||
public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
|
||||
// Enabled
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.isEnabled()).isTrue();
|
||||
}
|
||||
assertThat(mController.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,10 +120,10 @@ public class AutoTimePreferenceControllerTest {
|
||||
verify(mTimeManager).updateTimeConfiguration(timeConfiguration);
|
||||
|
||||
// Update the mTimeManager mock so that it now returns the expected updated config.
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
|
||||
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig())
|
||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
|
||||
capabilitiesAndConfigAfterUpdate);
|
||||
|
||||
assertThat(mController.isEnabled()).isTrue();
|
||||
}
|
||||
@@ -145,14 +147,14 @@ public class AutoTimePreferenceControllerTest {
|
||||
// Update the mTimeManager mock so that it now returns the expected updated config.
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
|
||||
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig())
|
||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
|
||||
capabilitiesAndConfigAfterUpdate);
|
||||
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
boolean autoSupported, boolean autoEnabled) {
|
||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(boolean autoSupported,
|
||||
boolean autoEnabled) {
|
||||
int configureAutoDetectionEnabledCapability =
|
||||
autoSupported ? Capabilities.CAPABILITY_POSSESSED
|
||||
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
||||
|
@@ -22,6 +22,8 @@ import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
|
||||
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
|
||||
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -62,6 +64,8 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
@Mock
|
||||
private TimeManager mTimeManager;
|
||||
|
||||
private AutoTimeZonePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -70,6 +74,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
mPreference = new Preference(mContext);
|
||||
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
|
||||
mController = new AutoTimeZonePreferenceController(mContext, "test_key");
|
||||
mController.setFromSUW(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,10 +85,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, true /* isFromSUW */);
|
||||
mController.setFromSUW(true);
|
||||
|
||||
assertThat(controller.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,10 +96,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, false /* isFromSUW */);
|
||||
mController.setFromSUW(false);
|
||||
|
||||
assertThat(controller.isAvailable()).isTrue();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,10 +107,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */false, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, false /* fromSUW */);
|
||||
|
||||
assertThat(controller.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,10 +116,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */false, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, true /* fromSUW */);
|
||||
mController.setFromSUW(true);
|
||||
|
||||
assertThat(controller.isEnabled()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,10 +127,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */false, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, true /* fromSUW */);
|
||||
mController.setFromSUW(true);
|
||||
|
||||
assertThat(controller.isEnabled()).isTrue();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,34 +138,27 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
/* autoSupported= */false, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, false /* fromSUW */);
|
||||
|
||||
assertThat(controller.isEnabled()).isFalse();
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEnabled_shouldReadFromTimeManagerConfig() {
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, null /* callback */, false /* fromSUW */);
|
||||
public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
|
||||
// Disabled
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
{
|
||||
// Disabled
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
assertThat(controller.isEnabled()).isFalse();
|
||||
}
|
||||
@Test
|
||||
public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
|
||||
// Enabled
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
{
|
||||
// Enabled
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(controller.isEnabled()).isTrue();
|
||||
}
|
||||
assertThat(mController.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,10 +168,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, mCallback, false /* fromSUW */);
|
||||
mController.setTimeAndDateCallback(mCallback);
|
||||
|
||||
assertThat(controller.onPreferenceChange(mPreference, true)).isTrue();
|
||||
assertThat(mController.onPreferenceChange(mPreference, true)).isTrue();
|
||||
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
||||
|
||||
// Check the service was asked to change the configuration correctly.
|
||||
@@ -193,7 +185,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||
|
||||
assertThat(controller.isEnabled()).isTrue();
|
||||
assertThat(mController.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,10 +195,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, mCallback, false /* fromSUW */);
|
||||
mController.setTimeAndDateCallback(mCallback);
|
||||
|
||||
assertThat(controller.onPreferenceChange(mPreference, false)).isTrue();
|
||||
assertThat(mController.onPreferenceChange(mPreference, false)).isTrue();
|
||||
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
||||
|
||||
// Check the service was asked to change the configuration correctly.
|
||||
@@ -221,13 +212,12 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||
|
||||
assertThat(controller.isEnabled()).isFalse();
|
||||
assertThat(mController.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary() {
|
||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
||||
mContext, mCallback, false /* fromSUW */);
|
||||
mController.setTimeAndDateCallback(mCallback);
|
||||
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
||||
@@ -235,7 +225,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||
|
||||
assertThat(controller.getSummary()).isEqualTo("");
|
||||
assertThat(mController.getSummary()).isEqualTo("");
|
||||
|
||||
capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
||||
@@ -243,7 +233,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||
|
||||
assertThat(controller.getSummary()).isEqualTo(
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.auto_zone_requires_location_summary));
|
||||
}
|
||||
|
||||
|
@@ -74,12 +74,8 @@ public class DatePreferenceControllerTest {
|
||||
when(mContext.getSystemService(TimeDetector.class)).thenReturn(mTimeDetector);
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
||||
mController = new DatePreferenceController(mContext, mHost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
mController = new DatePreferenceController(mContext, "test_key");
|
||||
mController.setHost(mHost);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,7 +143,7 @@ public class DatePreferenceControllerTest {
|
||||
assertEquals(2020, calendar.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
boolean suggestManualAllowed) {
|
||||
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
|
||||
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
||||
|
@@ -16,13 +16,15 @@
|
||||
|
||||
package com.android.settings.datetime;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -52,27 +54,30 @@ public class TimeFormatPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mApplication = ShadowApplication.getInstance();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TimeFormatPreferenceController(mContext, "test_key");
|
||||
mController.setTimeAndDateCallback(mCallback);
|
||||
mController.setFromSUW(false);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey("test_key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCalledFromSUW_NotAvailable() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, true);
|
||||
mController.setFromSUW(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notCalledFromSUW_shouldBeAvailable() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||
TimeFormatPreferenceController.HOURS_24);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_24HourSet_shouldCheckPreference() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||
TimeFormatPreferenceController.HOURS_24);
|
||||
|
||||
@@ -83,9 +88,6 @@ public class TimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_12HourSet_shouldNotCheckPreference() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||
TimeFormatPreferenceController.HOURS_12);
|
||||
|
||||
@@ -96,10 +98,7 @@ public class TimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoSet_shouldNotEnablePreference() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -108,14 +107,7 @@ public class TimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_12HourSet_shouldSendIntent() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mPreference.setChecked(false);
|
||||
|
||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
mController.setChecked(false);
|
||||
|
||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||
assertThat(intentsFired.size()).isEqualTo(1);
|
||||
@@ -127,14 +119,7 @@ public class TimeFormatPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_24HourSet_shouldSendIntent() {
|
||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
mPreference.setChecked(true);
|
||||
|
||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
mController.setChecked(true);
|
||||
|
||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||
assertThat(intentsFired.size()).isEqualTo(1);
|
||||
|
@@ -18,9 +18,12 @@ package com.android.settings.datetime;
|
||||
|
||||
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.app.time.TimeCapabilitiesAndConfig;
|
||||
import android.app.time.TimeManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -40,7 +43,7 @@ public class TimePreferenceControllerTest {
|
||||
@Mock
|
||||
private TimePreferenceController.TimePreferenceHost mHost;
|
||||
@Mock
|
||||
private DatePreferenceController mDatePreferenceController;
|
||||
private TimeManager mTimeManager;
|
||||
|
||||
private TimePreferenceController mController;
|
||||
private RestrictedPreference mPreference;
|
||||
@@ -48,14 +51,11 @@ public class TimePreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
||||
mController = new TimePreferenceController(mContext, mHost, mDatePreferenceController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = new TimePreferenceController(mContext, "test_key");
|
||||
mController.setHost(mHost);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +63,10 @@ public class TimePreferenceControllerTest {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mDatePreferenceController.isEnabled()).thenReturn(false);
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
|
||||
false);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
@@ -74,7 +77,10 @@ public class TimePreferenceControllerTest {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mDatePreferenceController.isEnabled()).thenReturn(true);
|
||||
TimeCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
|
||||
true);
|
||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
|
@@ -66,15 +66,10 @@ public class TimeZonePreferenceControllerTest {
|
||||
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
|
||||
mController = spy(new TimeZonePreferenceController(mContext));
|
||||
mController = spy(new TimeZonePreferenceController(mContext, "test_key"));
|
||||
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_suggestManualNotAllowed_shouldDisablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
|
Reference in New Issue
Block a user