A Friend Rediscovered - MockRunner

Life is funny. You meet a new friend, hit it off immediately and then slowly you drift away. One day you realize, “Hey, I haven’t seen my super cool friend Bob lately, what ever happened to that guy?”

I realized last night that my “super cool” friend MockRunner had gone missing. We first met a few years back when I was building a prototype of something that we ended up not running with. StrutsTestCase was a one of my favorite testing tools, allowing for true out-of-container testing that made life great for Struts fans. However, there were cases where I needed the ability to mock those beasts known as HttpServletRequest and HttpSession with ease.

Bacon and I are busy working on some new top3Clicks features and I needed to create unit tests that easily created mocks of request objects. A bit of searching reminded me of my old friend MockRunner. In a few mins, I cranked out unit tests (of course verifying the code coverage with Clover) that looked something like this:

public void testBuildListBeans() {
    String query = "U2";
    String productGroupID = "23";
    String error = "Invalid value found";
    ValidateListAction vla = new ValidateListAction();
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setupAddParameter("searchInput", query);
    mockRequest.setupAddParameter("productGroupID", productGroupID);
    List<ListBean> listBean = vla.buildListBeans(mockRequest);
    ListBean lb = listBean.get(0);
    assertEquals(error,query,lb.getInputText());
}

Pure Goodness.