Test Drive Robolectric 3.0 Vibrator

I am transferring my test cases to the latest Robolectric 3.0. To test the viberator service in my application, I previously used

org.robolectric.shadows.ShadowVibrator 

but now I can’t test it, even using my own shadow class.

Even Robolectric wesite is not updated, and it shows that Robolectric.shadowOf_ () does not exist.

This is a link to a website that is not being updated. Kindly guide.

Below is the code for a custom implementation: -

User 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 to use something like this in my code, can someone tell me the correct API: -

 ShadowVibrator shadowVibrator = Shadows.shadowOf((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)); 
0
source share
1 answer

Take a look at RoboVibrator

 RoboVibrator vibrator = (RoboVibrator) RuntimeEnvironment.application.getSystemService(Context.VIBRATOR_SERVICE); 
+2
source

All Articles