Mockito Inline Fails with "Java.lang.ExceptionInitializerError"

3,329 views
Skip to first unread message

Daniel Connelly

unread,
Jul 6, 2020, 7:06:39 PM7/6/20
to mockito
I am trying to mock a project that uses final classes. I have tried to implement the solution for mocking final classes using the Mockito version "org.mockito:mockito-core:2.+". There are a few problems:

When I use the solution linked above, I get the error (see withResourcesFolder file):
java.lang.ExceptionInInitializerError

When I remove the solution, I get the original error ([ ] are my addition) (see withoutResourcesFolder):
Cannot mock/spy class [multiple classes cannot be mocked]
Mockito cannot mock/spy following:
  - final classes
  - anonymous classes
  - primitive types

I've also noticed that when I get this error the issue is not always that the class is final or an anonymous class or a primitive type... sometimes it is a class file that has a type `enum`. For example:
public enum RobotType {
...
}

I appreciate any help that anyone can offer.

Best,
Daniel
withResourcesFolder
withoutResourcesFolder

Daniel Connelly

unread,
Jul 19, 2020, 4:17:22 PM7/19/20
to mockito
I asked for help on GitHub issues page and received my answer: https://github.com/mockito/mockito/issues/1965#issuecomment-657279223
Reply all
Reply to author
Forward
0 new messages