mardi 27 novembre 2018

What is the best way to test a factory/builder producing third party objects that lack a good equality?

As an example; I'm working on a builder to produce Apache HttpUriRequests.

My test is as follows:

@Test
public void testRequestGet() {
    HttpUriRequest request = RequestBuilder.request("http://www.google.com").get();

    assertEquals(new HttpGet("http://www.google.com"), request);
}

This fails, apparently because HttpGet does not have #equals defined, and so defaults to Object#equals.

I could manually test the equality of all the components of the produced HttpGet to verify they are what I expect- which is easy now, but will likely get ugly once headers, parameters, etc start getting involved (plus the additional noise that testing HttpEntity will pose once I add #post() to the builder).

Before going down that route, I thought I'd ask if there's a better approach to this general category of problem.

Aucun commentaire:

Enregistrer un commentaire