• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.text.Spanned;
22 import android.text.style.TtsSpan;
23 import android.view.ViewGroup;
24 import android.widget.FrameLayout;
25 import android.widget.SimpleAdapter;
26 import android.widget.TextView;
27 
28 import com.android.settings.datetime.ZonePicker;
29 import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
30 import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
31 
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.robolectric.RuntimeEnvironment;
35 import 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 )
47 public class ZonePickerTest {
48 
49     @Test
testConstructTimeZoneAdapter()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