hardayal / hamcrest

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

Suggestion: Replace multiple factories for IsIterableContainingXXX, etc. with single set of matcher list builder factories #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
IsIterableContainingInOrder, IsArrayContainingInAnyOrder, etc., each
present a set of a dozen or more factories with different numbers and types
of parameters for building these types of matchers. When I wanted to create
my own matcher in this same style, I didn't want to repeat all those
factories, so I experimented with writing some factories just for building
lists of matchers that other collection-oriented matchers could use.

The attached file is a version I've been using for a week or so, and I'm
fairly happy with it. Using these instead will simplify all of the
collection matchers at the cost of a very small increase in verbiage in the
specification of the matcher. For example:

  assertThat( matchingRecordIds, containsInAnyOrder( elements( 1, 7, 3, 5 )
) );
  assertThat( recordStore.getRecords(),
              contains( elementsMatching( sameInstance( newRecord ) ) ) );

The only addition is the "elements" or "elementsMatching" method calls. I
think these names are fairly clear but am willing to hear other suggestions.

I welcome feedback on this idea, and propose its inclusion in the Hamcrest
collections library.

Original issue reported on code.google.com by mhack...@kanayo.com on 27 Jan 2009 at 6:44

Attachments:

GoogleCodeExporter commented 8 years ago
tagging

Original comment by t.denley on 12 May 2012 at 11:01