简体   繁体   中英

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:

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. 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.

Any suggestions would be much appreciated.

For now, you can suppress this error using @SuppressWarnings("WrongConstant") for this specific test. It works fine, and keeps your production clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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