In writing unit-tests I find myself constantly importing the wrong Status
package, resulting in some puzzling assertSame errors:
expected same:<See Other> was not:<See Other>
If one uses assertEquals, the assertion reveals a bit more:
expected: javax.ws.rs.core.Response$Status<See Other> but was:
com.sun.jersey.api.client.ClientResponse$Status<See Other>
I suppose one could always resort to comparing raw response codes, but it's
long and crude:
assertEquals(Status.SEE_OTHER.getStatusCode(),
response.getClientResponseStatus().getStatusCode());
Invoking equals manually on one of the Enum's makes for worse test output,
but at least my IDE (NetBeans) will flag it as a warning:
assertTrue(Status.SEE_OTHER.equals(response.getClientResponseStatus()));
The shortest type-safe way appears to be useing this idiom, though it
doesn't make for nice test failure messages:
assertTrue(Status.SEE_OTHER == response.getClientResponseStatus());
Is there a good reason for, in the same API, defining both
Enum<ClientResponse.Status> and Enum<Response.Status> which confuses humans
and IDE's? As an API consumer, It feels a little like the Enum's got a bit
too much responsibility and could benefit from composition instead. Or am I
missing something?
Sincerely,
Casper