Open houssemzaier opened 1 year ago
I faced same issue with mocking final class after updating mockito kotlin from 4.1.0 to 5.1.0. I mock class that has such hierarchy:
When I mock ImplClass
I got this error:
Mockito cannot mock this class: class ru.gibdd_pay.app.utils.experimentalFeatureManager.experiments.KaskoTabExperiment.
Can not mock final classes with the following settings :
- explicit serialization (e.g. withSettings().serializable())
- extra interfaces (e.g. withSettings().extraInterfaces(...))
When I mock BaseTypedClass<Type>
I got this error:
Mockito cannot mock this class: class ru.gibdd_pay.app.utils.experimentalFeatureManager.core.RemoteNewOldUsersExperiment.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java : 17
JVM vendor name : Amazon.com Inc.
JVM vendor version : 17.0.8.1+8-LTS
JVM name : OpenJDK 64-Bit Server VM
JVM version : 17.0.8.1+8-LTS
JVM info : mixed mode, sharing
OS name : Mac OS X
OS version : 13.5.2
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.
At the end of error message I saw this, seems it is a problem:
Mismatch of count of formal and actual type arguments in constructor of com.package.ImplClass$classField$1: 0 formal argument(s) 1 actual argument(s)
Successfully fixed this by explicitly specifying type of classField
. Before it just was initialized with anonymous object of type BaseClass
.
Mockito cannot mock this class: interface
Java : 21
JVM vendor name : Amazon.com Inc.
JVM vendor version : 21.0.2+13-LTS
JVM name : OpenJDK 64-Bit Server VM
JVM version : 21.0.2+13-LTS
JVM info : mixed mode, sharing
OS name : Mac OS X
OS version : 14.1.2
deps
'kotlinMockito' : "org.mockito.kotlin:mockito-kotlin:5.2.1",
'mockitoJupiter' : "org.mockito:mockito-junit-jupiter:5.10.0",
args
jvmArgs("-Dnet.bytebuddy.experimental=true")
Mockito cannot mock this class: class pl.inpost.recruitmenttask.presentation.shipmentList.Section$HasId.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java : 17 JVM vendor name : Amazon.com Inc. JVM vendor version : 17.0.8+7-LTS JVM name : OpenJDK 64-Bit Server VM JVM version : 17.0.8+7-LTS JVM info : mixed mode, sharing OS name : Windows 10 OS version : 10.0
and here's the class: