簡體   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