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.shadow.ShadowLibcoreTimeZoneNames; 30import com.android.settings.testutils.shadow.ShadowTimeZoneNames; 31 32import org.junit.Test; 33import org.junit.runner.RunWith; 34import org.robolectric.RuntimeEnvironment; 35import org.robolectric.annotation.Config; 36 37@RunWith(SettingsRobolectricTestRunner.class) 38@Config( 39 manifest = TestConfig.MANIFEST_PATH, 40 sdk = TestConfig.SDK_VERSION, 41 shadows = { 42 ShadowLibcoreTimeZoneNames.class, 43 ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class, 44 ShadowTimeZoneNames.class 45 } 46) 47public class ZonePickerTest { 48 49 @Test 50 public void testConstructTimeZoneAdapter() { 51 final SimpleAdapter adapter = 52 ZonePicker.constructTimezoneAdapter(RuntimeEnvironment.application, true); 53 assertThat(adapter).isNotNull(); 54 55 ViewGroup parent = new FrameLayout(RuntimeEnvironment.application); 56 ViewGroup convertView = new FrameLayout(RuntimeEnvironment.application); 57 TextView text1 = new TextView(RuntimeEnvironment.application); 58 text1.setId(android.R.id.text1); 59 convertView.addView(text1); 60 TextView text2 = new TextView(RuntimeEnvironment.application); 61 text2.setId(android.R.id.text2); 62 convertView.addView(text2); 63 64 adapter.getView(0, convertView, parent); 65 final CharSequence text = text2.getText(); 66 assertThat(text).isInstanceOf(Spanned.class); 67 final TtsSpan[] spans = ((Spanned) text).getSpans(0, text.length(), TtsSpan.class); 68 // GMT offset label should have TTS spans 69 assertThat(spans.length).isGreaterThan(0); 70 } 71} 72