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 21 import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter; 22 import com.android.settings.testutils.SettingsRobolectricTestRunner; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 27 import java.util.Date; 28 import java.util.Locale; 29 30 @RunWith(SettingsRobolectricTestRunner.class) 31 public class TimeZoneInfoTest { 32 33 @Test 34 public void testFormat() { 35 Date now = new Date(0L); // 00:00 1/1/1970 36 Formatter formatter = new Formatter(Locale.US, now); 37 38 TimeZoneInfo timeZoneInfo = formatter.format("America/Los_Angeles"); 39 assertThat(timeZoneInfo.getId()).isEqualTo("America/Los_Angeles"); 40 assertThat(timeZoneInfo.getExemplarLocation()).isEqualTo("Los Angeles"); 41 assertThat(timeZoneInfo.getGmtOffset().toString()).isEqualTo("GMT-08:00"); 42 assertThat(timeZoneInfo.getGenericName()).isEqualTo("Pacific Time"); 43 assertThat(timeZoneInfo.getStandardName()).isEqualTo("Pacific Standard Time"); 44 assertThat(timeZoneInfo.getDaylightName()).isEqualTo("Pacific Daylight Time"); 45 } 46 47 @Test 48 public void getGmtOffset_zoneLordHowe_correctGmtOffset() { 49 Date date = new Date(1514764800000L); // 00:00 1/1/2018 GMT 50 Formatter formatter = new Formatter(Locale.US, date); 51 52 TimeZoneInfo timeZoneInfo = formatter.format("Australia/Lord_Howe"); 53 assertThat(timeZoneInfo.getGmtOffset().toString()).isEqualTo("GMT+11:00"); 54 } 55 } 56