I’m more excited about learning Scala, but some Java experiences I had last week:

  • I was making some changes to a third-party library that was already using mockito in its unit tests, so I decided to give it a try. And, after a half-day of experiences, I will tentatively declare myself to be a fan. My previous mocking experience was with jMock, and while jMock may work as well for code that was written in a GOOS style from the beginning, I really appreciated the fact that mockito didn’t insist on tracing every single application; its willingness to mock classes by default was useful in the context of the work I was doing as well. And I liked not having to go to the extra weight of subclassing Expectations in every single test. So I recommend that anybody programming in Java who is curious about mocking but is worried about what it will involve should give mockito a try: it’s remarkably light-weight and pleasant.
  • I wanted to add a polling thread wrapper around a metrics class that I’d written, and rather than do that by hand, I decided to look into Java’s reflection / dynamic proxies facility. And wow, writing a dynamic proxy in Java is easy! Maybe it’s not quite as trivial as overloading method_missing, but it’s only a little bit more work than that: I had a proxy up and running in a handful of minutes, and it was doing everything I wanted only took an hour or so. (And the vast majority of my code was talking about threads and caching, which is exactly what I wanted it to be talking about.) So score one for Java.

Post Revisions:

This post has not been revised since publication.