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 android.app.Activity;
     20 import android.icu.util.TimeZone;
     21 import android.support.v7.preference.Preference;
     22 
     23 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     24 
     25 import org.junit.Before;
     26 import org.junit.Test;
     27 import org.junit.runner.RunWith;
     28 import org.robolectric.Robolectric;
     29 
     30 import static com.google.common.truth.Truth.assertThat;
     31 
     32 @RunWith(SettingsRobolectricTestRunner.class)
     33 public class FixedOffsetPreferenceControllerTest {
     34 
     35     private Activity mActivity;
     36 
     37     @Before
     38     public void setUp() {
     39         mActivity = Robolectric.setupActivity(Activity.class);
     40     }
     41 
     42     @Test
     43     public void updateState_GmtMinus8_matchTimeZoneSummary() {
     44         TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
     45                     TimeZone.getFrozenTimeZone("Etc/GMT-8"))
     46                     .setGmtOffset("GMT-08:00")
     47                     .build();
     48         Preference preference = new Preference(mActivity);
     49         FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
     50         controller.setTimeZoneInfo(fixedOffsetZone);
     51         controller.updateState(preference);
     52         assertThat(preference.getSummary()).isEqualTo("GMT-08:00");
     53     }
     54 
     55     @Test
     56     public void updateState_Utc_matchTimeZoneSummary() {
     57         TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
     58                     TimeZone.getFrozenTimeZone("Etc/UTC"))
     59                     .setStandardName("Coordinated Universal Time")
     60                     .setGmtOffset("GMT+00:00")
     61                     .build();
     62         Preference preference = new Preference(mActivity);
     63         FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
     64         controller.setTimeZoneInfo(fixedOffsetZone);
     65         controller.updateState(preference);
     66         assertThat(preference.getSummary().toString())
     67                 .isEqualTo("Coordinated Universal Time (GMT+00:00)");
     68     }
     69 }
     70