Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


So you want to mock finals?
Now you can.

Step 1.  Call Unfinalizer.unfinalize(); in your tests before any of the classes containing finals are loaded.

Contacting me: Please send any comments to tuomas dot karkkainen at ri dot fi.
I would love to know if anyone is able to use this.

Step 2.  When running in your build tool, and the forking mode is such that several test classes
are run in the same jvm one after another, you must take care to run unfinalize() before anyone uses
the classes with finals in them.

The sample project demonstrates the problem and a fix.  
AardvarkTest is run before AcceptanceTest and uses AClass which is final.  
AcceptanceTest can no longer unfinalize it.  

To fix this, load unfinalizer in the build tool as an old fashioned agent:

ENV["JAVA_OPTIONS"] += "-javaagent:\"#{Artifact::lookup("org.jdave:jdave-unfinalizer:jar:#{jdave_version}").to_s}\""


The only runtime dependency is tools.jar from your jdk.

that is:

I couldn't get the maven thing to work so well with surefire.  You may want to read:


The previous version, with Java 5, required some -javaagent: stuff and in general was not very usable.  
You had to make sure your build tool did the same thing as your IDE, 
you had to include tools.jar from the jdk's lib dir,
you had to make sure everyone's IDE did the same as yours.
In your ide, you maybe needed to add the -javaagent stuff to every single test class.


Java 6 attach to the rescue.  
In short, VirtualMachine.attach() allows you to add agents programmatically after the JVM has been started.

If you like that, you may want to try the netbeans 6.5 profiler with dynamic attach.

Something went wrong with that request. Please try again.