Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subject.hasHashCode(int) and Subject.hasToString(String) #150

Closed
PhilippWendler opened this issue Nov 8, 2014 · 2 comments
Closed

Comments

@PhilippWendler
Copy link

Sometimes the hashCode() of a class implementing an interface is important and should be tested (for example for collections, Map.Entry). In such cases it would be nice to have Subject.hasHashCode() instead of having to write assertThat(obj.hashCode()).isEqualTo(h) because the former could provide a better failure message including the value of obj.toString().

@kluever
Copy link
Member

kluever commented Nov 8, 2014

If we add this, we'd also probably want to add:
Subject.hasToString(String)

@kluever kluever changed the title Add Subject.hasHashCode(int) Add Subject.hasHashCode(int) and Subject.hasToString(String) Nov 8, 2014
@kluever
Copy link
Member

kluever commented Dec 2, 2014

We discussed this pretty extensively, and we're deciding to not take any action here.

All of the assertions about hashcodes we could find inside of google, were of the form:
assertEquals(a.hashCode(), b.hashCode());

These use cases are much better supported by Guava's EqualsTester:
https://code.google.com/p/guava-libraries/source/browse/guava-testlib/src/com/google/common/testing/EqualsTester.java

@kluever kluever closed this as completed Dec 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants