Reputation: 2520
I have an integration test that checks the content type of a response as follows
Header header = new BasicHeader("Content-Type", "application/octet-stream; charset=UTF-8");
assertThat(response.getEntity().getContentType(), Matchers.is(header));
The test fails asserting that the response is same like the pre-built header with this odd message
Expected: is <Content-Type: application/octet-stream; charset=UTF-8>
but: was <Content-Type: application/octet-stream; charset=UTF-8>
My hunch is that since we are speaking of two objects, we are speaking of two different instances. for this I have also tried
assertThat(response.getEntity().getContentType(), Matchers.equalTo(header));
But the results were the same.
Any idea of what I'm doing wrong ?
Upvotes: 0
Views: 569
Reputation: 1332
Given the equals method is failing on you, an alternative would be to use the reflection equality ignoring the fields that are causing the problem with the equals method
org.mockito.Matchers.refEq(object,[list of fields to ignore])
Upvotes: 1
Reputation: 14520
it means that toString
of those two objects give the same results but those objects are different in terms of equals
method. maybe they have even different classes
Upvotes: 1