Issue with mocking type in "java.util.*", Java 12
See original GitHub issueAfter upgrading Mockito from 2.23.4
to 2.24.0
we can’t run JUnit 5’s tests anymore. The error message reads:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface java.util.concurrent.locks.Lock.
Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
Find the complete stacktrace here: https://travis-ci.org/junit-team/junit5/jobs/488684907
Note, that using Mockito 2.24.0
using Java 11 (and 13 locally) did work out! See this build matrix: https://travis-ci.org/junit-team/junit5/builds/488684905
Workaround: revert to Mockito 2.23.4
for the time being via https://github.com/junit-team/junit5/commit/754f1eb0f106ab043d79de546d49769690a731b6
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Mockito cannot mock this class - java - Stack Overflow
Using Java 11, I solved this issue by including the following dependency in build.gradle : compile group: 'org.mockito', name: 'mockito-core', ...
Read more >Mockito (Mockito 4.3.1 API) - javadoc.io
Mockito verifies argument values in natural java style: by using an equals() method. This is also the recommended way of matching arguments because...
Read more >[JDK-8228462] Unit test crash on method call to mock
A DESCRIPTION OF THE PROBLEM : When running a method on a mocked object, the JVM crashed. ... Metaspace: Usage: Non-class: 13.59 MB...
Read more >Unit tests with Mockito - Tutorial - Vogella.com
Using Mockito for mocking objects in unit tests. 3. Adding Mockito to a project ... For further information about testing with Java see:....
Read more >How to Fix A "Mockito cannot mock this class" Exception in A ...
How to fix a MockBean error on a CrudRepository interface in a Spring Boot app using Java 11. Tagged with java, springboot, mockito....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mockito 2.24.5 should be available on Maven central later today.
Looks good on 12: https://travis-ci.org/junit-team/junit5/jobs/495011557