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