In code reviews here, people often misread this:
assertThat(collection, contains("x"));
As meaning this: "Assert that the collection contains 'x'".
But what it actually means is this: "Assert that the collection contains only 'x'".
This causes a lot of unnecessary questions to be raised on our code reviews where code was updated to use Hamcrest, just because it reads differently to what it's actually doing.
At the same time, people looking to write new code with Hamcrest are using autocompletion to find appropriate-looking methods, and will often try to use contains before discovering that they really wanted hasItem.
I would suggest containsOnly as a new name, but containsInAnyOrder sort of has the same issue and I am finding it hard to jam the additional word in there.
In code reviews here, people often misread this:
As meaning this: "Assert that the collection contains 'x'".
But what it actually means is this: "Assert that the collection contains only 'x'".
This causes a lot of unnecessary questions to be raised on our code reviews where code was updated to use Hamcrest, just because it reads differently to what it's actually doing.
At the same time, people looking to write new code with Hamcrest are using autocompletion to find appropriate-looking methods, and will often try to use
containsbefore discovering that they really wantedhasItem.I would suggest
containsOnlyas a new name, butcontainsInAnyOrdersort of has the same issue and I am finding it hard to jam the additional word in there.