Adopt robolectric 3.6.1
Bug: 71596155 Test: make RunSettingsRoboTests Change-Id: I46362bae1e3ddd3ce19ade1c93250d272f3366e6
This commit is contained in:
@@ -20,6 +20,8 @@ import android.content.Context;
|
|||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settingslib.utils.AsyncLoader;
|
import com.android.settingslib.utils.AsyncLoader;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loader that can be used by classes to load BatteryInfo in a background thread. This loader will
|
* Loader that can be used by classes to load BatteryInfo in a background thread. This loader will
|
||||||
* automatically grab enhanced battery estimates if available or fall back to the system estimate
|
* automatically grab enhanced battery estimates if available or fall back to the system estimate
|
||||||
@@ -30,9 +32,13 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
|||||||
BatteryStatsHelper mStatsHelper;
|
BatteryStatsHelper mStatsHelper;
|
||||||
private static final String LOG_TAG = "BatteryInfoLoader";
|
private static final String LOG_TAG = "BatteryInfoLoader";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
BatteryUtils batteryUtils;
|
||||||
|
|
||||||
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
||||||
super(context);
|
super(context);
|
||||||
mStatsHelper = batteryStatsHelper;
|
mStatsHelper = batteryStatsHelper;
|
||||||
|
batteryUtils = BatteryUtils.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +48,6 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BatteryInfo loadInBackground() {
|
public BatteryInfo loadInBackground() {
|
||||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(getContext());
|
|
||||||
return batteryUtils.getBatteryInfo(mStatsHelper, LOG_TAG);
|
return batteryUtils.getBatteryInfo(mStatsHelper, LOG_TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -136,7 +136,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
mContext.getSharedPreferences(SHARED_PREFS_TAG, Context.MODE_PRIVATE)
|
mContext.getSharedPreferences(SHARED_PREFS_TAG, Context.MODE_PRIVATE)
|
||||||
.edit()
|
.edit()
|
||||||
.clear()
|
.clear()
|
||||||
.commit();
|
.apply();
|
||||||
dropTables(db);
|
dropTables(db);
|
||||||
createDatabases(db);
|
createDatabases(db);
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
|
|||||||
|
|
||||||
LOCAL_JAVA_LIBRARIES := \
|
LOCAL_JAVA_LIBRARIES := \
|
||||||
junit \
|
junit \
|
||||||
platform-robolectric-3.5.1-prebuilt \
|
platform-robolectric-3.6.1-prebuilt \
|
||||||
telephony-common
|
telephony-common
|
||||||
|
|
||||||
LOCAL_INSTRUMENTATION_FOR := Settings
|
LOCAL_INSTRUMENTATION_FOR := Settings
|
||||||
@@ -42,4 +42,4 @@ LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src
|
|||||||
|
|
||||||
LOCAL_ROBOTEST_TIMEOUT := 36000
|
LOCAL_ROBOTEST_TIMEOUT := 36000
|
||||||
|
|
||||||
include prebuilts/misc/common/robolectric/3.5.1/run_robotests.mk
|
include prebuilts/misc/common/robolectric/3.6.1/run_robotests.mk
|
||||||
|
@@ -90,7 +90,7 @@ public class BluetoothPairingPreferenceControllerTest {
|
|||||||
Preference pref = mController.createBluetoothPairingPreference(ORDER);
|
Preference pref = mController.createBluetoothPairingPreference(ORDER);
|
||||||
|
|
||||||
assertThat(pref.getKey()).isEqualTo(BluetoothPairingPreferenceController.KEY_PAIRING);
|
assertThat(pref.getKey()).isEqualTo(BluetoothPairingPreferenceController.KEY_PAIRING);
|
||||||
assertThat(pref.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_add));
|
assertThat(pref.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_menu_add));
|
||||||
assertThat(pref.getOrder()).isEqualTo(ORDER);
|
assertThat(pref.getOrder()).isEqualTo(ORDER);
|
||||||
assertThat(pref.getTitle()).isEqualTo(
|
assertThat(pref.getTitle()).isEqualTo(
|
||||||
mContext.getString(R.string.bluetooth_pairing_pref_title));
|
mContext.getString(R.string.bluetooth_pairing_pref_title));
|
||||||
|
@@ -76,6 +76,7 @@ public class BatteryInfoLoaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test_loadInBackground_dischargingOldEstimate_dischargingLabelNotNull() {
|
public void test_loadInBackground_dischargingOldEstimate_dischargingLabelNotNull() {
|
||||||
BatteryInfoLoader loader = new BatteryInfoLoader(mContext, mHelper);
|
BatteryInfoLoader loader = new BatteryInfoLoader(mContext, mHelper);
|
||||||
|
loader.batteryUtils = new BatteryUtils(mContext);
|
||||||
|
|
||||||
BatteryInfo info = loader.loadInBackground();
|
BatteryInfo info = loader.loadInBackground();
|
||||||
|
|
||||||
|
@@ -190,8 +190,7 @@ public class XmlParserUtilTest {
|
|||||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||||
&& type != XmlPullParser.START_TAG) {
|
&& type != XmlPullParser.START_TAG) {
|
||||||
}
|
}
|
||||||
while (parser.getName() != xmlType) {
|
while (parser.getName() != xmlType && parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||||
parser.next();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
@@ -79,7 +79,6 @@ public class SlicesIndexerTest {
|
|||||||
String newKey = "newKey";
|
String newKey = "newKey";
|
||||||
String newTitle = "newTitle";
|
String newTitle = "newTitle";
|
||||||
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
||||||
Locale.setDefault(new Locale("ca"));
|
|
||||||
insertSpecialCase(newKey, newTitle);
|
insertSpecialCase(newKey, newTitle);
|
||||||
|
|
||||||
// Attempt indexing - should not do anything.
|
// Attempt indexing - should not do anything.
|
||||||
|
@@ -15,25 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.testutils;
|
package com.android.settings.testutils;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import java.net.MalformedURLException;
|
||||||
import android.content.Intent;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.junit.runners.model.InitializationError;
|
import org.junit.runners.model.InitializationError;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.android.controller.ActivityController;
|
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.manifest.AndroidManifest;
|
import org.robolectric.manifest.AndroidManifest;
|
||||||
import org.robolectric.res.Fs;
|
import org.robolectric.res.Fs;
|
||||||
import org.robolectric.res.ResourcePath;
|
import org.robolectric.res.ResourcePath;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT;
|
|
||||||
import static org.robolectric.Robolectric.getShadowsAdapter;
|
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom test runner for the testing of BluetoothPairingDialogs. This is needed because the
|
* Custom test runner for the testing of BluetoothPairingDialogs. This is needed because the
|
||||||
* default behavior for robolectric is just to grab the resource directory in the target package.
|
* default behavior for robolectric is just to grab the resource directory in the target package.
|
||||||
@@ -54,68 +46,49 @@ public class SettingsRobolectricTestRunner extends RobolectricTestRunner {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AndroidManifest getAppManifest(Config config) {
|
protected AndroidManifest getAppManifest(Config config) {
|
||||||
// Using the manifest file's relative path, we can figure out the application directory.
|
try {
|
||||||
final String appRoot = "packages/apps/Settings";
|
// Using the manifest file's relative path, we can figure out the application directory.
|
||||||
final String manifestPath = appRoot + "/AndroidManifest.xml";
|
final URL appRoot = new URL("file:packages/apps/Settings/");
|
||||||
final String resDir = appRoot + "/tests/robotests/res";
|
final URL manifestPath = new URL(appRoot, "AndroidManifest.xml");
|
||||||
final String assetsDir = appRoot + config.assetDir();
|
final URL resDir = new URL(appRoot, "tests/robotests/res");
|
||||||
|
final URL assetsDir = new URL(appRoot, "tests/robotests/assets");
|
||||||
|
|
||||||
// By adding any resources from libraries we need the AndroidManifest, we can access
|
// By adding any resources from libraries we need the AndroidManifest, we can access
|
||||||
// them from within the parallel universe's resource loader.
|
// them from within the parallel universe's resource loader.
|
||||||
return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir),
|
return new AndroidManifest(Fs.fromURL(manifestPath), Fs.fromURL(resDir),
|
||||||
Fs.fileFromPath(assetsDir), "com.android.settings") {
|
Fs.fromURL(assetsDir), "com.android.settings") {
|
||||||
@Override
|
@Override
|
||||||
public List<ResourcePath> getIncludedResourcePaths() {
|
public List<ResourcePath> getIncludedResourcePaths() {
|
||||||
List<ResourcePath> paths = super.getIncludedResourcePaths();
|
final List<ResourcePath> paths = super.getIncludedResourcePaths();
|
||||||
SettingsRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths);
|
addIncludedResourcePaths(paths);
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException("SettingsRobolectricTestRunner failure", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) {
|
public static void addIncludedResourcePaths(List<ResourcePath> paths) {
|
||||||
paths.add(new ResourcePath(
|
try {
|
||||||
null,
|
paths.add(new ResourcePath(null,
|
||||||
Fs.fileFromPath("./packages/apps/Settings/res"),
|
Fs.fromURL(new URL("file:packages/apps/Settings/res")), null));
|
||||||
null));
|
paths.add(new ResourcePath(null,
|
||||||
paths.add(new ResourcePath(
|
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/res")), null));
|
||||||
null,
|
paths.add(new ResourcePath(null,
|
||||||
Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
|
Fs.fromURL(new URL("file:frameworks/base/core/res/res")), null));
|
||||||
null));
|
paths.add(new ResourcePath(null,
|
||||||
paths.add(new ResourcePath(
|
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/main/res")), null));
|
||||||
null,
|
paths.add(new ResourcePath(null,
|
||||||
Fs.fileFromPath("./frameworks/base/core/res/res"),
|
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/gingerbread/res")), null));
|
||||||
null));
|
paths.add(new ResourcePath(null,
|
||||||
paths.add(new ResourcePath(
|
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/recyclerview/res")), null));
|
||||||
null,
|
paths.add(new ResourcePath(null,
|
||||||
Fs.fileFromPath("./frameworks/opt/setupwizard/library/main/res"),
|
Fs.fromURL(new URL("file:frameworks/support/v7/appcompat/res")), null));
|
||||||
null));
|
paths.add(new ResourcePath(null,
|
||||||
paths.add(new ResourcePath(
|
Fs.fromURL(new URL("file:frameworks/support/v7/cardview/res")), null));
|
||||||
null,
|
} catch (MalformedURLException e) {
|
||||||
Fs.fileFromPath("./frameworks/opt/setupwizard/library/gingerbread/res"),
|
throw new RuntimeException("SettingsRobolectricTestRunner failure", e);
|
||||||
null));
|
}
|
||||||
paths.add(new ResourcePath(
|
|
||||||
null,
|
|
||||||
Fs.fileFromPath("./frameworks/opt/setupwizard/library/recyclerview/res"),
|
|
||||||
null));
|
|
||||||
paths.add(new ResourcePath(
|
|
||||||
null,
|
|
||||||
Fs.fileFromPath("./frameworks/support/v7/appcompat/res"),
|
|
||||||
null));
|
|
||||||
paths.add(new ResourcePath(
|
|
||||||
null,
|
|
||||||
Fs.fileFromPath("./frameworks/support/v7/cardview/res"),
|
|
||||||
null));
|
|
||||||
}
|
|
||||||
|
|
||||||
// A simple utility class to start a Settings fragment with an intent. The code here is almost
|
|
||||||
// the same as FragmentTestUtil.startFragment except that it starts an activity with an intent.
|
|
||||||
public static void startSettingsFragment(
|
|
||||||
Fragment fragment, Class<? extends SettingsActivity> activityClass) {
|
|
||||||
Intent intent = new Intent().putExtra(EXTRA_SHOW_FRAGMENT, fragment.getClass().getName());
|
|
||||||
SettingsActivity activity = ActivityController.of(
|
|
||||||
getShadowsAdapter(), ReflectionHelpers.callConstructor(activityClass), intent)
|
|
||||||
.setup().get();
|
|
||||||
activity.getFragmentManager().beginTransaction().add(fragment, null).commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user