fest-assert-2.x
fest-assert-2.x copied to clipboard
Remove methods from *ArrayAssert that take an object to compare size
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).
Pros for such methods:
- readability, the test author's intent is captured more precisely:
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.
- "write-ability". I choose fest-assert over plain testng/junit assertions because it have all this kind of assertion methods that are very convenient to use. It's like fest-assert goes one step further than others, do a bit more for you, saving keystrokes.
Cons:
- A little API explosion?. Yes, for "regular" libraries it would have been. But not for testing framework imo. The whole library is an API explosion compared to Java's
assertkeyword :)
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.