The idea came to me one day after I realized that I spent too much time creating the proper mock objects. Since we needed to have many variations of this object in order to do Unit testing (technically integration), the testing helper classes have evolved. They have evolved to a point where a method would create one type of object, another method would create another type, and so forth.
The methods began to have params in them to help and reuse the code, but at some point it just became to unwieldy and took up hours of my time just to create a proper mock.
Since I have been using Groovy lately, I thought about how easy it is to create complex hierarchical structures using Groovy's builder pattern. I began looking at Groovy for the answer and how to construct my own kind of builder for our domain.
I realized that it will take some time to familiarize myself with what needed to happen and it may have become not an easy task.
I then looked to the more familiar Java's style of Builders and ended up creating a Builder class per each domain class. This actually ended up working out really well and now all it takes to create a mock object is a few minutes.
If you'd like to see it in action, please visit my posting here: