Skip to content

InjectMocks and Spy annotations are no more working in Java 17 #2449

@balajikrb

Description

@balajikrb

I have been using InjectMocks and Spy annotations of mockito for the purpose mocking my objects and it used to work fine. I recently migrated to Java 17 and I am getting "InaccessibleObjectException" for the same test case which used to work in Java 16. On checking more about the same I found that illegal-access flag has been deprecated in java 17 and due to which I am getting this exception.

com.balaji.MyClassTest > calculateTest FAILED
java.lang.ExceptionInInitializerError at MyClassTest.java:57
Caused by: java.lang.reflect.InaccessibleObjectException at MyClassTest.java:57

Is there any alternative way to achieve the similar functionalities of InjectMocks and Spy in mockito ?

Details:
Mockito version: org.mockito:mockito-core:3.9.0
Gradle version: 7.3-rc.1
Java version: 17

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions