use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class SandboxFactory method getSdkEnvironment.
public synchronized SdkEnvironment getSdkEnvironment(InstrumentationConfiguration instrumentationConfig, DependencyResolver dependencyResolver, SdkConfig sdkConfig) {
Pair<InstrumentationConfiguration, SdkConfig> key = Pair.create(instrumentationConfig, sdkConfig);
SdkEnvironment sdkEnvironment = sdkToEnvironment.get(key);
if (sdkEnvironment == null) {
URL url = dependencyResolver.getLocalArtifactUrl(sdkConfig.getAndroidSdkDependency());
ClassLoader robolectricClassLoader = createClassLoader(instrumentationConfig, url);
sdkEnvironment = new SdkEnvironment(sdkConfig, robolectricClassLoader);
sdkToEnvironment.put(key, sdkEnvironment);
}
return sdkEnvironment;
}
use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class RobolectricTestRunner method createClassLoaderConfig.
/**
* Create an {@link InstrumentationConfiguration} suitable for the provided {@link
* FrameworkMethod}.
*
* <p>Adds configuration for Android using {@link AndroidConfigurer}.
*
* <p>Custom TestRunner subclasses may wish to override this method to provide additional
* configuration.
*
* @param method the test method that's about to run
* @return an {@link InstrumentationConfiguration}
*/
@Override
@Nonnull
protected InstrumentationConfiguration createClassLoaderConfig(final FrameworkMethod method) {
Configuration configuration = ((RobolectricFrameworkMethod) method).getConfiguration();
Config config = configuration.get(Config.class);
Builder builder = new Builder(super.createClassLoaderConfig(method));
androidConfigurer.configure(builder, getInterceptors());
androidConfigurer.withConfig(builder, config);
return builder.build();
}
use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class SandboxClassLoaderTest method shouldRemapClassesWhileInterceptingMethods.
@Test
public void shouldRemapClassesWhileInterceptingMethods() throws Exception {
InstrumentationConfiguration config = configureBuilder().addClassNameTranslation(AClassToForget.class.getName(), AClassToRemember.class.getName()).addInterceptedMethod(new MethodRef(AClassThatCallsAMethodReturningAForgettableClass.class, "getAForgettableClass")).build();
setClassLoader(new SandboxClassLoader(config));
Class<?> theClass = loadClass(AClassThatCallsAMethodReturningAForgettableClass.class);
theClass.getMethod("callSomeMethod").invoke(shadow.directlyOn(theClass.newInstance(), (Class<Object>) theClass));
}
use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class SandboxClassLoaderTest method shouldDelegateClassLoadForUnacquiredClasses.
@Test
public void shouldDelegateClassLoadForUnacquiredClasses() throws Exception {
InstrumentationConfiguration config = mock(InstrumentationConfiguration.class);
when(config.shouldAcquire(anyString())).thenReturn(false);
when(config.shouldInstrument(any(ClassInfo.class))).thenReturn(false);
ClassLoader classLoader = new SandboxClassLoader(config);
Class<?> exampleClass = classLoader.loadClass(AnExampleClass.class.getName());
assertSame(getClass().getClassLoader(), exampleClass.getClassLoader());
}
use of org.robolectric.internal.bytecode.InstrumentationConfiguration in project robolectric by robolectric.
the class SandboxTestRunner method getSandbox.
@NotNull
protected Sandbox getSandbox(FrameworkMethod method) {
InstrumentationConfiguration instrumentationConfiguration = createClassLoaderConfig(method);
URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
ClassLoader sandboxClassLoader = new SandboxClassLoader(systemClassLoader, instrumentationConfiguration);
Sandbox sandbox = new Sandbox(sandboxClassLoader);
configureShadows(method, sandbox);
return sandbox;
}
Aggregations