Over a million developers have joined DZone.

How to "Mock" Final Classes With Mockito

· Java Zone

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

 If you are using mockito, then you cannot "mock" final classes. But there is a nice library called JDave which does some bytecode, i.e. CGLIB, magic to change final classes to non-final classes.

Just download JDave, add the JAR files to the classpath, and start your test cases with the following VM option:

-javaagent:your-library-directory\jdave-unfinalizer-1.1.jar

 

The Java Zone is brought to you in partnership with JetBrains.  Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}