1 /* 2 * Copyright 2020 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 android.service.timezone.cts; 18 19 import static android.app.time.cts.ParcelableTestSupport.assertRoundTripParcelable; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.assertNotEquals; 23 24 import static java.util.Collections.singletonList; 25 26 import android.service.timezone.TimeZoneProviderSuggestion; 27 28 import org.junit.Test; 29 30 import java.util.List; 31 32 public class TimeZoneProviderSuggestionTest { 33 34 private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 9999; 35 36 private static final List<String> ARBITRARY_TIME_ZONE_IDS = singletonList("Europe/London"); 37 38 @Test(expected = RuntimeException.class) testInvalidTimeZoneIds()39 public void testInvalidTimeZoneIds() { 40 new TimeZoneProviderSuggestion.Builder() 41 .setTimeZoneIds(null); 42 } 43 44 @Test testAccessors()45 public void testAccessors() { 46 TimeZoneProviderSuggestion suggestion = new TimeZoneProviderSuggestion.Builder() 47 .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS) 48 .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) 49 .build(); 50 51 assertEquals(ARBITRARY_TIME_ZONE_IDS, suggestion.getTimeZoneIds()); 52 assertEquals(ARBITRARY_ELAPSED_REALTIME_MILLIS, suggestion.getElapsedRealtimeMillis()); 53 } 54 55 @Test testEquals()56 public void testEquals() { 57 TimeZoneProviderSuggestion.Builder builder1 = new TimeZoneProviderSuggestion.Builder() 58 .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); 59 { 60 TimeZoneProviderSuggestion one = builder1.build(); 61 assertEquals(one, one); 62 } 63 64 TimeZoneProviderSuggestion.Builder builder2 = new TimeZoneProviderSuggestion.Builder() 65 .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); 66 { 67 TimeZoneProviderSuggestion one = builder1.build(); 68 TimeZoneProviderSuggestion two = builder2.build(); 69 assertEquals(one, two); 70 assertEquals(two, one); 71 } 72 73 builder1.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); 74 { 75 TimeZoneProviderSuggestion one = builder1.build(); 76 TimeZoneProviderSuggestion two = builder2.build(); 77 assertNotEquals(one, two); 78 assertNotEquals(two, one); 79 } 80 81 builder2.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); 82 { 83 TimeZoneProviderSuggestion one = builder1.build(); 84 TimeZoneProviderSuggestion two = builder2.build(); 85 assertEquals(one, two); 86 assertEquals(two, one); 87 } 88 89 builder2.setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); 90 { 91 TimeZoneProviderSuggestion one = builder1.build(); 92 TimeZoneProviderSuggestion two = builder2.build(); 93 assertNotEquals(one, two); 94 assertNotEquals(two, one); 95 } 96 97 builder1.setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); 98 { 99 TimeZoneProviderSuggestion one = builder1.build(); 100 TimeZoneProviderSuggestion two = builder2.build(); 101 assertEquals(one, two); 102 assertEquals(two, one); 103 } 104 } 105 106 @Test testParcelable_noTimeZoneIds()107 public void testParcelable_noTimeZoneIds() { 108 TimeZoneProviderSuggestion.Builder builder = new TimeZoneProviderSuggestion.Builder() 109 .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); 110 assertRoundTripParcelable(builder.build()); 111 } 112 113 @Test testParcelable_withTimeZoneIds()114 public void testParcelable_withTimeZoneIds() { 115 TimeZoneProviderSuggestion.Builder builder = new TimeZoneProviderSuggestion.Builder() 116 .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) 117 .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); 118 assertRoundTripParcelable(builder.build()); 119 } 120 } 121