Search in sources :

Example 1 with ShadowInvalidator

use of org.robolectric.internal.bytecode.ShadowInvalidator in project robolectric by robolectric.

the class SandboxClassLoaderTest method loadClass.

private Class<?> loadClass(Class<?> clazz) throws ClassNotFoundException {
    if (classLoader == null) {
        classLoader = new SandboxClassLoader(configureBuilder().build());
    }
    setStaticField(classLoader.loadClass(InvokeDynamicSupport.class.getName()), "INTERCEPTORS", new Interceptors(Collections.<Interceptor>emptyList()));
    setStaticField(classLoader.loadClass(Shadow.class.getName()), "SHADOW_IMPL", newInstance(classLoader.loadClass(ShadowImpl.class.getName())));
    ShadowInvalidator invalidator = Mockito.mock(ShadowInvalidator.class);
    when(invalidator.getSwitchPoint(any(Class.class))).thenReturn(new SwitchPoint());
    String className = RobolectricInternals.class.getName();
    Class<?> robolectricInternalsClass = ReflectionHelpers.loadClass(classLoader, className);
    ReflectionHelpers.setStaticField(robolectricInternalsClass, "classHandler", classHandler);
    ReflectionHelpers.setStaticField(robolectricInternalsClass, "shadowInvalidator", invalidator);
    return classLoader.loadClass(clazz.getName());
}
Also used : Interceptors(org.robolectric.internal.bytecode.Interceptors) ShadowInvalidator(org.robolectric.internal.bytecode.ShadowInvalidator) SwitchPoint(java.lang.invoke.SwitchPoint) ShadowImpl(org.robolectric.internal.bytecode.ShadowImpl) 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) Matchers.anyString(org.mockito.Matchers.anyString) AnInstrumentedClassWithoutToStringWithSuperToString(org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString) AClassWithoutEqualsHashCodeToString(org.robolectric.testing.AClassWithoutEqualsHashCodeToString) AClassWithEqualsHashCodeToString(org.robolectric.testing.AClassWithEqualsHashCodeToString) Interceptor(org.robolectric.internal.bytecode.Interceptor) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader)

Aggregations

SwitchPoint (java.lang.invoke.SwitchPoint)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Interceptor (org.robolectric.internal.bytecode.Interceptor)1 Interceptors (org.robolectric.internal.bytecode.Interceptors)1 SandboxClassLoader (org.robolectric.internal.bytecode.SandboxClassLoader)1 ShadowImpl (org.robolectric.internal.bytecode.ShadowImpl)1 ShadowInvalidator (org.robolectric.internal.bytecode.ShadowInvalidator)1 AClassThatCallsAMethodReturningAForgettableClass (org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass)1 AClassThatRefersToAForgettableClass (org.robolectric.testing.AClassThatRefersToAForgettableClass)1 AClassWithEqualsHashCodeToString (org.robolectric.testing.AClassWithEqualsHashCodeToString)1 AClassWithoutEqualsHashCodeToString (org.robolectric.testing.AClassWithoutEqualsHashCodeToString)1 AFinalClass (org.robolectric.testing.AFinalClass)1 AnExampleClass (org.robolectric.testing.AnExampleClass)1 AnInstrumentedClassWithoutToStringWithSuperToString (org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString)1 AnUninstrumentedClass (org.robolectric.testing.AnUninstrumentedClass)1