View Post
Development

Unit Testing Servlets Using Jetty

Jetty is a very lightweight servlet container, it starts up in just a handful of milliseconds, and easily allows you to unit test your HTTP Servlets.

Unfortunately, the Jetty API isn’t that easy to navigate. Here is a ServletRunner that will start up a Jetty container, and some useful stuff that is easy to integrate into your unit tests to test the servlets.

View Post
Development

Double Brace Initialization

Double brace initialization in Java is a great way to work around APIs that require loads of calls to setters to initialize initial object state.

I needed to create an ATOM feed, and found the ROME jar. This seemed to meet my needs, but I didn’t like the example code.

View Post
Development

Announcer

When registering event listeners it seems that there are many different and duplicate implementations of iterating over the listeners and broadcasting your event. This broadcaster takes the strain out of many uses of this pattern, by reflectively calling the notification method(s) on all registered listeners.

View Post
Development

Microtypes

Passing Strings and doubles around in an application can significantly increase the likelihood of inadvertantly passing incorrect parameters to methods. By strongly typing all string and number parameter types, this can be simply avoided. Its then also possible to add behaviour to these types, meaning that “utility” classes are removed, keeping behaviour close to the objects that need it.