benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Add optional Comparator to methods that otherwise use equals() #148

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes I'm interested in comparing objects using a custom comparator
instead of using the default equals() method definitions. For example, I
have a list of invoices and I want to make sure there isn't more than one
invoice with the same date.

I can't use the doesNotHaveDuplicates() method since that uses the equals()
method on the objects. I'd like to use something like

assertThat(firstInvoiceList)
  .doesNotHaveDuplicates(DATE_COMPARATOR);

where DATE_COMPARATOR compares the two invoices just by the date on each.

This would also apply to methods such as isEqualTo(), so that I can say:

assertThat(firstInvoiceList)
  .isEqualTo(PAYEE_COMPARATOR, secondInvoiceList);

that would make sure that the two lists are equal, but only paying
attention to the Payee property for each. An alternative would be:

assertThat(firstInvoiceList)
  .using(PAYEE_COMPARATOR)
  .isEqualTo(secondInvoiceList);

But that would make it difficult to combine my prior duplicate assert with
this one, e.g.:

assertThat(firstInvoiceList)
  .doesNotHaveDuplicates(DATE_COMPARATOR)
  .isEqualTo(PAYEE_COMPARATOR, secondInvoiceList);

Original issue reported on code.google.com by tedyo...@gmail.com on 10 Jun 2008 at 12:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Issue migrated to http://jira.codehaus.org/browse/FEST-64

Original comment by Alex.Rui...@gmail.com on 5 Mar 2009 at 10:38

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Please see comment added to JIRA issue.

Original comment by Alex.Rui...@gmail.com on 28 Mar 2009 at 8:18