You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the Quarkus Mockito dependency as-is I cannot mock a final class because it also includes a dependency to mockito-subclass. Mockito can mock final classes, but with this mock maker it can not (see Mockito issue referenced above).
I am not sure why the Mockito-subclass dependency is used, it might have a purpose or be needed on older JVMs. So I'm not sure what the side effects of the fix are.
Dependencies
Mockito 5.14.2 through Quarkus Mockito 3.17.2
Expected behavior
Final classes can be mocked (as Mockito supports that)
Actual behavior
We see an error when running the test.
[ERROR] IssueTest.issue -- Time elapsed: 0.159 s <<< ERROR!
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class java.lang.reflect.Method
Mockito cannot mock/spy because :
- final class
at IssueTest.issue(IssueTest.java:12)
@Testvoidissue() {
vargood = mock(IssueTest.class); // works fine regardlessvarerror = mock(Method.class); // generates error if mockito-subclass is included
}
Output of uname -a or ver
Darwin Mac.lan 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031 arm64
This issue can be fixed by changing the pom, as suggested in the Mockito issue where it was originally filed.
I do not know whether that would break something different on older JVMs.
I am not sure why the Mockito-subclass dependency is used, it might have a purpose or be needed on older JVMs. So I'm not sure what the side effects of the fix are.
Describe the bug
Reference:
Description
Using the Quarkus Mockito dependency as-is I cannot mock a final class because it also includes a dependency to
mockito-subclass
. Mockito can mock final classes, but with this mock maker it can not (see Mockito issue referenced above).I am not sure why the
Mockito-subclass
dependency is used, it might have a purpose or be needed on older JVMs. So I'm not sure what the side effects of the fix are.Dependencies
Expected behavior
Final classes can be mocked (as Mockito supports that)
Actual behavior
We see an error when running the test.
How to Reproduce?
Full code on example project: https://github.com/lwiddershoven/mockito-issue
Run
mvn clean test
Relevant parts of the dependencies:
pom.xml (broken)
Output of
uname -a
orver
Darwin Mac.lan 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031 arm64
Output of
java -version
JVM OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
Quarkus version or git rev
3.17.2
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d26018693
Additional information
This issue can be fixed by changing the pom, as suggested in the Mockito issue where it was originally filed.
I do not know whether that would break something different on older JVMs.
(Also - if mockito is being looked at - do consider looking at https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#mockito-instrumentation and updating the maven-dependency-plugin and maven-surefire-plugin config to get rid of some of the warning messages that keep popping up.)
pom.xml (fixed)
The text was updated successfully, but these errors were encountered: