Use external/robolectric-shadows/run_robotests.mk
This allows Settings to test against the latest framework changes. Also replaced TestConfig with traditional robolectric.properties. Bug: 73173204 Bug: 73892008 Test: make -j56 RunSettingsRoboTests Change-Id: I3135b4fa5f095ba79b282a76f45dd9baa2584bc7
This commit is contained in:
@@ -20,18 +20,15 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DataLoaderTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
*/
|
||||
package com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.icu.util.TimeZone;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -40,15 +39,10 @@ import org.robolectric.annotation.Implements;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
TimeZoneAdapterTest.ShadowDataFormat.class})
|
||||
@Config(shadows = TimeZoneAdapterTest.ShadowDataFormat.class)
|
||||
public class TimeZoneAdapterTest {
|
||||
|
||||
@Mock
|
||||
private View.OnClickListener mOnClickListener;
|
||||
|
||||
@@ -58,7 +52,7 @@ public class TimeZoneAdapterTest {
|
||||
private Locale mDefaultLocale;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
|
||||
@@ -66,26 +60,16 @@ public class TimeZoneAdapterTest {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
Locale.setDefault(mDefaultLocale);
|
||||
}
|
||||
|
||||
@Implements(android.text.format.DateFormat.class)
|
||||
public static class ShadowDataFormat {
|
||||
|
||||
public static String mTimeFormatString = "";
|
||||
|
||||
@Implementation
|
||||
public static String getTimeFormatString(Context context) {
|
||||
return mTimeFormatString;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_onDefaultTimeZone_returnsTypeSelected() {
|
||||
final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getDefault());
|
||||
mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
|
||||
assertThat(mTimeZoneAdapter.getItemViewType(0)).isEqualTo(TimeZoneAdapter.VIEW_TYPE_SELECTED);
|
||||
assertThat(mTimeZoneAdapter.getItemViewType(0))
|
||||
.isEqualTo(TimeZoneAdapter.VIEW_TYPE_SELECTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,8 +86,10 @@ public class TimeZoneAdapterTest {
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mDstView).isNotNull();
|
||||
assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -114,8 +100,10 @@ public class TimeZoneAdapterTest {
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mDstView).isNotNull();
|
||||
assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@@ -130,8 +118,10 @@ public class TimeZoneAdapterTest {
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mTimeView).isNotNull();
|
||||
assertThat(viewHolder.mTimeView.getText().toString()).hasLength(5);
|
||||
}
|
||||
|
||||
@@ -146,8 +136,10 @@ public class TimeZoneAdapterTest {
|
||||
|
||||
final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
|
||||
|
||||
final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
final ViewHolder viewHolder =
|
||||
(ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
|
||||
mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
|
||||
assertThat(viewHolder.mTimeView).isNotNull();
|
||||
assertThat(viewHolder.mTimeView.getText().toString()).hasLength(8);
|
||||
}
|
||||
|
||||
@@ -164,4 +156,15 @@ public class TimeZoneAdapterTest {
|
||||
private TimeZoneInfo dummyTimeZoneInfo(TimeZone timeZone) {
|
||||
return new TimeZoneInfo.Builder(timeZone).setGmtOffset("GMT+0").setItemId(1).build();
|
||||
}
|
||||
|
||||
@Implements(android.text.format.DateFormat.class)
|
||||
public static class ShadowDataFormat {
|
||||
|
||||
private static String mTimeFormatString = "";
|
||||
|
||||
@Implementation
|
||||
public static String getTimeFormatString(Context context) {
|
||||
return mTimeFormatString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,23 +16,18 @@
|
||||
|
||||
package com.android.settings.datetime.timezone;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class TimeZoneInfoTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,29 +16,25 @@
|
||||
|
||||
package com.android.settings.datetime.timezone.model;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import libcore.util.CountryTimeZones;
|
||||
import libcore.util.CountryZonesFinder;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import libcore.util.CountryTimeZones;
|
||||
import libcore.util.CountryTimeZones.TimeZoneMapping;
|
||||
import libcore.util.CountryZonesFinder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class TimeZoneDataTest {
|
||||
|
||||
private CountryZonesFinder mCountryZonesFinder;
|
||||
@@ -61,7 +57,7 @@ public class TimeZoneDataTest {
|
||||
|
||||
@Test
|
||||
public void testGetRegionIds() {
|
||||
when(mCountryZonesFinder.lookupAllCountryIsoCodes()).thenReturn(Arrays.asList());
|
||||
when(mCountryZonesFinder.lookupAllCountryIsoCodes()).thenReturn(Collections.emptyList());
|
||||
TimeZoneData timeZoneData = new TimeZoneData(mCountryZonesFinder);
|
||||
assertThat(timeZoneData.getRegionIds()).isEmpty();
|
||||
|
||||
@@ -82,8 +78,8 @@ public class TimeZoneDataTest {
|
||||
));
|
||||
CountryTimeZones GB = mock(CountryTimeZones.class);
|
||||
when(GB.getCountryIso()).thenReturn("gb");
|
||||
when(GB.getTimeZoneMappings()).thenReturn(Arrays.asList(
|
||||
new CountryTimeZones.TimeZoneMapping("Unknown/Secret_City", true)
|
||||
when(GB.getTimeZoneMappings()).thenReturn(Collections.singletonList(
|
||||
new TimeZoneMapping("Unknown/Secret_City", true)
|
||||
));
|
||||
when(mCountryZonesFinder.lookupCountryTimeZonesForZoneId("Unknown/Secret_City"))
|
||||
.thenReturn(Arrays.asList(US, GB));
|
||||
|
||||
Reference in New Issue
Block a user