1package org.robolectric;
2
3import static org.junit.Assert.assertEquals;
4
5import org.junit.Test;
6import org.junit.runner.RunWith;
7import org.robolectric.annotation.Implements;
8import org.robolectric.annotation.RealObject;
9import org.robolectric.annotation.internal.Instrument;
10import org.robolectric.internal.SandboxTestRunner;
11import org.robolectric.internal.bytecode.SandboxConfig;
12
13@RunWith(SandboxTestRunner.class)
14public class ClassicSuperHandlingTest {
15  @Test
16  @SandboxConfig(shadows = {ChildShadow.class, ParentShadow.class, GrandparentShadow.class})
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})
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
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
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
51    public String method(String value) {
52      return "1s-" + value;
53    }
54  }
55
56  private static class BabiesHavingBabies extends Child {
57    @Override
58    public String method(String value) {
59      return "4-" + super.method(value);
60    }
61  }
62
63  @Instrument
64  public static class Child extends Parent {
65    @Override public String method(String value) {
66      throw new RuntimeException("Stub!");
67    }
68  }
69
70  @Instrument
71  public static class Parent extends Grandparent {
72    @Override public String method(String value) {
73      throw new RuntimeException("Stub!");
74    }
75  }
76
77  @Instrument
78  private static class Grandparent {
79    public String method(String value) {
80      throw new RuntimeException("Stub!");
81    }
82  }
83}
84