use of org.robolectric.pluginapi.Sdk in project robolectric by robolectric.
the class RobolectricTestRunner method getChildren.
@Override
protected List<FrameworkMethod> getChildren() {
List<FrameworkMethod> children = new ArrayList<>();
for (FrameworkMethod frameworkMethod : super.getChildren()) {
try {
Configuration configuration = getConfiguration(frameworkMethod.getMethod());
AndroidManifest appManifest = getAppManifest(configuration);
List<Sdk> sdksToRun = sdkPicker.selectSdks(configuration, appManifest);
RobolectricFrameworkMethod last = null;
for (Sdk sdk : sdksToRun) {
if (resModeStrategy.includeLegacy(appManifest)) {
children.add(last = new RobolectricFrameworkMethod(frameworkMethod.getMethod(), appManifest, sdk, configuration, ResourcesMode.LEGACY, resModeStrategy, alwaysIncludeVariantMarkersInName));
}
if (resModeStrategy.includeBinary(appManifest)) {
children.add(last = new RobolectricFrameworkMethod(frameworkMethod.getMethod(), appManifest, sdk, configuration, ResourcesMode.BINARY, resModeStrategy, alwaysIncludeVariantMarkersInName));
}
}
if (last != null) {
last.dontIncludeVariantMarkersInTestName();
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("failed to configure " + getTestClass().getName() + "." + frameworkMethod.getMethod().getName() + ": " + e.getMessage(), e);
}
}
return children;
}
use of org.robolectric.pluginapi.Sdk in project robolectric by robolectric.
the class SandboxManager method getAndroidSandbox.
public synchronized AndroidSandbox getAndroidSandbox(InstrumentationConfiguration instrumentationConfig, Sdk sdk, ResourcesMode resourcesMode, LooperMode.Mode looperMode) {
SandboxKey key = new SandboxKey(instrumentationConfig, sdk, resourcesMode, looperMode);
AndroidSandbox androidSandbox = sandboxesByKey.get(key);
if (androidSandbox == null) {
Sdk compileSdk = sdkCollection.getMaxSupportedSdk();
androidSandbox = sandboxBuilder.build(instrumentationConfig, sdk, compileSdk, resourcesMode, looperMode);
sandboxesByKey.put(key, androidSandbox);
}
return androidSandbox;
}
use of org.robolectric.pluginapi.Sdk in project robolectric by robolectric.
the class RobolectricTestRunner method beforeTest.
@Override
protected void beforeTest(Sandbox sandbox, FrameworkMethod method, Method bootstrappedMethod) throws Throwable {
AndroidSandbox androidSandbox = (AndroidSandbox) sandbox;
RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
PerfStatsCollector perfStatsCollector = PerfStatsCollector.getInstance();
Sdk sdk = roboMethod.getSdk();
perfStatsCollector.putMetadata(AndroidMetadata.class, new AndroidMetadata(ImmutableMap.of("ro.build.version.sdk", "" + sdk.getApiLevel()), roboMethod.resourcesMode.name()));
Logger.lifecycle(roboMethod.getDeclaringClass().getName() + "." + roboMethod.getMethod().getName() + ": sdk=" + sdk.getApiLevel() + "; resources=" + roboMethod.resourcesMode);
if (roboMethod.resourcesMode == ResourcesMode.LEGACY) {
Logger.warn("Legacy resources mode is deprecated; see" + " http://robolectric.org/migrating/#migrating-to-40");
}
roboMethod.setStuff(androidSandbox, androidSandbox.getTestEnvironment());
Class<TestLifecycle> cl = androidSandbox.bootstrappedClass(getTestLifecycleClass());
roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
AndroidManifest appManifest = roboMethod.getAppManifest();
roboMethod.getTestEnvironment().setUpApplicationState(bootstrappedMethod, roboMethod.getConfiguration(), appManifest);
roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
use of org.robolectric.pluginapi.Sdk in project robolectric by robolectric.
the class TestUtil method systemResources.
public static ResourcePath systemResources() {
if (SYSTEM_RESOURCE_PATH == null) {
Sdk sdk = getSdkCollection().getMaxSupportedSdk();
Path path = sdk.getJarPath();
SYSTEM_RESOURCE_PATH = new ResourcePath(android.R.class, path.resolve("raw-res/res"), path.resolve("raw-res/assets"));
}
return SYSTEM_RESOURCE_PATH;
}
use of org.robolectric.pluginapi.Sdk in project robolectric by robolectric.
the class RobolectricTestRunner method getSandbox.
@Override
@Nonnull
protected AndroidSandbox getSandbox(FrameworkMethod method) {
RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
Sdk sdk = roboMethod.getSdk();
InstrumentationConfiguration classLoaderConfig = createClassLoaderConfig(method);
ResourcesMode resourcesMode = roboMethod.getResourcesMode();
if (resourcesMode == ResourcesMode.LEGACY && sdk.getApiLevel() > Build.VERSION_CODES.P) {
throw new AssumptionViolatedException("Robolectric doesn't support legacy mode after P");
}
LooperMode.Mode looperMode = roboMethod.configuration == null ? Mode.LEGACY : roboMethod.configuration.get(LooperMode.Mode.class);
sdk.verifySupportedSdk(method.getDeclaringClass().getName());
return sandboxManager.getAndroidSandbox(classLoaderConfig, sdk, resourcesMode, looperMode);
}
Aggregations