Home | History | Annotate | Download | only in timezone
      1 /*
      2  * Copyright (C) 2018 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.datetime.timezone;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 import static org.mockito.Mockito.mock;
     21 import static org.mockito.Mockito.when;
     22 
     23 import com.android.settings.datetime.timezone.model.TimeZoneData;
     24 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     25 import com.android.settings.testutils.shadow.SettingsShadowResources;
     26 import com.android.settingslib.core.AbstractPreferenceController;
     27 
     28 import org.junit.Test;
     29 import org.junit.runner.RunWith;
     30 import org.robolectric.RuntimeEnvironment;
     31 import org.robolectric.annotation.Config;
     32 
     33 import java.util.Arrays;
     34 import java.util.HashSet;
     35 import java.util.List;
     36 
     37 @RunWith(SettingsRobolectricTestRunner.class)
     38 @Config(shadows = {
     39                 SettingsShadowResources.class,
     40                 SettingsShadowResources.SettingsShadowTheme.class,
     41         })
     42 public class TimeZoneSettingsTest {
     43 
     44     @Test
     45     public void findRegionIdForTzId_matchExpectedCountry() {
     46         String tzId = "Unknown/Secret_City";
     47         TimeZoneData timeZoneData = mock(TimeZoneData.class);
     48         when(timeZoneData.lookupCountryCodesForZoneId(tzId))
     49                 .thenReturn(new HashSet<>(Arrays.asList("US", "GB")));
     50 
     51         TimeZoneSettings settings = new TimeZoneSettings();
     52         settings.setTimeZoneData(timeZoneData);
     53         assertThat(settings.findRegionIdForTzId(tzId, null, "")).matches("US|GB");
     54         assertThat(settings.findRegionIdForTzId(tzId, "GB", "")).isEqualTo("GB");
     55         assertThat(settings.findRegionIdForTzId(tzId, null, "GB")).isEqualTo("GB");
     56     }
     57 
     58     @Test
     59     public void createPreferenceControllers_matchExpectedControllers() {
     60         TimeZoneSettings settings = new TimeZoneSettings();
     61         List<AbstractPreferenceController> controllers =
     62                 settings.createPreferenceControllers(RuntimeEnvironment.application);
     63         assertThat(controllers).hasSize(3);
     64         assertThat(controllers.get(0)).isInstanceOf(RegionPreferenceController.class);
     65         assertThat(controllers.get(1)).isInstanceOf(RegionZonePreferenceController.class);
     66         assertThat(controllers.get(2)).isInstanceOf(FixedOffsetPreferenceController.class);
     67     }
     68 }
     69