use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class SandboxTestRunner method createClassLoaderConfig.
/**
* Create an {@link InstrumentationConfiguration} suitable for the provided {@link
* FrameworkMethod}.
*
* <p>Custom TestRunner subclasses may wish to override this method to provide alternate
* configuration.
*
* @param method the test method that's about to run
* @return an {@link InstrumentationConfiguration}
*/
@Nonnull
protected InstrumentationConfiguration createClassLoaderConfig(FrameworkMethod method) {
InstrumentationConfiguration.Builder builder = InstrumentationConfiguration.newBuilder().doNotAcquirePackage("java.").doNotAcquirePackage("jdk.internal.").doNotAcquirePackage("sun.").doNotAcquirePackage("org.robolectric.annotation.").doNotAcquirePackage("org.robolectric.internal.").doNotAcquirePackage("org.robolectric.pluginapi.").doNotAcquirePackage("org.robolectric.util.").doNotAcquirePackage("org.junit");
String customPackages = System.getProperty("org.robolectric.packagesToNotAcquire", "");
for (String pkg : customPackages.split(",")) {
if (!pkg.isEmpty()) {
builder.doNotAcquirePackage(pkg);
}
}
String customClassesRegex = System.getProperty("org.robolectric.classesToNotInstrumentRegex", "");
if (!customClassesRegex.isEmpty()) {
builder.setDoNotInstrumentClassRegex(customClassesRegex);
}
for (Class<?> shadowClass : getExtraShadows(method)) {
ShadowInfo shadowInfo = ShadowMap.obtainShadowInfo(shadowClass);
builder.addInstrumentedClass(shadowInfo.shadowedClassName);
}
addInstrumentedPackages(method, builder);
return builder.build();
}
use of org.robolectric.internal.bytecode.InstrumentationConfiguration 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