1 package org.robolectric; 2 3 import static org.junit.Assert.assertEquals; 4 5 import org.junit.Test; 6 import org.junit.runner.RunWith; 7 import org.robolectric.annotation.Implements; 8 import org.robolectric.annotation.internal.Instrument; 9 import org.robolectric.internal.SandboxTestRunner; 10 import org.robolectric.internal.bytecode.SandboxConfig; 11 import org.robolectric.testing.Pony; 12 13 @RunWith(SandboxTestRunner.class) 14 public class RealApisTest { 15 @Test 16 @SandboxConfig(shadows = {ShimmeryShadowPony.class}) whenShadowHandlerIsInRealityBasedMode_shouldNotCallRealForUnshadowedMethod()17 public void whenShadowHandlerIsInRealityBasedMode_shouldNotCallRealForUnshadowedMethod() throws Exception { 18 assertEquals("Off I saunter to the salon!", new Pony().saunter("the salon")); 19 } 20 21 @Implements(Pony.class) 22 public static class ShimmeryShadowPony extends Pony.ShadowPony { 23 } 24 25 @Test 26 @SandboxConfig(shadows = {ShadowOfClassWithSomeConstructors.class}) shouldCallOriginalConstructorBodySomehow()27 public void shouldCallOriginalConstructorBodySomehow() throws Exception { 28 ClassWithSomeConstructors o = new ClassWithSomeConstructors("my name"); 29 assertEquals("my name", o.name); 30 } 31 32 @Instrument 33 public static class ClassWithSomeConstructors { 34 public String name; 35 ClassWithSomeConstructors(String name)36 public ClassWithSomeConstructors(String name) { 37 this.name = name; 38 } 39 } 40 41 @Implements(ClassWithSomeConstructors.class) 42 public static class ShadowOfClassWithSomeConstructors { 43 } 44 } 45