Remove the feature flag and dead code for the old time zone picker

Created b/77277084 to help Android variants to migrate from
old time zone data source, i.e. ZoneGetter.getZonesList, to
new time zone source, e.g. TimeZoneFinder.

Bug: 72376227
Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.datetime
Test: manual
Change-Id: I332077a67cc9f9c83b298e25feea71463e1ee98b
This commit is contained in:
Victor Chang
2018-03-29 18:52:09 +01:00
parent e978d3dae0
commit 6be6c58206
10 changed files with 1 additions and 569 deletions

View File

@@ -1,109 +0,0 @@
package com.android.settings.datetime;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.datetime.ZoneGetter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZonePickerComparatorTest {
// Strings in Chinese are sorted by alphabet order of their Pinyin.
// "伦敦" -> "lundun"; "纽约" -> "niuyue"; "悉尼" -> "xini"
// "开罗" -> "kailuo"; "雅典" -> "yadian"; "上海" -> "shanghai"
private static final String[] TEST_CHINESE_NAME =
{"伦敦", "纽约", "悉尼", "开罗", "雅典", "上海"};
private static final String[] ORDERED_CHINESE_NAME =
{"开罗", "伦敦", "纽约", "上海", "悉尼", "雅典"};
private static final String[] TEST_ENGLISH_NAME =
{"London", "New York", "Sydney", "Cairo", "Athens", "Shanghai"};
private static final String[] ORDERED_ENGLISH_NAME =
{"Athens", "Cairo", "London", "New York", "Shanghai", "Sydney"};
private static final Locale INIT_LOCALE = Locale.getDefault();
private Map<String, List<String>> mTestDataMap;
private List<Map<String, Object>> mTestList;
@Before
public void setUp() {
mTestDataMap = new HashMap<>();
mTestDataMap.put("zh_CN", Arrays.asList(TEST_CHINESE_NAME));
mTestDataMap.put("en_US", Arrays.asList(TEST_ENGLISH_NAME));
}
@After
public void tearDown() {
Locale.setDefault(INIT_LOCALE);
}
@Test
public void testComparator_sortChineseString() {
String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
mTestList = getMockZonesList("zh_CN");
Locale.setDefault(new Locale("zh"));
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_CHINESE_NAME[i]);
}
}
@Test
public void testComparator_sortEnglishString() {
String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
mTestList = getMockZonesList("en_US");
Locale.setDefault(new Locale("en"));
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_ENGLISH_NAME[i]);
}
}
@Test
public void testComparator_sortInteger() {
String sortKey = ZoneGetter.KEY_OFFSET;
// TestList of any locale can be selected to test integer sorting.
mTestList = getMockZonesList("en_US");
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey)).isEqualTo(i);
}
}
private List<Map<String, Object>> getMockZonesList(String locale) {
List<Map<String, Object>> zones = new ArrayList<>();
List<String> testData = mTestDataMap.get(locale);
TimeZone tz = TimeZone.getDefault();
int testSize = testData.size();
for (int i = 0; i < testSize; i++) {
zones.add(createMockDisplayEntry(tz, "GMT+08:00", testData.get(i), testSize - i - 1));
}
return zones;
}
private Map<String, Object> createMockDisplayEntry(
TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
Map<String, Object> map = new HashMap<>();
map.put(ZoneGetter.KEY_ID, tz.getID());
map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
return map;
}
}

View File

@@ -1,66 +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;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowZoneGetter;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZonePickerTest {
private Activity mActivity;
private ZonePicker mZonePicker;
@Before
public void setUp() {
mActivity = Robolectric.setupActivity(Activity.class);
mZonePicker = spy(ZonePicker.class);
ReflectionHelpers.setField(mZonePicker, "mVisibilityLoggerMixin",
mock(VisibilityLoggerMixin.class));
}
@Test
@Config(shadows = ShadowZoneGetter.class)
public void testLaunch() {
// Shouldn't crash
mActivity.getFragmentManager().beginTransaction().add(mZonePicker, "test_tag").commit();
// Should render
verify(mZonePicker).onCreateView(
nullable(LayoutInflater.class),
nullable(ViewGroup.class),
nullable(Bundle.class));
}
}