Search in sources :

Example 6 with MethodRef

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));
}
Also used : MethodRef(org.robolectric.internal.bytecode.MethodRef) AnUninstrumentedClass(org.robolectric.testing.AnUninstrumentedClass) AClassThatRefersToAForgettableClass(org.robolectric.testing.AClassThatRefersToAForgettableClass) AFinalClass(org.robolectric.testing.AFinalClass) AClassThatCallsAMethodReturningAForgettableClass(org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass) AnExampleClass(org.robolectric.testing.AnExampleClass) Method(java.lang.reflect.Method) AClassWithNativeMethod(org.robolectric.testing.AClassWithNativeMethod) AClassWithStaticMethod(org.robolectric.testing.AClassWithStaticMethod) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader)

Example 7 with MethodRef

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);
        }
    }
}
Also used : RoboCharsets(org.robolectric.android.fakes.RoboCharsets) MethodRef(org.robolectric.internal.bytecode.MethodRef) AndroidManifest(org.robolectric.manifest.AndroidManifest) RoboExtendedResponseCache(org.robolectric.android.fakes.RoboExtendedResponseCache) ResourceTable(org.robolectric.res.ResourceTable)

Aggregations

MethodRef (org.robolectric.internal.bytecode.MethodRef)7 SandboxClassLoader (org.robolectric.internal.bytecode.SandboxClassLoader)5 Test (org.junit.Test)4 AClassThatCallsAMethodReturningAForgettableClass (org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass)4 AClassThatRefersToAForgettableClass (org.robolectric.testing.AClassThatRefersToAForgettableClass)4 AFinalClass (org.robolectric.testing.AFinalClass)4 AnExampleClass (org.robolectric.testing.AnExampleClass)4 AnUninstrumentedClass (org.robolectric.testing.AnUninstrumentedClass)4 Method (java.lang.reflect.Method)1 StandardCharsets (java.nio.charset.StandardCharsets)1 RoboCharsets (org.robolectric.android.fakes.RoboCharsets)1 RoboExtendedResponseCache (org.robolectric.android.fakes.RoboExtendedResponseCache)1 InstrumentationConfiguration (org.robolectric.internal.bytecode.InstrumentationConfiguration)1 AndroidManifest (org.robolectric.manifest.AndroidManifest)1 ResourceTable (org.robolectric.res.ResourceTable)1 AClassToForget (org.robolectric.testing.AClassToForget)1 AClassToRemember (org.robolectric.testing.AClassToRemember)1 AClassWithNativeMethod (org.robolectric.testing.AClassWithNativeMethod)1 AClassWithStaticMethod (org.robolectric.testing.AClassWithStaticMethod)1