My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Copyright (c) 2000-2006 hamcrest.org
*/
package org.hamcrest;

/**
* A matcher over acceptable values.
* A matcher is able to describe itself to give feedback when it fails.
* <p/>
* Matcher implementations should <b>NOT directly implement this interface</b>.
* Instead, <b>extend</b> the {@link BaseMatcher} abstract class,
* which will ensure that the Matcher API can grow to support
* new features and remain compatible with all Matcher implementations.
* <p/>
* For easy access to common Matcher implementations, use the static factory
* methods in {@link CoreMatchers}.
*
* @see CoreMatchers
* @see BaseMatcher
*/
public interface Matcher<T> extends SelfDescribing {

/**
* Evaluates the matcher for argument <var>item</var>.
* <p/>
* This method matches against Object, instead of the generic type T. This is
* because the caller of the Matcher does not know at runtime what the type is
* (because of type erasure with Java generics). It is down to the implementations
* to check the correct type.
*
* @param item the object against which the matcher is evaluated.
* @return <code>true</code> if <var>item</var> matches, otherwise <code>false</code>.
*
* @see BaseMatcher
*/
boolean matches(Object item);

/**
* Generate a description of why the matcher has not accepted the item.
* The description will be part of a larger description of why a matching
* failed, so it should be concise.
* This method assumes that <code>matches(item)</code> is false, but
* will not check this.
*
* @param item The item that the Matcher has rejected.
* @param mismatchDescription
* The description to be built or appended to.
*/
void describeMismatch(Object item, Description mismatchDescription);

/**
* This method simply acts a friendly reminder not to implement Matcher directly and
* instead extend BaseMatcher. It's easy to ignore JavaDoc, but a bit harder to ignore
* compile errors .
*
* @see Matcher for reasons why.
* @see BaseMatcher
* @deprecated to make
*/
@Deprecated
void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}

Change log

r302 by smgfreeman on Sep 30, 2008   Diff
Merged in Neil's mismatch implementation.
Go to: 
Project members, sign in to write a code review

Older revisions

r281 by nat.pryce on Jul 6, 2008   Diff
Addressing  issue 35 
r258 by neildunn on Apr 2, 2008   Diff
* Added Array, Iterable and Collection
variants of:
 - contains in order
 - contains in any order
 - is empty
...
r228 by sebastian.bergmann on Jan 4, 2008   Diff
- Fix EOLs.
All revisions of this file

File info

Size: 2244 bytes, 61 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting