Migrate robolectric tests to junit tests
This change do the 2 things: 1. Add new junit tests files which replace robolectric RobolectricTestRunner & RuntimeEnvironment with AndroidX objects without problem. 2. Remove the robolectric test files which have it's new junit files. This change migrate 103 files, there are still 1209 files to go. Bug: 174728471 Test: atest make RunSettingsRoboTests Change-Id: I15ed3f4745b85862f720aabbf710ce1475aced93
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 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 com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.icu.text.Collator;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.datetime.timezone.RegionZonePicker.TimeZoneInfoComparator;
|
||||
import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class RegionZonePickerTest {
|
||||
|
||||
@Test
|
||||
public void compareTimeZoneInfo_matchGmtOrder() {
|
||||
Date now = new Date(0); // 00:00 1, Jan 1970
|
||||
Formatter formatter = new Formatter(Locale.US, now);
|
||||
TimeZoneInfo timeZone1 = formatter.format("Pacific/Honolulu");
|
||||
TimeZoneInfo timeZone2 = formatter.format("America/Los_Angeles");
|
||||
TimeZoneInfo timeZone3 = formatter.format("America/Indiana/Marengo");
|
||||
TimeZoneInfo timeZone4 = formatter.format("America/New_York");
|
||||
|
||||
TimeZoneInfoComparator comparator =
|
||||
new TimeZoneInfoComparator(Collator.getInstance(Locale.US), now);
|
||||
|
||||
// Verify the sorted order
|
||||
List<TimeZoneInfo> list = Arrays.asList(timeZone4, timeZone2, timeZone3, timeZone1);
|
||||
Collections.sort(list, comparator);
|
||||
assertThat(list).isEqualTo(Arrays.asList(timeZone1, timeZone2, timeZone3, timeZone4));
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 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 com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TimeZoneInfoPreferenceControllerTest {
|
||||
|
||||
private TimeZoneInfo mTimeZoneInfo;
|
||||
private TimeZoneInfoPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final Context context = ApplicationProvider.getApplicationContext();
|
||||
final Date now = new Date(0L); // 00:00 1/1/1970
|
||||
final Formatter formatter = new Formatter(Locale.US, now);
|
||||
mTimeZoneInfo = formatter.format("America/Los_Angeles");
|
||||
mController = new TimeZoneInfoPreferenceController(context, "key");
|
||||
mController.mDate = now;
|
||||
mController.setTimeZoneInfo(mTimeZoneInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_matchExpectedFormattedText() {
|
||||
assertThat(mController.getSummary().toString()).isEqualTo(
|
||||
"Uses Pacific Time (GMT-08:00). "
|
||||
+ "Pacific Daylight Time starts on April 26, 1970.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_timeZoneInfoSet_shouldReturnAVAILABLE_UNSEARCHABLE() {
|
||||
mController.setTimeZoneInfo(mTimeZoneInfo);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noTimeZoneInfoSet_shouldReturnUNSUPPORTED_ON_DEVICE() {
|
||||
mController.setTimeZoneInfo(null);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 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 com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TimeZoneInfoTest {
|
||||
|
||||
@Test
|
||||
public void testFormat() {
|
||||
Date now = new Date(0L); // 00:00 1/1/1970
|
||||
Formatter formatter = new Formatter(Locale.US, now);
|
||||
|
||||
TimeZoneInfo timeZoneInfo = formatter.format("America/Los_Angeles");
|
||||
assertThat(timeZoneInfo.getId()).isEqualTo("America/Los_Angeles");
|
||||
assertThat(timeZoneInfo.getExemplarLocation()).isEqualTo("Los Angeles");
|
||||
assertThat(timeZoneInfo.getGmtOffset().toString()).isEqualTo("GMT-08:00");
|
||||
assertThat(timeZoneInfo.getGenericName()).isEqualTo("Pacific Time");
|
||||
assertThat(timeZoneInfo.getStandardName()).isEqualTo("Pacific Standard Time");
|
||||
assertThat(timeZoneInfo.getDaylightName()).isEqualTo("Pacific Daylight Time");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGmtOffset_zoneLordHowe_correctGmtOffset() {
|
||||
Date date = new Date(1514764800000L); // 00:00 1/1/2018 GMT
|
||||
Formatter formatter = new Formatter(Locale.US, date);
|
||||
|
||||
TimeZoneInfo timeZoneInfo = formatter.format("Australia/Lord_Howe");
|
||||
assertThat(timeZoneInfo.getGmtOffset().toString()).isEqualTo("GMT+11:00");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user