184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam/*
284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * Copyright (C) 2016 The Android Open Source Project
384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam *
484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * you may not use this file except in compliance with the License.
684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * You may obtain a copy of the License at
784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam *
884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam *
1084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * Unless required by applicable law or agreed to in writing, software
1184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
1284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * See the License for the specific language governing permissions and
1484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam * limitations under the License
1584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam */
1684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
1784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lampackage com.android.settings;
1884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
1984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport static com.google.common.truth.Truth.assertThat;
2084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
2184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.text.Spanned;
2284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.text.style.TtsSpan;
2384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.view.ViewGroup;
2484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.widget.FrameLayout;
2584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.widget.SimpleAdapter;
2684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport android.widget.TextView;
2784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
281447da277b7c26713571b0e818794e70ec4dc6d2Fan Zhangimport com.android.settings.datetime.ZonePicker;
299f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner;
3084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
3184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport com.android.settings.testutils.shadow.ShadowTimeZoneNames;
3284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
3384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport org.junit.Test;
3484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport org.junit.runner.RunWith;
3584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport org.robolectric.RuntimeEnvironment;
3684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lamimport org.robolectric.annotation.Config;
3784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
3884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam@RunWith(SettingsRobolectricTestRunner.class)
3984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam@Config(
4084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        manifest = TestConfig.MANIFEST_PATH,
4184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        sdk = TestConfig.SDK_VERSION,
4284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        shadows = {
4384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam                ShadowLibcoreTimeZoneNames.class,
4484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam                ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class,
4584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam                ShadowTimeZoneNames.class
4684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        }
4784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam)
4884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lampublic class ZonePickerTest {
4984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
5084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam    @Test
5184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam    public void testConstructTimeZoneAdapter() {
5284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        final SimpleAdapter adapter =
5384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam                ZonePicker.constructTimezoneAdapter(RuntimeEnvironment.application, true);
5484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        assertThat(adapter).isNotNull();
5584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
5684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        ViewGroup parent = new FrameLayout(RuntimeEnvironment.application);
5784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        ViewGroup convertView = new FrameLayout(RuntimeEnvironment.application);
5884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        TextView text1 = new TextView(RuntimeEnvironment.application);
5984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        text1.setId(android.R.id.text1);
6084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        convertView.addView(text1);
6184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        TextView text2 = new TextView(RuntimeEnvironment.application);
6284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        text2.setId(android.R.id.text2);
6384b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        convertView.addView(text2);
6484b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam
6584b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        adapter.getView(0, convertView, parent);
6684b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        final CharSequence text = text2.getText();
6784b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        assertThat(text).isInstanceOf(Spanned.class);
6884b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        final TtsSpan[] spans = ((Spanned) text).getSpans(0, text.length(), TtsSpan.class);
6984b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        // GMT offset label should have TTS spans
7084b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam        assertThat(spans.length).isGreaterThan(0);
7184b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam    }
7284b1ceda7c59787aaef986d819df56cfc812f78cMaurice Lam}
73