question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with mocking type in "java.util.*", Java 12

See original GitHub issue

After 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:closed
  • Created 5 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
TimvdLippecommented, Feb 18, 2019

Mockito 2.24.5 should be available on Maven central later today.

0reactions
sormurascommented, Feb 18, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found