1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.settings;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.text.Spanned;
22import android.text.style.TtsSpan;
23import android.view.ViewGroup;
24import android.widget.FrameLayout;
25import android.widget.SimpleAdapter;
26import android.widget.TextView;
27
28import com.android.settings.datetime.ZonePicker;
29import com.android.settings.testutils.SettingsRobolectricTestRunner;
30import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
31import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
32
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.robolectric.RuntimeEnvironment;
36import org.robolectric.annotation.Config;
37
38@RunWith(SettingsRobolectricTestRunner.class)
39@Config(
40        manifest = TestConfig.MANIFEST_PATH,
41        sdk = TestConfig.SDK_VERSION,
42        shadows = {
43                ShadowLibcoreTimeZoneNames.class,
44                ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class,
45                ShadowTimeZoneNames.class
46        }
47)
48public class ZonePickerTest {
49
50    @Test
51    public void testConstructTimeZoneAdapter() {
52        final SimpleAdapter adapter =
53                ZonePicker.constructTimezoneAdapter(RuntimeEnvironment.application, true);
54        assertThat(adapter).isNotNull();
55
56        ViewGroup parent = new FrameLayout(RuntimeEnvironment.application);
57        ViewGroup convertView = new FrameLayout(RuntimeEnvironment.application);
58        TextView text1 = new TextView(RuntimeEnvironment.application);
59        text1.setId(android.R.id.text1);
60        convertView.addView(text1);
61        TextView text2 = new TextView(RuntimeEnvironment.application);
62        text2.setId(android.R.id.text2);
63        convertView.addView(text2);
64
65        adapter.getView(0, convertView, parent);
66        final CharSequence text = text2.getText();
67        assertThat(text).isInstanceOf(Spanned.class);
68        final TtsSpan[] spans = ((Spanned) text).getSpans(0, text.length(), TtsSpan.class);
69        // GMT offset label should have TTS spans
70        assertThat(spans.length).isGreaterThan(0);
71    }
72}
73