Merge "Remove dead code in time zone picker" into pi-dev
This commit is contained in:
@@ -89,7 +89,6 @@ public class BaseTimeZoneInfoPickerTest {
|
||||
.setDaylightName("Pacific Daylight Time")
|
||||
.setExemplarLocation("Los Angeles")
|
||||
.setGmtOffset("GMT-08:00")
|
||||
.setItemId(0)
|
||||
.build();
|
||||
TimeZoneInfo zone2 = new TimeZoneInfo.Builder(
|
||||
TimeZone.getFrozenTimeZone("America/New_York"))
|
||||
@@ -98,7 +97,6 @@ public class BaseTimeZoneInfoPickerTest {
|
||||
.setDaylightName("Eastern Daylight Time")
|
||||
.setExemplarLocation("New York")
|
||||
.setGmtOffset("GMT-05:00")
|
||||
.setItemId(1)
|
||||
.build();
|
||||
|
||||
return Arrays.asList(zone1, zone2);
|
||||
|
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.datetime.timezone;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DataLoaderTest {
|
||||
|
||||
@Test
|
||||
public void testHasData() {
|
||||
List<RegionInfo> regions = new DataLoader(Locale.US).loadRegionInfos();
|
||||
// Sanity check. Real size is closer to 200.
|
||||
assertNotNull(regions);
|
||||
assertTrue(regions.size() > 100);
|
||||
assertEquals("Afghanistan", regions.get(0).getName());
|
||||
assertEquals("Zimbabwe", regions.get(regions.size() - 1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionsWithTimeZone() {
|
||||
List<RegionInfo> regions = new DataLoader(Locale.US).loadRegionInfos();
|
||||
checkRegionHasTimeZone(regions, "AT", "Europe/Vienna");
|
||||
checkRegionHasTimeZone(regions, "US", "America/Los_Angeles");
|
||||
checkRegionHasTimeZone(regions, "CN", "Asia/Shanghai");
|
||||
checkRegionHasTimeZone(regions, "AU", "Australia/Sydney");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixedOffsetTimeZones() {
|
||||
List<TimeZoneInfo> timeZones = new DataLoader(Locale.US).loadFixedOffsets();
|
||||
// Etc/GMT would be equivalent to Etc/UTC, except for how it is labelled. Users have
|
||||
// explicitly asked for UTC to be supported, so make sure we label it as such.
|
||||
checkHasTimeZone(timeZones, "Etc/UTC");
|
||||
checkHasTimeZone(timeZones, "Etc/GMT-1");
|
||||
checkHasTimeZone(timeZones, "Etc/GMT-14");
|
||||
checkHasTimeZone(timeZones, "Etc/GMT+1");
|
||||
checkHasTimeZone(timeZones, "Etc/GMT+12");
|
||||
}
|
||||
|
||||
private void checkRegionHasTimeZone(List<RegionInfo> regions, String regionId, String tzId) {
|
||||
RegionInfo ri = findRegion(regions, regionId);
|
||||
assertTrue("Region " + regionId + " does not have time zone " + tzId,
|
||||
ri.getTimeZoneIds().contains(tzId));
|
||||
}
|
||||
|
||||
private void checkHasTimeZone(List<TimeZoneInfo> timeZoneInfos, String tzId) {
|
||||
for (TimeZoneInfo tz : timeZoneInfos) {
|
||||
if (tz.getId().equals(tzId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Fixed offset time zones do not contain " + tzId);
|
||||
}
|
||||
|
||||
private RegionInfo findRegion(List<RegionInfo> regions, String regionId) {
|
||||
for (RegionInfo region : regions) {
|
||||
if (region.getId().equals(regionId)) {
|
||||
assertNotNull(region.getName());
|
||||
return region;
|
||||
}
|
||||
|
||||
}
|
||||
fail("No region with id " + regionId + " found.");
|
||||
return null; // can't reach.
|
||||
}
|
||||
}
|
@@ -44,7 +44,6 @@ public class FixedOffsetPreferenceControllerTest {
|
||||
TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
|
||||
TimeZone.getFrozenTimeZone("Etc/GMT-8"))
|
||||
.setGmtOffset("GMT-08:00")
|
||||
.setItemId(0)
|
||||
.build();
|
||||
Preference preference = new Preference(mActivity);
|
||||
FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
|
||||
@@ -59,7 +58,6 @@ public class FixedOffsetPreferenceControllerTest {
|
||||
TimeZone.getFrozenTimeZone("Etc/UTC"))
|
||||
.setStandardName("Coordinated Universal Time")
|
||||
.setGmtOffset("GMT+00:00")
|
||||
.setItemId(0)
|
||||
.build();
|
||||
Preference preference = new Preference(mActivity);
|
||||
FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
|
||||
|
@@ -48,7 +48,6 @@ public class RegionZonePreferenceControllerTest {
|
||||
.setDaylightName("Pacific Daylight Time")
|
||||
.setExemplarLocation("Los Angeles")
|
||||
.setGmtOffset("GMT-08:00")
|
||||
.setItemId(0)
|
||||
.build();
|
||||
Preference preference = new Preference(mActivity);
|
||||
RegionZonePreferenceController controller = new RegionZonePreferenceController(mActivity);
|
||||
|
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.icu.util.TimeZone;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
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 org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = TimeZoneAdapterTest.ShadowDataFormat.class)
|
||||
public class TimeZoneAdapterTest {
|
||||
|
||||
@Mock
|
||||
private View.OnClickListener mOnClickListener;
|
||||
|
||||
private TimeZoneAdapter mTimeZoneAdapter;
|
||||
|
||||
private Context mContext;
|
||||
private Locale mDefaultLocale;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
|
||||
mDefaultLocale = Locale.getDefault();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Locale.setDefault(mDefaultLocale);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_onDefaultTimeZone_returnsTypeSelected() {
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getDefault());
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
assertThat(mTimeZoneAdapter.getItemViewType(0))
|
||||
.isEqualTo(TimeZoneAdapter.VIEW_TYPE_SELECTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_onNonDefaultTimeZone_returnsTypeNormal() {
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(getNonDefaultTimeZone());
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
assertThat(mTimeZoneAdapter.getItemViewType(0)).isEqualTo(TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindViewHolder_onDstTimeZone_showsDstLabel() {
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mDstView).isNotNull();
|
||||
assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindViewHolder_onNonDstTimeZone_hidesDstLabel() {
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mDstView).isNotNull();
|
||||
assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindViewHolder_on24Hour() {
|
||||
Locale.setDefault(Locale.US);
|
||||
ShadowDataFormat.mTimeFormatString = "HH:mm";
|
||||
mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
|
||||
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mTimeView).isNotNull();
|
||||
assertThat(viewHolder.mTimeView.getText().toString()).hasLength(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindViewHolder_on12Hour() {
|
||||
Locale.setDefault(Locale.US);
|
||||
ShadowDataFormat.mTimeFormatString = "hh:mm a";
|
||||
mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
|
||||
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mTimeView).isNotNull();
|
||||
assertThat(viewHolder.mTimeView.getText().toString()).hasLength(8);
|
||||
}
|
||||
|
||||
// Pick an arbitrary time zone that's not the current default.
|
||||
private static TimeZone getNonDefaultTimeZone() {
|
||||
final String[] availableIDs = TimeZone.getAvailableIDs();
|
||||
int index = 0;
|
||||
if (TextUtils.equals(availableIDs[index], TimeZone.getDefault().getID())) {
|
||||
index++;
|
||||
}
|
||||
return TimeZone.getTimeZone(availableIDs[index]);
|
||||
}
|
||||
|
||||
private TimeZoneInfo dummyTimeZoneInfo(TimeZone timeZone) {
|
||||
return new TimeZoneInfo.Builder(timeZone).setGmtOffset("GMT+0").setItemId(1).build();
|
||||
}
|
||||
|
||||
@Implements(android.text.format.DateFormat.class)
|
||||
public static class ShadowDataFormat {
|
||||
|
||||
private static String mTimeFormatString = "";
|
||||
|
||||
@Implementation
|
||||
public static String getTimeFormatString(Context context) {
|
||||
return mTimeFormatString;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user