Skip to content

Commit 82e83c6

Browse files
committed
Added comment about idempotency to Matcher
1 parent 7852275 commit 82e83c6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

hamcrest-core/src/main/java/org/hamcrest/Matcher.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
* new features and remain compatible with all Matcher implementations.
1313
* </p>
1414
* <p>
15+
* When using Hamcrest, there is no guarantee as to how often <code>matches()</code> or
16+
* <code>describeMismatch()</code> will be called, so the objects passed as
17+
* <code>actual</code> arguments should not change when referenced. If you're testing a
18+
* stream, a good practice is to collect the contents of the stream before matching.
19+
* </p>
20+
* <p>
1521
* N.B. Well designed matchers should be immutable.
1622
* </p>
1723
*
@@ -27,12 +33,12 @@ public interface Matcher<T> extends SelfDescribing {
2733
* (because of type erasure with Java generics). It is down to the implementations
2834
* to check the correct type.
2935
*
30-
* @param item the object against which the matcher is evaluated.
36+
* @param actual the object against which the matcher is evaluated.
3137
* @return <code>true</code> if <var>item</var> matches, otherwise <code>false</code>.
3238
*
3339
* @see BaseMatcher
3440
*/
35-
boolean matches(Object item);
41+
boolean matches(Object actual);
3642

3743
/**
3844
* Generate a description of why the matcher has not accepted the item.
@@ -41,11 +47,11 @@ public interface Matcher<T> extends SelfDescribing {
4147
* This method assumes that <code>matches(item)</code> is false, but
4248
* will not check this.
4349
*
44-
* @param item The item that the Matcher has rejected.
50+
* @param actual The item that the Matcher has rejected.
4551
* @param mismatchDescription
4652
* The description to be built or appended to.
4753
*/
48-
void describeMismatch(Object item, Description mismatchDescription);
54+
void describeMismatch(Object actual, Description mismatchDescription);
4955

5056
/**
5157
* This method simply acts a friendly reminder not to implement Matcher directly and

0 commit comments

Comments
 (0)