Open alexruiz opened 12 years ago
Pros for such methods:
assertThat(array).hasSameSizeAs(collection);
reads a lot better than
assertThat(array).hasSize(collection.size());
The less steps it takes reader to get the assertion the better.
Cons:
assert
keyword :)p.s. Original feature request http://jira.codehaus.org/browse/FEST-221 p.s.s. If Map have .size() then why can't you assert that an array have the same number of elements as there are mapping in the map?
I'm sorry, but I don't agree. I can see having the same argument over hasSameSize(byte[]) and all the primitive arrays or some crazy stuff as hasSameSize(String), hasSameSize(StringBuilder). We can revisit this feature after 2.0 is released.
For example, we have a method that takes an Iterable and asserts that an array has the same size. This is unnecessary API explosion. We need to draw the line somewhere. Now we compare to Iterable and Object array, which give users the idea they can request size comparison to whatever type they think they need, e.g. a Map and so on.
To assert the size of an array, just pass the expected size. If users have to compare it to the size of an array, get the size of such array and do an assertThat(array).hasSize(#number).