Home | History | Annotate | Download | only in settings
      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.SettingsRobolectricTestRunner;
     30 import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
     31 import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
     32 
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 import org.robolectric.RuntimeEnvironment;
     36 import 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 )
     48 public 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