Hi there, I tried to mock one of my classes and got this error

1,779 views
Skip to first unread message

Connor Kolan

unread,
Mar 13, 2023, 9:49:38 AM3/13/23
to mockito
[ERROR] testRemoveContextFromInfomodell(unit.setter.KmsSetterTest)  Time elapsed: 1.988 s  <<< ERROR!
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.myCompany.kms.KmsConnector.
If you're not sure why you're getting this error, please report to the mailing list.
Java               : 17
JVM vendor name    : Eclipse Adoptium
JVM vendor version : 17.0.4+8
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 17.0.4+8
JVM info           : mixed mode, sharing
OS name            : Windows 10
OS version         : 10.0
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class com.MyCompany.kms.KmsConnector, class java.lang.Object]
at unit.setter.KmsSetterTest.testRemoveContextFromInfomodell(KmsSetterTest.java:46)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class   com.MyCompany.kms.KmsConnector, class java.lang.Object]
at unit.setter.KmsSetterTest.testRemoveContextFromInfomodell(KmsSetterTest.java:46)
Caused by: java.lang.IllegalStateException:
Byte Buddy could not instrument all classes within the mock's type hierarchy
This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
 - Compiled by older versions of scalac
 - Classes that are part of the Android distribution
at unit.setter.KmsSetterTest.testRemoveContextFromInfomodell(KmsSetterTest.java:46)
Caused by: java.lang.UnsupportedOperationException: This feature requires ASM7
at unit.setter.KmsSetterTest.testRemoveContextFromInfomodell(KmsSetterTest.java:46)

In the Pom I have:         
       <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-inline</artifactId>
            <version>5.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>5.2.0</version>
            <scope>test</scope>
       </dependency>

As I have the newest version of Mockito it should be compatible with java 17 and as far as I know mocking a custom class should be no problem. What exactly could be my problem here 
Reply all
Reply to author
Forward
0 new messages