OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.testing.local; |
| 6 |
| 7 import org.junit.runners.model.InitializationError; |
| 8 |
| 9 import org.robolectric.AndroidManifest; |
| 10 import org.robolectric.DependencyResolver; |
| 11 import org.robolectric.LocalDependencyResolver; |
| 12 import org.robolectric.RobolectricTestRunner; |
| 13 import org.robolectric.SdkConfig; |
| 14 import org.robolectric.annotation.Config; |
| 15 |
| 16 import java.io.File; |
| 17 |
| 18 /** |
| 19 * A custom Robolectric Junit4 Test Runner. This test runner will load the |
| 20 * "real" android jars from a local directory rather than use Maven to fetch |
| 21 * them from the Maven Central repository. Additionally, it will ignore the |
| 22 * API level written in the AndroidManifest as that can cause issues if |
| 23 * robolectric does not support that API level. |
| 24 */ |
| 25 public class LocalRobolectricTestRunner extends RobolectricTestRunner { |
| 26 |
| 27 private static final int ANDROID_API_LEVEL = 18; |
| 28 |
| 29 public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationE
rror { |
| 30 super(testClass); |
| 31 } |
| 32 |
| 33 @Override |
| 34 protected final DependencyResolver getJarResolver() { |
| 35 String dependencyDir = System.getProperty("robolectric.dependency.dir"); |
| 36 if (dependencyDir == null) { |
| 37 throw new IllegalStateException("robolectric.dependency.dir not spec
ified. Make sure" |
| 38 + " you are setting the robolectric.dependency.dir system pr
operty to the" |
| 39 + " directory containing Robolectric's runtime dependency ja
rs."); |
| 40 } |
| 41 return new LocalDependencyResolver(new File(dependencyDir)); |
| 42 } |
| 43 |
| 44 @Override |
| 45 protected SdkConfig pickSdkVersion(AndroidManifest appManifest, Config confi
g) { |
| 46 // Pulling from the manifest is dangerous as the apk might target a vers
ion of |
| 47 // android that robolectric does not yet support. We still allow the API
level to |
| 48 // be overridden with the Config annotation. |
| 49 return config.emulateSdk() < 0 |
| 50 ? new SdkConfig(ANDROID_API_LEVEL) : super.pickSdkVersion(null,
config); |
| 51 } |
| 52 |
| 53 @Override |
| 54 protected int pickReportedSdkVersion(Config config, AndroidManifest appManif
est) { |
| 55 return config.reportSdk() < 0 |
| 56 ? ANDROID_API_LEVEL : super.pickReportedSdkVersion(config, appMa
nifest); |
| 57 } |
| 58 } |
OLD | NEW |