additional isEqualTo API #119

Open
kretes opened this Issue Oct 25, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@kretes

kretes commented Oct 25, 2012

It would be nice to have be able to write:

assertThat(someObject).isEqualOnFields(expectedObject,"id","name");
and
assertThat(someObject)..isEqualExcludingFields(expectedObject,"id","name")

which would under the hood use a comparator that is doing a reflection equals (similiar to the one in org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals ) only on specified fields.
There could be as well a reversed method

@joel-costigliola

This comment has been minimized.

Show comment Hide comment
@joel-costigliola

joel-costigliola Oct 25, 2012

Contributor

Have a look at lenient equals assertions, I think they'll do the job

// frodo and sam both are hobbits, so they are lenient equals on race
assertThat(frodo).isLenientEqualsToByAcceptingFields(sam, "race");
// Except name and age, frodo and sam both are hobbits, so they are lenient equals ignoring name and age
assertThat(frodo).isLenientEqualsToByIgnoringFields(sam, "name", "age");

examples from BasicAssertionsExamples.java in fest-examples project.

Contributor

joel-costigliola commented Oct 25, 2012

Have a look at lenient equals assertions, I think they'll do the job

// frodo and sam both are hobbits, so they are lenient equals on race
assertThat(frodo).isLenientEqualsToByAcceptingFields(sam, "race");
// Except name and age, frodo and sam both are hobbits, so they are lenient equals ignoring name and age
assertThat(frodo).isLenientEqualsToByIgnoringFields(sam, "name", "age");

examples from BasicAssertionsExamples.java in fest-examples project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment