I am trying
MockIto
to mock Field class and when I try to do it as below.
I want my program to throw IllegalAccessException so that I can
test
the library ( that I am testing for my project).
//java.lang.reflect.Field
Field mockIT = Mockito.mock(Field.class);
Mockito.doThrow(new IllegalAccessException()).when(mockIT).getInt(String.class);
mockIT.getInt(str);
output:
Exception in
thread
"main" org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class java.lang.reflect.Field
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types
does any one know how can I mock the Final class