If you'd like to do mockito style mocking, you should use that, Robolectric should play fine. Me personally? I'm not a fan of that style of testing, but that's just my opinion.
@Implementation
public static int getAudioSourceMax() {
return audioSourceMax;
}
/* non-Android setter */
public static void setAudioSourceMax(int audioSourceMax) {
this.audioSourceMax = audioSourceMax;
}
...
}
You'd need to set the value to be returned in your test's setup by invoking the method on the shadow.
@RunWith(WithTestDefaultsRunner.class)
public class MediaRecorderTest {
...
public void setUp() {
ShadowMediaRecorder.setAudioSourceMax(42);
}
public void testMaxAudio() {
assertThat(MediaRecorder.getAudioSourceMax(), equalTo(42));
}
}
One last thing to note here is that we're using the static. This will cause test pollution, so you need to do teardown. We make a point to do this type of cleanup in one place:
public class Robolectric {
...
public static void resetStaticState() {
...
ShadowMediaRecorder.reset();
}
...
}
--Tyler