Skip to content

HTTPS clone URL

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.
.settings
sample-project
src
.fbprefs
README
pom.xml

README

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}\""
--

Dependencies.

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

that is:
test.with("#{ENV["JAVA_HOME"]}/lib/tools.jar")
or 
	<dependency>
	    <groupId>com.sun</groupId>
	    <artifactId>tools</artifactId>
	    <version>1.6.0</version>
	    <scope>system</scope>
		<systemPath>${java.home}/../lib/tools.jar</systemPath>
	</dependency>

I couldn't get the maven thing to work so well with surefire.  You may want to read:
http://maven.apache.org/plugins/maven-surefire-plugin/examples/class-loading.html
--

Ramblings.

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.

Blah.

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.