| 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.RobolectricTestRunner; | 9 import org.robolectric.RobolectricTestRunner; |
| 10 import org.robolectric.annotation.Config; | 10 import org.robolectric.SdkPicker; |
| 11 import org.robolectric.manifest.AndroidManifest; | |
| 12 | 11 |
| 13 /** | 12 /** |
| 14 * A custom Robolectric Junit4 Test Runner. This test runner will ignore the | 13 * A custom Robolectric Junit4 Test Runner. This test runner specifies which |
| 15 * API level written in the AndroidManifest as that can cause issues if | 14 * API levels are supported in Chromium. |
| 16 * Robolectric does not support that API level. The API level will be grabbed | |
| 17 * from the robolectric Config annotation, or just be | |
| 18 * |DEFAULT_ANDROID_API_LEVEL| | |
| 19 */ | 15 */ |
| 20 public class LocalRobolectricTestRunner extends RobolectricTestRunner { | 16 public class LocalRobolectricTestRunner extends RobolectricTestRunner { |
| 21 | 17 |
| 22 private static final int DEFAULT_ANDROID_API_LEVEL = 21; | |
| 23 | |
| 24 public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationE
rror { | 18 public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationE
rror { |
| 25 super(testClass); | 19 super(testClass); |
| 26 } | 20 } |
| 27 | 21 |
| 28 @Override | 22 @Override |
| 29 protected int pickSdkVersion(Config config, AndroidManifest appManifest) { | 23 protected SdkPicker createSdkPicker() { |
| 30 // Pulling from the manifest is dangerous as the apk might target a vers
ion of | 24 return new SdkPicker(System.getProperties(), 18, 21, 25); |
| 31 // android that robolectric does not yet support. We still allow the API
level to | |
| 32 // be overridden with the Config annotation. | |
| 33 if (config != null) { | |
| 34 if (config.sdk().length > 1) { | |
| 35 throw new IllegalArgumentException( | |
| 36 "RobolectricTestRunner does not support multiple values
for @Config.sdk"); | |
| 37 } else if (config.sdk().length == 1) { | |
| 38 return config.sdk()[0]; | |
| 39 } | |
| 40 } | |
| 41 return DEFAULT_ANDROID_API_LEVEL; | |
| 42 } | 25 } |
| 43 } | 26 } |
| OLD | NEW |