Robolectric 3.0 测试振动器服务

Robolectric 3.0 testing Vibrator service

我正在将我的测试用例迁移到最新的 Robolectric 3.0。 为了在我的应用程序中测试振动器服务,之前我使用了

org.robolectric.shadows.ShadowVibrator

但现在我无法测试它,即使使用自定义阴影 class。

甚至 Robolectric 网站也没有更新,它显示了不存在的 Robolectric.shadowOf_() 用法。

This是网站的link,不是更新版本。请指导。

以下是自定义实现的代码:--

自定义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;
    }
}

我想在我的代码中使用这样的东西,有人能指出我正确的地方吗API:--

ShadowVibrator shadowVibrator = Shadows.shadowOf((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE));

看看 RoboVibrator

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