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.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
|
||||
* 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;
|
||||
private static final String LOG_TAG = "BatteryInfoLoader";
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryUtils batteryUtils;
|
||||
|
||||
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
||||
super(context);
|
||||
mStatsHelper = batteryStatsHelper;
|
||||
batteryUtils = BatteryUtils.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +48,6 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
||||
|
||||
@Override
|
||||
public BatteryInfo loadInBackground() {
|
||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(getContext());
|
||||
return batteryUtils.getBatteryInfo(mStatsHelper, LOG_TAG);
|
||||
}
|
||||
}
|
||||
|
@@ -136,7 +136,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
mContext.getSharedPreferences(SHARED_PREFS_TAG, Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.clear()
|
||||
.commit();
|
||||
.apply();
|
||||
dropTables(db);
|
||||
createDatabases(db);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
junit \
|
||||
platform-robolectric-3.5.1-prebuilt \
|
||||
platform-robolectric-3.6.1-prebuilt \
|
||||
telephony-common
|
||||
|
||||
LOCAL_INSTRUMENTATION_FOR := Settings
|
||||
@@ -42,4 +42,4 @@ LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src
|
||||
|
||||
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);
|
||||
|
||||
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.getTitle()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_pairing_pref_title));
|
||||
|
@@ -76,6 +76,7 @@ public class BatteryInfoLoaderTest {
|
||||
@Test
|
||||
public void test_loadInBackground_dischargingOldEstimate_dischargingLabelNotNull() {
|
||||
BatteryInfoLoader loader = new BatteryInfoLoader(mContext, mHelper);
|
||||
loader.batteryUtils = new BatteryUtils(mContext);
|
||||
|
||||
BatteryInfo info = loader.loadInBackground();
|
||||
|
||||
|
@@ -190,8 +190,7 @@ public class XmlParserUtilTest {
|
||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
&& type != XmlPullParser.START_TAG) {
|
||||
}
|
||||
while (parser.getName() != xmlType) {
|
||||
parser.next();
|
||||
while (parser.getName() != xmlType && parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
@@ -79,7 +79,6 @@ public class SlicesIndexerTest {
|
||||
String newKey = "newKey";
|
||||
String newTitle = "newTitle";
|
||||
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
||||
Locale.setDefault(new Locale("ca"));
|
||||
insertSpecialCase(newKey, newTitle);
|
||||
|
||||
// Attempt indexing - should not do anything.
|
||||
|
@@ -15,25 +15,17 @@
|
||||
*/
|
||||
package com.android.settings.testutils;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.manifest.AndroidManifest;
|
||||
import org.robolectric.res.Fs;
|
||||
import org.robolectric.res.ResourcePath;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
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
|
||||
* 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
|
||||
protected AndroidManifest getAppManifest(Config config) {
|
||||
try {
|
||||
// Using the manifest file's relative path, we can figure out the application directory.
|
||||
final String appRoot = "packages/apps/Settings";
|
||||
final String manifestPath = appRoot + "/AndroidManifest.xml";
|
||||
final String resDir = appRoot + "/tests/robotests/res";
|
||||
final String assetsDir = appRoot + config.assetDir();
|
||||
final URL appRoot = new URL("file:packages/apps/Settings/");
|
||||
final URL manifestPath = new URL(appRoot, "AndroidManifest.xml");
|
||||
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
|
||||
// them from within the parallel universe's resource loader.
|
||||
return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir),
|
||||
Fs.fileFromPath(assetsDir), "com.android.settings") {
|
||||
return new AndroidManifest(Fs.fromURL(manifestPath), Fs.fromURL(resDir),
|
||||
Fs.fromURL(assetsDir), "com.android.settings") {
|
||||
@Override
|
||||
public List<ResourcePath> getIncludedResourcePaths() {
|
||||
List<ResourcePath> paths = super.getIncludedResourcePaths();
|
||||
SettingsRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths);
|
||||
final List<ResourcePath> paths = super.getIncludedResourcePaths();
|
||||
addIncludedResourcePaths(paths);
|
||||
return paths;
|
||||
}
|
||||
};
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException("SettingsRobolectricTestRunner failure", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) {
|
||||
paths.add(new ResourcePath(
|
||||
null,
|
||||
Fs.fileFromPath("./packages/apps/Settings/res"),
|
||||
null));
|
||||
paths.add(new ResourcePath(
|
||||
null,
|
||||
Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
|
||||
null));
|
||||
paths.add(new ResourcePath(
|
||||
null,
|
||||
Fs.fileFromPath("./frameworks/base/core/res/res"),
|
||||
null));
|
||||
paths.add(new ResourcePath(
|
||||
null,
|
||||
Fs.fileFromPath("./frameworks/opt/setupwizard/library/main/res"),
|
||||
null));
|
||||
paths.add(new ResourcePath(
|
||||
null,
|
||||
Fs.fileFromPath("./frameworks/opt/setupwizard/library/gingerbread/res"),
|
||||
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));
|
||||
public static void addIncludedResourcePaths(List<ResourcePath> paths) {
|
||||
try {
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:packages/apps/Settings/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/base/core/res/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/main/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/gingerbread/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/opt/setupwizard/library/recyclerview/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/support/v7/appcompat/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/support/v7/cardview/res")), null));
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException("SettingsRobolectricTestRunner failure", e);
|
||||
}
|
||||
|
||||
// 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