<p>I am relatively new to matchers. I am toying around with <a href="http://code.google.com/p/hamcrest/" rel="noreferrer">hamcrest</a> in combination with JUnit and I kinda like it.</p>

<p>Is there a way, to state that one of multiple choices is correct?</p>

<p>Something like</p>

<pre><code>assertThat( result, is( either( 1, or( 2, or( 3 ) ) ) ) ) //does not work in hamcrest
</code></pre>

<p>The method I am testing returns one element of a collection. The list may contain multiple candidates. My current implementation returns the first hit, but that is not a requirement. I would like my testcase to succeed, if any of the possible candidates is returned. How would you express this in Java?</p>

<p>(I am open to hamcrest-alternatives)</p>

```
```
assertThat(result, anyOf(equalTo(1), equalTo(2), equalTo(3)))
```
```
From
Hamcrest tutorial
:
```
anyOf
```
- matches if any matchers match, short circuits (like Java ||)
See also
Javadoc
.
Moreover, you could write your own Matcher, which is quite easy to do.