I am in process of migrating my test cases to latest Robolectric 3.0. To test the viberator service in my app, earlier I used
org.robolectric.shadows.ShadowVibrator
but now I am not able to test it, even using custom shadow class.
Even the Robolectric wesite is not updated and it shows the use Robolectric.shadowOf_() which does not exist.
This is the link of the website, which is not updated version. Kindly guide.
Following is code for custom implementation:--
The custom class:--
@Implements(Vibrator.class)
public class ShadowVibrator {
private boolean vibrating;
private boolean cancelled;
private long milliseconds;
private long[] pattern;
private int repeat;
@Implementation
public void vibrate(long milliseconds) {
vibrating = true;
this.milliseconds = milliseconds;
}
@Implementation
public void vibrate(long[] pattern, int repeat) {
vibrating = true;
this.pattern = pattern;
this.repeat = repeat;
}
@Implementation
public void cancel() {
cancelled = true;
vibrating = false;
}
public boolean isVibrating() {
return vibrating;
}
public boolean isCancelled() {
return cancelled;
}
public long getMilliseconds() {
return milliseconds;
}
public long[] getPattern() {
return pattern;
}
public int getRepeat() {
return repeat;
}
}
And I want use in my code something like this , can someone point me correct API:--
ShadowVibrator shadowVibrator = Shadows.shadowOf((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE));
Have a look at RoboVibrator