blob: 8099eb11edb4f8119723b420d2f670a6ccaaa2b9 [file] [log] [blame]
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.settingslib;
17
18import org.junit.runners.model.InitializationError;
19import org.robolectric.RobolectricTestRunner;
20import org.robolectric.annotation.Config;
21import org.robolectric.manifest.AndroidManifest;
22import org.robolectric.res.Fs;
Fan Zhang60b850d2017-07-18 15:59:06 -070023import org.robolectric.res.ResourcePath;
24
25import java.util.List;
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -080026
Tony Mantler4ca9ebd2017-07-31 10:54:20 -070027public class SettingsLibRobolectricTestRunner extends RobolectricTestRunner {
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -080028
Tony Mantler4ca9ebd2017-07-31 10:54:20 -070029 public SettingsLibRobolectricTestRunner(Class<?> testClass) throws InitializationError {
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -080030 super(testClass);
31 }
32
33 @Override
34 protected AndroidManifest getAppManifest(Config config) {
35 // Using the manifest file's relative path, we can figure out the application directory.
36 final String appRoot = "frameworks/base/packages/SettingsLib";
37 final String manifestPath = appRoot + "/AndroidManifest.xml";
38 final String resDir = appRoot + "/tests/robotests/res";
39 final String assetsDir = appRoot + config.assetDir();
40
41 final AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath),
Fan Zhang60b850d2017-07-18 15:59:06 -070042 Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) {
43 @Override
44 public List<ResourcePath> getIncludedResourcePaths() {
45 List<ResourcePath> paths = super.getIncludedResourcePaths();
Tony Mantler4ca9ebd2017-07-31 10:54:20 -070046 SettingsLibRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths);
Fan Zhang60b850d2017-07-18 15:59:06 -070047 return paths;
48 }
49 };
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -080050 manifest.setPackageName("com.android.settingslib");
51 return manifest;
52 }
53
Fan Zhang60b850d2017-07-18 15:59:06 -070054 static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) {
55 paths.add(new ResourcePath(
56 packageName,
57 Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
58 null));
59 paths.add(new ResourcePath(
60 packageName,
61 Fs.fileFromPath("./frameworks/base/core/res/res"),
62 null));
63 paths.add(new ResourcePath(
64 packageName,
65 Fs.fileFromPath("./frameworks/support/v7/appcompat/res"),
66 null));
67 }
68
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -080069}