Search in sources :

Example 11 with SandboxClassLoader

use of org.robolectric.internal.bytecode.SandboxClassLoader 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;
}
Also used : InstrumentationConfiguration(org.robolectric.internal.bytecode.InstrumentationConfiguration) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader) Sandbox(org.robolectric.internal.bytecode.Sandbox) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with SandboxClassLoader

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

the class SandboxClassLoaderTest method shouldFixTypesInMethodArgsAndReturn.

@Test
public void shouldFixTypesInMethodArgsAndReturn() throws Exception {
    setClassLoader(new SandboxClassLoader(createRemappingConfig()));
    Class<?> theClass = loadClass(AClassThatRefersToAForgettableClassInMethodCalls.class);
    assertNotNull(theClass.getDeclaredMethod("aMethod", int.class, loadClass(AClassToRemember.class), String.class));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) AnInstrumentedClassWithoutToStringWithSuperToString(org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString) AClassWithoutEqualsHashCodeToString(org.robolectric.testing.AClassWithoutEqualsHashCodeToString) AClassWithEqualsHashCodeToString(org.robolectric.testing.AClassWithEqualsHashCodeToString) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader) Test(org.junit.Test)

Example 13 with SandboxClassLoader

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

the class SandboxClassLoaderTest method shouldRemapClasses.

@Test
public void shouldRemapClasses() throws Exception {
    setClassLoader(new SandboxClassLoader(createRemappingConfig()));
    Class<?> theClass = loadClass(AClassThatRefersToAForgettableClass.class);
    assertEquals(loadClass(AClassToRemember.class), theClass.getField("someField").getType());
    assertEquals(Array.newInstance(loadClass(AClassToRemember.class), 0).getClass(), theClass.getField("someFields").getType());
}
Also used : AClassToRemember(org.robolectric.testing.AClassToRemember) SandboxClassLoader(org.robolectric.internal.bytecode.SandboxClassLoader) Test(org.junit.Test)

Aggregations

SandboxClassLoader (org.robolectric.internal.bytecode.SandboxClassLoader)13 Test (org.junit.Test)10 AnExampleClass (org.robolectric.testing.AnExampleClass)7 AnUninstrumentedClass (org.robolectric.testing.AnUninstrumentedClass)6 MethodRef (org.robolectric.internal.bytecode.MethodRef)5 AClassThatCallsAMethodReturningAForgettableClass (org.robolectric.testing.AClassThatCallsAMethodReturningAForgettableClass)5 AClassThatRefersToAForgettableClass (org.robolectric.testing.AClassThatRefersToAForgettableClass)5 AFinalClass (org.robolectric.testing.AFinalClass)5 InstrumentationConfiguration (org.robolectric.internal.bytecode.InstrumentationConfiguration)3 Method (java.lang.reflect.Method)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AClassToRemember (org.robolectric.testing.AClassToRemember)2 AClassWithEqualsHashCodeToString (org.robolectric.testing.AClassWithEqualsHashCodeToString)2 AClassWithNativeMethod (org.robolectric.testing.AClassWithNativeMethod)2 AClassWithStaticMethod (org.robolectric.testing.AClassWithStaticMethod)2 AClassWithoutEqualsHashCodeToString (org.robolectric.testing.AClassWithoutEqualsHashCodeToString)2 AnInstrumentedClassWithoutToStringWithSuperToString (org.robolectric.testing.AnInstrumentedClassWithoutToStringWithSuperToString)2 SwitchPoint (java.lang.invoke.SwitchPoint)1 Field (java.lang.reflect.Field)1 URLClassLoader (java.net.URLClassLoader)1