Hello everyone,
I just started to migrate our application from axon 10 to axon 12.
So far everything works good except some of our unittests. We use mockito to mock some DAO classes that are derived from AuditableDAO (from persistence utils). Just now my maven build tells me that mockito cannot mock these DAO classes as there is a problem with the compile version of some classes (see code below).
I understand that axon 12 needs java 21 to compile, but persistence utils are compiled for java19, is that correct? As a result mockito does have a problem when mocking such classes. Is there any mistake in my side or anything I don't see and need to adjust?
Our current setup:
axon ivy 12.0.15
persistence utils 12.0.3
org.mockito.mockito-inline 5.2.0
Java version: 21.0.2, vendor: Oracle Corporation,
maven.compiler.target 21
`[ERROR] de.esg.imst.core.service.ProjectImportServiceTest.testTakeoverRiskFromInitiative -- Time elapsed: 0.165 s <<< ERROR!
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class de.imst.core.daos.ProjectDAO.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java : 21
JVM vendor name : Oracle Corporation
JVM vendor version : 21.0.2+13-58
JVM name : OpenJDK 64-Bit Server VM
JVM version : 21.0.2+13-58
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.axonivy.utils.persistence.dao.AuditableIdDAO, class com.axonivy.utils.persistence.dao.Gener
icDAO, class com.axonivy.utils.persistence.dao.AbstractDAO, class java.lang.Object, class de.imst.core.daos.ProjectDAO, class de.imst.core.daos.BaseIdDAO, class com.axonivy.utils.persistenc
e.dao.AuditableDAO, interface de.imst.core.daos.BaseDAO, interface com.axonivy.utils.persistence.dao.BaseDAO]
at de.imst.core.service.ProjectImportServiceTest.testTakeoverRiskFromInitiative(ProjectImportServiceTest.java:1121)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at ch.ivyteam.ivy.server.internal.test.AbstractScopeContext.proceed(AbstractScopeContext.java:12)
at ch.ivyteam.ivy.server.internal.test.AbstractScopeContext.callInScopeContext(AbstractScopeContext.java:7)
at ch.ivyteam.ivy.environment.internal.IvyTestScopeContext.lambda$0(IvyTestScopeContext.java:35)
at ch.ivyteam.util.callable.AbstractExecutionContext.callInContext(AbstractExecutionContext.java:10)
at ch.ivyteam.ivy.request.impl.RequestResponseContext.lambda$0(RequestResponseContext.java:21)
at ch.ivyteam.util.callable.AbstractExecutionContext.callInContext(AbstractExecutionContext.java:10)
at ch.ivyteam.ivy.request.impl.RequestResponseContext.callInContext(RequestResponseContext.java:20)
at ch.ivyteam.ivy.environment.internal.IvyTestScopeContext.callInScopeContext(IvyTestScopeContext.java:35)
at ch.ivyteam.ivy.server.internal.test.AbstractTestJu5Ext.callInContext(AbstractTestJu5Ext.java:122)
at ch.ivyteam.ivy.server.internal.test.AbstractTestJu5Ext.interceptTestMethod(AbstractTestJu5Ext.java:109)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class com.axonivy.utils.persistence.dao.AuditableIdDAO, class com.axonivy.utils.persistence.dao.GenericDAO, class
com.axonivy.utils.persistence.dao.AbstractDAO, class java.lang.Object, class de.imst.core.daos.ProjectDAO, class de.imst.core.daos.BaseIdDAO, class com.axonivy.utils.persistence.dao.Audita
bleDAO, interface de.imst.core.daos.BaseDAO, interface com.axonivy.utils.persistence.dao.BaseDAO]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:153)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:366)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:175)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:377)
... 14 more
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 org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:285)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.mockClass(InlineBytecodeGenerator.java:218)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.lambda$mockClass$0(TypeCachingBytecodeGenerator.java:47)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:153)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:366)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:175)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:377)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40)
at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.createMockType(InlineDelegateByteBuddyMockMaker.java:396)
at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.doCreateMock(InlineDelegateByteBuddyMockMaker.java:355)
at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.createMock(InlineDelegateByteBuddyMockMaker.java:334)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMock(InlineByteBuddyMockMaker.java:56)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:99)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:88)
at org.mockito.Mockito.mock(Mockito.java:2087)
at org.mockito.Mockito.mock(Mockito.java:2002)
... 14 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 65
at net.bytebuddy.jar.asm.ClassReader.<init>(ClassReader.java:199)
at net.bytebuddy.jar.asm.ClassReader.<init>(ClassReader.java:180)
at net.bytebuddy.jar.asm.ClassReader.<init>(ClassReader.java:166)
at net.bytebuddy.utility.OpenedClassReader.of(OpenedClassReader.java:99)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:3916)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:2193)
at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:224)
at net.bytebuddy.dynamic.scaffold.inline.AbstractInliningDynamicTypeBuilder.make(AbstractInliningDynamicTypeBuilder.java:123)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3658)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.transform(InlineBytecodeGenerator.java:402)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:244)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:610)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:225)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:281)
... 29 more
`
Thanks for any hints on how to solve that issue,
Greets Alex