FEST

Iterables assertion support

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: FEST-Assert 1.2
  • Fix Version/s: FEST-Assert 1.3
  • Component/s: Assert
  • Labels:
    None
  • Number of attachments :
    0

Description

One thing I miss a lot from hamcrest are the hasItem and related matchers for Iterables. It would be great if fest-asserts had an IterableAssert that gets returned for iterables.

Activity

Hide
Luke Nezda added a comment -

Implementations would be trivial with Google Collections (com.google.common.collect.Iterables, etc.) available in final form in Maven Central repository now:

<dependency>
  <groupId>com.google.collections</groupId>
  <artifactId>google-collections</artifactId>
  <version>1.0</version>
</dependency>

For familiarity for Hamcrest users, hasItem might be nice, but contains would be more consistent.

Show
Luke Nezda added a comment - Implementations would be trivial with Google Collections (com.google.common.collect.Iterables, etc.) available in final form in Maven Central repository now:
<dependency>
  <groupId>com.google.collections</groupId>
  <artifactId>google-collections</artifactId>
  <version>1.0</version>
</dependency>
For familiarity for Hamcrest users, hasItem might be nice, but contains would be more consistent.
Hide
Alex Ruiz added a comment -

Hi James & Luke,

I'd like to have more details about what is the expected output of this task. Can you please provide a little more details? like how would you like the API look like, what is the expected input, etc.

So far, my understanding is that given a Iterable, there would be a method hasItem that takes a FEST Condition and returns the item (or items?) that satisfy such condition. Am I in the right track?

Thanks!

Show
Alex Ruiz added a comment - Hi James & Luke, I'd like to have more details about what is the expected output of this task. Can you please provide a little more details? like how would you like the API look like, what is the expected input, etc. So far, my understanding is that given a Iterable, there would be a method hasItem that takes a FEST Condition and returns the item (or items?) that satisfy such condition. Am I in the right track? Thanks!
Hide
Alex Ruiz added a comment -

Luke, you are right, contains is more consistent than hasItem.

Show
Alex Ruiz added a comment - Luke, you are right, contains is more consistent than hasItem.
Hide
James Ravn added a comment - - edited

Hi Alex,

I ended up using Assertions.assertThat(Iterator):

assertThat(myIterable.iterator()).contains(myObj);

I'm happy with this except for the verbosity of calling #iterator. An assertThat which unboxes the iterator would be sufficient, I think. The returned CollectionAssert works well.

Show
James Ravn added a comment - - edited Hi Alex, I ended up using Assertions.assertThat(Iterator):
assertThat(myIterable.iterator()).contains(myObj);
I'm happy with this except for the verbosity of calling #iterator. An assertThat which unboxes the iterator would be sufficient, I think. The returned CollectionAssert works well.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: