1 /* 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 */ 16 package com.android.settingslib; 17 18 import org.junit.runners.model.InitializationError; 19 import org.robolectric.RobolectricTestRunner; 20 import org.robolectric.annotation.Config; 21 import org.robolectric.manifest.AndroidManifest; 22 import org.robolectric.res.Fs; 23 import org.robolectric.res.ResourcePath; 24 25 import java.util.List; 26 27 public class SettingLibRobolectricTestRunner extends RobolectricTestRunner { 28 29 public SettingLibRobolectricTestRunner(Class<?> testClass) throws InitializationError { 30 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), 42 Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { 43 @Override 44 public List<ResourcePath> getIncludedResourcePaths() { 45 List<ResourcePath> paths = super.getIncludedResourcePaths(); 46 SettingLibRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths); 47 return paths; 48 } 49 }; 50 manifest.setPackageName("com.android.settingslib"); 51 return manifest; 52 } 53 54 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 69 } 70