繁体   English   中英

结合使用Mockito Matchers.any()和android.support.annotation.IntDef自定义注释

[英]Using Mockito Matchers.any() with android.support.annotation.IntDef custom annotation

我正在尝试编写一个Junit测试,它将验证是否调用了以下方法:

public long executeRequest(@RequestCodes.Code.RequestAnnotation int requestCode, Object requestInformation, RequestListener requestListener) {

    boolean success = false;

    ... do stuff ...

    return success ? 1L : -1L;

}

在测试中使用:

Mockito.when(mockedRequest.executeRequest(Matchers.any(RequestCodes.Code.RequestAnnotation.class), Matchers.any(RequestWrapper.class), Matchers.any(RequestListener.class))).thenReturn(1L);

RequestCodes.Code.RequestAnnotation类是使用int标识使用开关进行的调用的基本indef接口。 很像这样

Matchers.any(RequestCodes.Code.RequestAnnotation.class)在这里不起作用,我已经尝试过Matchers.any()Matchers.anyInt()Matchers.isA(RequestCodes.Code.RequestAnnotation.getClass()) (以及以及其他任何想到的东西)都没有成功。

任何建议将不胜感激。

现在,您可以使用@SuppressWarnings("WrongConstant")对此特定测试消除此错误。 它工作正常,并保持生产清洁。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM