use of org.robolectric.internal.bytecode.MethodRef in project robolectric by robolectric.
the class SandboxClassLoaderTest method invokeInterceptedMethodOnAClassToForget.
private Object invokeInterceptedMethodOnAClassToForget(String methodName) throws Exception {
setClassLoader(new SandboxClassLoader(configureBuilder().addInterceptedMethod(new MethodRef(AClassToForget.class, "*")).build()));
Class<?> theClass = loadClass(AClassThatRefersToAForgettableClassInMethodCallsReturningPrimitive.class);
Object instance = theClass.newInstance();
Method m = theClass.getDeclaredMethod(methodName);
m.setAccessible(true);
return m.invoke(shadow.directlyOn(instance, (Class<Object>) theClass));
}
use of org.robolectric.internal.bytecode.MethodRef in project robolectric by robolectric.
the class AndroidConfigurer method configure.
public static void configure(InstrumentationConfiguration.Builder builder, Interceptors interceptors) {
for (MethodRef methodRef : interceptors.getAllMethodRefs()) {
builder.addInterceptedMethod(methodRef);
}
builder.doNotAcquireClass(TestLifecycle.class).doNotAcquireClass(AndroidManifest.class).doNotAcquireClass(RobolectricTestRunner.class).doNotAcquireClass(RobolectricTestRunner.HelperTestRunner.class).doNotAcquireClass(ResourcePath.class).doNotAcquireClass(ResourceTable.class).doNotAcquireClass(XmlBlock.class);
builder.doNotAcquirePackage("javax.").doNotAcquirePackage("org.junit").doNotAcquirePackage("org.hamcrest").doNotAcquirePackage("org.robolectric.annotation.").doNotAcquirePackage("org.robolectric.internal.").doNotAcquirePackage("org.robolectric.manifest.").doNotAcquirePackage("org.robolectric.res.").doNotAcquirePackage("org.robolectric.util.").doNotAcquirePackage("org.robolectric.RobolectricTestRunner$").doNotAcquirePackage("sun.").doNotAcquirePackage("com.sun.").doNotAcquirePackage("org.w3c.").doNotAcquirePackage("org.xml.").doNotAcquirePackage(// allows for android projects with mixed scala\java tests to be
"org.specs2").doNotAcquirePackage(// run with Maven Surefire (see the RoboSpecs project on github)
"scala.").doNotAcquirePackage("kotlin.").doNotAcquirePackage(// Fix #958: SQLite native library must be loaded once.
"com.almworks.sqlite4java");
builder.addClassNameTranslation("java.net.ExtendedResponseCache", RoboExtendedResponseCache.class.getName()).addClassNameTranslation("java.net.ResponseSource", RoboResponseSource.class.getName()).addClassNameTranslation("java.nio.charset.Charsets", RoboCharsets.class.getName());
// Instrumenting these classes causes a weird failure.
builder.doNotInstrumentClass("android.R").doNotInstrumentClass("android.R$styleable");
builder.addInstrumentedPackage("dalvik.").addInstrumentedPackage("libcore.").addInstrumentedPackage("android.").addInstrumentedPackage("com.android.internal.").addInstrumentedPackage("org.apache.http.").addInstrumentedPackage("org.ccil.cowan.tagsoup").addInstrumentedPackage("org.kxml2.");
for (ShadowProvider provider : ServiceLoader.load(ShadowProvider.class)) {
for (String packagePrefix : provider.getProvidedPackageNames()) {
builder.addInstrumentedPackage(packagePrefix);
}
}
}
Aggregations