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 ability to specify what fields should make up equals() and hashCode() #128

Closed
anwarchk opened this issue Sep 10, 2015 · 6 comments
Closed
Labels

Comments

@anwarchk
Copy link

Just like EqualsVerifier.allFieldsShouldBeUsedExcept() , it would be nice to have EqualsVerifier.onlyTheseFields(String ...fieldNames). The limitation to the former is that, for a class with lot of fields, it's tedious to specify the exclusions.

@jqno
Copy link
Owner

jqno commented Sep 10, 2015

Just to clarify, what would be the difference between this, and simply
calling EqualsVerifier without any qualifiers?

On Thu, Sep 10, 2015 at 6:18 PM Anwar C [email protected] wrote:

Just like EqualsVerifier.allFieldsShouldBeUsedExcept() , it would be nice
to have EqualsVerifier.onlyTheseFields(String ...fieldNames). The
limitation to the former is that, for a class with lot of fields, it's
tedious to specify the exclusions.


Reply to this email directly or view it on GitHub
#128.

@anwarchk
Copy link
Author

In my use case, I use https://projectlombok.org/ annotations to add equals and hashCode. What I have been running into with the annotation is that , people use a blanket @EqualsAndHashCode annotations on classes without being explicit about the fields. My goal is, with the help of equalsverifier, to make sure that if we specify fields on the above specified annotation, only those are included in the equals and hashCode. Later on , if some one adds or removes a field, there better be a failing test. Hope it makes sense.

@jqno
Copy link
Owner

jqno commented Sep 10, 2015

Thanks for the clarification. So if I understand you correctly, you want to specify exactly which fields are used. Then if somebody adds a field without also adding it to the test, EV will fail, and if someone removes a field without also removing it from the test, EV will also fail.

I like that idea, and I'll probably add that in a future version. I'm currently working on a few big things so it probably won't be the next one, though. Probably the one after that.

@jqno jqno added the accepted label Sep 10, 2015
@anwarchk
Copy link
Author

Would you accept a PR for this feature ?

@jqno
Copy link
Owner

jqno commented Sep 10, 2015

Well, I would appreciate that very much :)!

However, you should know that I'm preparing a 2.0 version in the current master branch. One of the things I've already implemented there is issue #65, that makes allFieldsShouldBeUsed the default behavior. As you can imagine, things work differently from what you're used to. It will be a little while until I've finished up the whole version though (there's some other things I want to do as well). So the timing is a little bit unfortunate, I'm sorry!

If you don't mind all that, then I very much appreciate your PR, and I'll include it in the 2.0 release. Otherwise, I'll add it in 2.1.

@jqno
Copy link
Owner

jqno commented Mar 6, 2016

I've included this in version 2.0, which has just been released!

@jqno jqno closed this as completed Mar 6, 2016
jqno pushed a commit that referenced this issue Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants