gpt4 book ai didi

android - 将 Mockito Matchers.any() 与 android.support.annotation.IntDef 自定义注释一起使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:44 25 4
gpt4 key购买 nike

我正在尝试编写一个 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 类是一个基本的 indef 接口(interface),它使用一个 int 来标识要使用开关进行的调用。很像 this .

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

如有任何建议,我们将不胜感激。

最佳答案

目前,您可以针对此特定测试使用 @SuppressWarnings("WrongConstant") 来抑制此错误。它运行良好,并使您的作品保持清洁。

关于android - 将 Mockito Matchers.any() 与 android.support.annotation.IntDef 自定义注释一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38721699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com