I have a Groovy array that will receive a given number of random Integer values. And I want to argue that every element in the array has a value within a given range. I am trying to use Hamcrest Matchers. So my test is as follows:
@Test void testShouldReturnArrayOfStats(){ def results = pg.rollStats() assertThat results, everyItem(both(greaterThan(0)).and(lessThanOrEqualTo(6))) }
When I run the test, I get assertionError
java.lang.AssertionError: Expected: every item is (a value greater than <0> and a value less than or equal to <6>) but: was [<6>, <3>, <5>, <4>, <3>, <2>]
I have tried some variations of this, but I am not getting the passing test. just looking at the βBut: wasβ part of the error, I see that all 6 values ββmeet the requirements, but the test still doesn't work.
I have not used Groovy or Hamcrest for a very long time, so I'm sure something is missing. Thanks
Troyb source share