diff options
| author | 2021-04-09 17:26:16 +0100 | |
|---|---|---|
| committer | 2021-04-09 17:26:16 +0100 | |
| commit | 676d687dc7ab4ff088188af9dbb7d9ca488b0303 (patch) | |
| tree | fc1e8da8976642f8964cd3a4da1316cd84af23a1 | |
| parent | 44772ed462d394489afca07d56fef272b7df3b8c (diff) | |
Move some tests into CTS to avoid duplication
Move some tests into CTS to avoid duplication.
Test: See associated cts/ change
Bug: 184947690
Change-Id: I175725fe5028f06a00580a3a7f21ec6786045804
3 files changed, 0 insertions, 231 deletions
diff --git a/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java b/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java deleted file mode 100644 index 1c6b3cc47a45..000000000000 --- a/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.app.time; - -import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable; -import static android.app.timezonedetector.ParcelableTestSupport.roundTripParcelable; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import android.os.TimestampedValue; - -import org.junit.Test; - -public class ExternalTimeSuggestionTest { - - private static final TimestampedValue<Long> ARBITRARY_TIME = - new TimestampedValue<>(1111L, 2222L); - - @Test - public void testEquals() { - ExternalTimeSuggestion one = new ExternalTimeSuggestion( - ARBITRARY_TIME.getReferenceTimeMillis(), - ARBITRARY_TIME.getValue()); - assertEquals(one, one); - - ExternalTimeSuggestion two = new ExternalTimeSuggestion( - ARBITRARY_TIME.getReferenceTimeMillis(), - ARBITRARY_TIME.getValue()); - assertEquals(one, two); - assertEquals(two, one); - - ExternalTimeSuggestion three = new ExternalTimeSuggestion( - ARBITRARY_TIME.getReferenceTimeMillis() + 1, - ARBITRARY_TIME.getValue()); - assertNotEquals(one, three); - assertNotEquals(three, one); - - // DebugInfo must not be considered in equals(). - one.addDebugInfo("Debug info 1"); - two.addDebugInfo("Debug info 2"); - assertEquals(one, two); - } - - @Test - public void testParcelable() { - ExternalTimeSuggestion suggestion = new ExternalTimeSuggestion( - ARBITRARY_TIME.getReferenceTimeMillis(), - ARBITRARY_TIME.getValue()); - assertRoundTripParcelable(suggestion); - - // DebugInfo should also be stored (but is not checked by equals()) - suggestion.addDebugInfo("This is debug info"); - ExternalTimeSuggestion rtSuggestion = roundTripParcelable(suggestion); - assertEquals(suggestion.getDebugInfo(), rtSuggestion.getDebugInfo()); - } -} diff --git a/core/tests/coretests/src/android/service/timezone/ParcelableTestSupport.java b/core/tests/coretests/src/android/service/timezone/ParcelableTestSupport.java deleted file mode 100644 index 777bda9fe1ff..000000000000 --- a/core/tests/coretests/src/android/service/timezone/ParcelableTestSupport.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.service.timezone; - -import static org.junit.Assert.assertEquals; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.lang.reflect.Field; - -/** Utility methods related to {@link Parcelable} objects used in several tests. */ -final class ParcelableTestSupport { - - private ParcelableTestSupport() {} - - /** Returns the result of parceling and unparceling the argument. */ - @SuppressWarnings("unchecked") - public static <T extends Parcelable> T roundTripParcelable(T parcelable) { - Parcel parcel = Parcel.obtain(); - parcel.writeTypedObject(parcelable, 0); - parcel.setDataPosition(0); - - Parcelable.Creator<T> creator; - try { - Field creatorField = parcelable.getClass().getField("CREATOR"); - creator = (Parcelable.Creator<T>) creatorField.get(null); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new AssertionError(e); - } - T toReturn = parcel.readTypedObject(creator); - parcel.recycle(); - return toReturn; - } - - public static <T extends Parcelable> void assertRoundTripParcelable(T instance) { - assertEquals(instance, roundTripParcelable(instance)); - } -} diff --git a/core/tests/coretests/src/android/service/timezone/TimeZoneProviderSuggestionTest.java b/core/tests/coretests/src/android/service/timezone/TimeZoneProviderSuggestionTest.java deleted file mode 100644 index f805555145f6..000000000000 --- a/core/tests/coretests/src/android/service/timezone/TimeZoneProviderSuggestionTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.service.timezone; - -import static android.service.timezone.ParcelableTestSupport.assertRoundTripParcelable; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import static java.util.Collections.singletonList; - -import org.junit.Test; - -import java.util.List; - -public class TimeZoneProviderSuggestionTest { - - private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 9999; - - private static final List<String> ARBITRARY_TIME_ZONE_IDS = singletonList("Europe/London"); - - @Test(expected = RuntimeException.class) - public void testInvalidTimeZoneIds() { - new TimeZoneProviderSuggestion.Builder() - .setTimeZoneIds(null); - } - - @Test - public void testEquals() { - TimeZoneProviderSuggestion.Builder builder1 = new TimeZoneProviderSuggestion.Builder() - .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); - { - TimeZoneProviderSuggestion one = builder1.build(); - assertEquals(one, one); - } - - TimeZoneProviderSuggestion.Builder builder2 = new TimeZoneProviderSuggestion.Builder() - .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); - { - TimeZoneProviderSuggestion one = builder1.build(); - TimeZoneProviderSuggestion two = builder2.build(); - assertEquals(one, two); - assertEquals(two, one); - } - - builder1.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); - { - TimeZoneProviderSuggestion one = builder1.build(); - TimeZoneProviderSuggestion two = builder2.build(); - assertNotEquals(one, two); - assertNotEquals(two, one); - } - - builder2.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); - { - TimeZoneProviderSuggestion one = builder1.build(); - TimeZoneProviderSuggestion two = builder2.build(); - assertEquals(one, two); - assertEquals(two, one); - } - - builder2.setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); - { - TimeZoneProviderSuggestion one = builder1.build(); - TimeZoneProviderSuggestion two = builder2.build(); - assertNotEquals(one, two); - assertNotEquals(two, one); - } - - builder1.setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); - { - TimeZoneProviderSuggestion one = builder1.build(); - TimeZoneProviderSuggestion two = builder2.build(); - assertEquals(one, two); - assertEquals(two, one); - } - } - - @Test - public void testParcelable_noTimeZoneIds() { - TimeZoneProviderSuggestion.Builder builder = new TimeZoneProviderSuggestion.Builder() - .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); - assertRoundTripParcelable(builder.build()); - } - - @Test - public void testParcelable_withTimeZoneIds() { - TimeZoneProviderSuggestion.Builder builder = new TimeZoneProviderSuggestion.Builder() - .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) - .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS); - assertRoundTripParcelable(builder.build()); - } -} |