I'm trying to shadow the Camera.Size object. This is a non-static inner class on Camera.
It contains only public fields and a constructor, so I attempted to shadow the constructor like so:
@Implements(Camera.Size.class)
public class ShadowCameraSize {
@RealObject private Camera.Size realCameraSize;
public void __constructor__(int width, int height) {
realCameraSize.width = width;
realCameraSize.height = height;
}
}
And here's a bit of code I used to test the constructor:
@Before
public void setUp() throws Exception {
Robolectric.bindDefaultShadowClasses();
cameraSize = Robolectric.newInstanceOf(Camera.class).new Size(480, 320);
}
@Test
public void testConstructor() throws Exception {
assertThat(cameraSize.width, equalTo(480));
assertThat(cameraSize.height, equalTo(320));
}
I'm seeing two problems when I run the tests:
1) The constructor is never being invoked, so width/height are both zero and the test fails.
2) The Robolectric wiring test fails, because it cannot match the __constructor__ up with the real class constructor:
testAllImplementationMethodsHaveCorrectSignature(com.xtremelabs.robolectric.bytecode.RobolectricWiringTest) Time elapsed: 0.26 sec <<< FAILURE!
java.lang.AssertionError: @Implementation method mismatch: public void com.xtremelabs.robolectric.shadows.ShadowCameraSize.__constructor__(int,int) doesn't match a real method expected:<0> but was:<1>
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.failNotEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:126)
at org.junit.Assert.assertEquals(Assert.java:470)
at com.xtremelabs.robolectric.bytecode.RobolectricWiringTest.testAllImplementationMethodsHaveCorrectSignature(RobolectricWiringTest.java:30)
Can someone help me understand what I'm doing wrong here?
I'd like to send a pull request, and this is the biggest thing standing in the way.
Thanks,
M.