Mockito: How to match any enum parameter
Apart from the above solution try this...
when(object.doThings((MyEnum)anyObject(), anyLong()).thenReturn(123L);
Matchers.any(Class)
will do the trick:
Mockito.when(object.doThings(Matchers.any(MyEnum.class), Matchers.anyLong()))
.thenReturn(123L);
null
will be excluded with Matchers.any(Class)
. If you want to include null
you must use the more generic Matchers.any()
.
As a side note: consider using Mockito
static imports:
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
Mocking gets a lot shorter:
when(object.doThings(any(MyEnum.class), anyLong())).thenReturn(123L);