简体   繁体   English

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

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

I am trying to write a Junit test which will verify whether the following method is called: 我正在尝试编写一个Junit测试,它将验证是否调用了以下方法:

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

    boolean success = false;

    ... do stuff ...

    return success ? 1L : -1L;

}

in a test using: 在测试中使用:

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

The RequestCodes.Code.RequestAnnotation class is a elementary indef interface using an int to identify the call to make using a switch. RequestCodes.Code.RequestAnnotation类是使用int标识使用开关进行的调用的基本indef接口。 Pretty much like this . 很像这样

Matchers.any(RequestCodes.Code.RequestAnnotation.class) won't work here and I have tried Matchers.any() , Matchers.anyInt() , Matchers.isA(RequestCodes.Code.RequestAnnotation.getClass()) (as well as anything else that came to mind) with no success. Matchers.any(RequestCodes.Code.RequestAnnotation.class)在这里不起作用,我已经尝试过Matchers.any()Matchers.anyInt()Matchers.isA(RequestCodes.Code.RequestAnnotation.getClass()) (以及以及其他任何想到的东西)都没有成功。

Any suggestions would be much appreciated. 任何建议将不胜感激。

For now, you can suppress this error using @SuppressWarnings("WrongConstant") for this specific test. 现在,您可以使用@SuppressWarnings("WrongConstant")对此特定测试消除此错误。 It works fine, and keeps your production clean. 它工作正常,并保持生产清洁。

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

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