|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.mockachino.matchers.MatchersBase
se.mockachino.matchers.Matchers
public class Matchers
Matchers is a utility class, containing a lot of useful default matchers.
A matcher is just a plain java object of theMatcher
type,
which can be used by verifying and stubbing.
The only important thing is that when using a matcher for a method call, you need to wrap it in
Matchers.match() (or Matchers.m() as a shortcut).
This wrapping MUST be directly in the actual method call for it to work.
Example:
List myMock = mock(List.class); MatcherApart from using custom matchers, you can use some predefined ones. All methods here that return a Matcher needs to be wrapped in Matchers.match() when using in an argument. The methods that return a primitive or a <T> have already been wrapped in Matchers.match() and can be used directly as is. Example:myMatcher = new Matcher {...}; // won't work, get expects an integer, not a matcher stubReturn(1).on(myMock).get(myMatcher)); // Will work: stubReturn(1).on(myMock).get(match(myMatcher)));
stubReturn(1).on(myMock).get(match(mAnyInt())); stubReturn(1).on(myMock).get(m(mAnyInt())); stubReturn(1).on(myMock).get(anyInt());
Constructor Summary | |
---|---|
Matchers()
|
Method Summary | ||
---|---|---|
static
|
and(Matcher<T>... matchers)
Matches the parameter if and only if all the matchers match. |
|
static
|
any(java.lang.Class<T> clazz)
Always matches. |
|
static boolean |
anyBoolean()
Always matches. |
|
static byte |
anyByte()
Always matches. |
|
static char |
anyChar()
Always matches. |
|
static double |
anyDouble()
Always matches. |
|
static float |
anyFloat()
Always matches. |
|
static int |
anyInt()
Always matches. |
|
static long |
anyLong()
Always matches. |
|
static short |
anyShort()
Always matches. |
|
static java.lang.String |
contains(java.lang.String s)
Matches if the parameter value contains s. |
|
static java.lang.String |
endsWith(java.lang.String s)
Matches if the parameter value ends with s. |
|
static
|
eq(T value)
Compares value with the actual parameter based on equality. |
|
static
|
m(Matcher<T> matcher)
Shortcut for match(se.mockachino.matchers.matcher.Matcher |
|
static
|
match(Matcher<T> matcher)
Matches using a custom matcher. |
|
static
|
not(Matcher<T> matcher)
Negates the matching of the specified matcher. |
|
static
|
notEq(T value)
Matches negation of eq(T) |
|
static
|
notSame(T value)
Matches negation of same(T) |
|
static
|
or(Matcher<T>... matchers)
Matches the parameter if any of the matchers match. |
|
static java.lang.String |
regexp(java.lang.String s)
Matches if the parameter value matches the regular expression. |
|
static
|
same(T value)
Compares value with the actual parameter based on object identity. |
|
static java.lang.String |
startsWith(java.lang.String s)
Matches if the parameter value starts with s. |
|
static
|
type(java.lang.Class<T> clazz,
java.lang.Class<?>... classes)
Matches if the argument is an instance of any of the classes. |
Methods inherited from class se.mockachino.matchers.MatchersBase |
---|
mAnd, mAny, mAnyBoolean, mAnyByte, mAnyChar, mAnyDouble, mAnyFloat, mAnyInt, mAnyLong, mAnyShort, matchEq, mContains, mEndsWith, mEq, mNot, mOr, mRegexp, mSame, mStartsWith, mType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Matchers()
Method Detail |
---|
public static <T> T match(Matcher<T> matcher)
matcher
- public static <T> T m(Matcher<T> matcher)
match(se.mockachino.matchers.matcher.Matcher)
public static <T> T same(T value)
value
- the value
public static <T> T notSame(T value)
same(T)
public static <T> T eq(T value)
value
- public static <T> T notEq(T value)
eq(T)
public static <T> T and(Matcher<T>... matchers)
matchers
- public static <T> T or(Matcher<T>... matchers)
matchers
- public static <T> T not(Matcher<T> matcher)
matcher
- public static java.lang.String contains(java.lang.String s)
s
- the string to search forpublic static java.lang.String startsWith(java.lang.String s)
s
- the string to search forpublic static java.lang.String endsWith(java.lang.String s)
s
- the string to search forpublic static java.lang.String regexp(java.lang.String s)
s
- the string to search forpublic static boolean anyBoolean()
public static <T> T any(java.lang.Class<T> clazz)
public static char anyChar()
public static long anyLong()
public static float anyFloat()
public static double anyDouble()
public static short anyShort()
public static byte anyByte()
public static int anyInt()
public static <T> T type(java.lang.Class<T> clazz, java.lang.Class<?>... classes)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |