Trying to mock a method with int parameter but Mockito fails

Viewed 123

I want to simulate the response of the following method:

public JobResult getJobResult(String jobId, int pageSize, String cursor)

The following way:

when(analyticsApi.getJobResult(any(), any(), any())).thenReturn(jobResult);

But Mockito fails with the following error:

java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.mockito.ArgumentMatchers.any()" is null

1 Answers

Turns out you cannot put any() on int parameters, so you have to mock it the following way:

when(analyticsApi.getJobResult(any(), anyInt(), any())).thenReturn(jobResult);
Related