EasyMock 2.5
By Henri Tremblay on Saturday, June 20 2009, 17:40 - Java - Permalink
I hope most you have noticed EasyMock 2.5 version is finally out. For this version I had two goals:
- Learn from my mistakes that prevented some users to upgrade to 2.4
- Implement a lots of great ideas that where submitted by you
You can have the complete release notes here (at the end. And yes, I should add anchors). However, I'll give some more details below.
Properties and thread-safety
EasyMock 2.4 had a feature called thread-safety check. Basically, it would return an error if the mock wasn't flagged as thread-safe and used in a multithreaded environment. The problem was that it was on by default. So someone with a lots of tests in a multithreaded environment will have them now failing. And he'll need to call makeThreadSafe() on all of them to repair.
The strange thing is that previously, EasyMock wasn't behaving really well in a threaded environments. So I would have expect these tests to have random failures anyway. But it seems I was wrong.
So I did two things. First, I've changed the default behavior. Mocks are now thread-safe by default and there's no thread-safety check. Then, if you don't like this default, you can use the new property system to change that. Hopefully, that should cover it all.
Capture
In EasyMock 2.4, the capture was having a very hard to guess behavior and was quite limited in capture types.
EasyMock 2.5 changed that. You should see the behavior everyone expect. A method is called, the parameter is captured. You can also decide to capture the first, the last or all parameters.
andDelegateTo
That was a neat idea (from virtualwarp). It allows to have something more typed than andAnswer. The drawback being that you have to implement an interface.
As a unexpected side effect, you can use this to create a Real objects spy
.
Error messages
On the Yahoo group, we keep receiving questions about why a given example is failing. Big sign that the error messages were not that clear. One of the worst was the +1 on an unexpected call. I've worked on it (with Tammo insights) to improve some and to refine some others. For instance the unexpected call message now depends on the number of possibles matches to have a more meaningful message.
OSGi
The great thing when you're working on a framework like EasyMock is that people are asking you things about stuff you don't know. For instance, I never had the time to use an OSGi framework. Banks still love classic application servers. However, I always thought that OSGi seemed like a good idea to improve development times. Application servers take ages to launch and deploy.
But someone asked me to have EasyMock being an OSGi bundle. So I was forced to learn. After some reading (mainly the official specification), I managed to get started.
The maven-bundle-plugin and Spring OSGi test framework did the rest. This is interesting enough to worth its own post.
EasyMock 2.5 is now an OSGi bundle.


Comments
Awesome, I was dancing around the Capture limitations but it works beautifully now!
One thing I can't seem to figure out is why there is no easymock classextensions 2.5... do you happen to know the reason?
It's not finished yet. But the 2.4 version is compatible. Should be out at the end of this year.