Chromium Code Reviews| Index: testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java |
| diff --git a/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java b/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8409fecab524b22a534e232da55a53d3c5d6d1d6 |
| --- /dev/null |
| +++ b/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.testing.local; |
| + |
| +import org.junit.runners.model.InitializationError; |
| + |
| +import org.robolectric.AndroidManifest; |
| +import org.robolectric.DependencyResolver; |
| +import org.robolectric.LocalDependencyResolver; |
| +import org.robolectric.RobolectricTestRunner; |
| +import org.robolectric.SdkConfig; |
| +import org.robolectric.annotation.Config; |
| + |
| +import java.io.File; |
| + |
| +/** |
| + * A custom Robolectric Junit4 Test Runner. This test runner will load the |
| + * "real" android jars from a local directory rather than use Maven to fetch |
| + * them from the Maven Central repository. Additionally, it will ignore the |
| + * API level written in the AndroidManifest as that can cause issues if |
| + * robolectric does not support that API level. |
| + */ |
| +public class LocalRobolectricTestRunner extends RobolectricTestRunner { |
| + |
| + public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationError { |
| + super(testClass); |
| + } |
| + |
| + @Override |
| + protected final DependencyResolver getJarResolver() { |
| + String dependencyDir = System.getProperty("robolectric.dependency.dir"); |
| + if (dependencyDir == null) { |
| + throw new IllegalStateException("robolectric.dependency.dir not specified. Make sure" |
| + + " you are setting the robolectric.dependency.dir system property to the" |
| + + " directory containing Robolectric's runtime dependency jars."); |
| + } |
| + return new LocalDependencyResolver(new File(dependencyDir)); |
| + } |
| + |
| + @Override |
| + protected SdkConfig pickSdkVersion(AndroidManifest appManifest, Config config) { |
| + // Pulling from the manifest is dangerous as the apk might target a version of |
| + // android that robolectric does not yet support. We still allow the API level to |
| + // be overridden with the Config annotation. |
| + return config.emulateSdk() < 0 ? new SdkConfig(18) : super.pickSdkVersion(null, config); |
|
nyquist
2015/03/09 22:10:54
Could you extract 18 to a constant here and below?
mikecase (-- gone --)
2015/03/09 23:40:40
Done.
|
| + } |
| + |
| + @Override |
| + protected int pickReportedSdkVersion(Config config, AndroidManifest appManifest) { |
| + return config.reportSdk() < 0 ? 18 : super.pickReportedSdkVersion(config, appManifest); |
| + } |
| +} |