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.RealObject;
9 import org.robolectric.annotation.internal.Instrument;
10 import org.robolectric.internal.SandboxTestRunner;
11 import org.robolectric.internal.bytecode.SandboxConfig;
12 
13 @RunWith(SandboxTestRunner.class)
14 public class ClassicSuperHandlingTest {
15   @Test
16   @SandboxConfig(shadows = {ChildShadow.class, ParentShadow.class, GrandparentShadow.class})
uninstrumentedSubclassesShouldBeAbleToCallSuperWithoutLooping()17   public void uninstrumentedSubclassesShouldBeAbleToCallSuperWithoutLooping() throws Exception {
18     assertEquals("4-3s-2s-1s-boof", new BabiesHavingBabies().method("boof"));
19   }
20 
21   @Test
22   @SandboxConfig(shadows = {ChildShadow.class, ParentShadow.class, GrandparentShadow.class})
shadowInvocationWhenAllAreShadowed()23   public void shadowInvocationWhenAllAreShadowed() throws Exception {
24     assertEquals("3s-2s-1s-boof", new Child().method("boof"));
25     assertEquals("2s-1s-boof", new Parent().method("boof"));
26     assertEquals("1s-boof", new Grandparent().method("boof"));
27   }
28 
29   @Implements(Child.class)
30   public static class ChildShadow extends ParentShadow {
31     private @RealObject Child realObject;
32 
method(String value)33     @Override public String method(String value) {
34       return "3s-" + super.method(value);
35     }
36   }
37 
38   @Implements(Parent.class)
39   public static class ParentShadow extends GrandparentShadow {
40     private @RealObject Parent realObject;
41 
method(String value)42     @Override public String method(String value) {
43       return "2s-" + super.method(value);
44     }
45   }
46 
47   @Implements(Grandparent.class)
48   public static class GrandparentShadow {
49     private @RealObject Grandparent realObject;
50 
method(String value)51     public String method(String value) {
52       return "1s-" + value;
53     }
54   }
55 
56   private static class BabiesHavingBabies extends Child {
57     @Override
method(String value)58     public String method(String value) {
59       return "4-" + super.method(value);
60     }
61   }
62 
63   @Instrument
64   public static class Child extends Parent {
method(String value)65     @Override public String method(String value) {
66       throw new RuntimeException("Stub!");
67     }
68   }
69 
70   @Instrument
71   public static class Parent extends Grandparent {
method(String value)72     @Override public String method(String value) {
73       throw new RuntimeException("Stub!");
74     }
75   }
76 
77   @Instrument
78   private static class Grandparent {
method(String value)79     public String method(String value) {
80       throw new RuntimeException("Stub!");
81     }
82   }
83 }
84