mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 11:04:00 +01:00
339 lines
16 KiB
HTML
339 lines
16 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!--NewPage-->
|
|
<HTML>
|
|
<HEAD>
|
|
<!-- Generated by javadoc (build 1.5.0_22) on Mon May 24 23:03:13 CEST 2010 -->
|
|
<TITLE>
|
|
ArgumentMatcher (Mockito API)
|
|
</TITLE>
|
|
|
|
<META NAME="keywords" CONTENT="org.mockito.ArgumentMatcher class">
|
|
|
|
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
|
|
|
|
<SCRIPT type="text/javascript">
|
|
function windowTitle()
|
|
{
|
|
parent.document.title="ArgumentMatcher (Mockito API)";
|
|
}
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
</NOSCRIPT>
|
|
|
|
</HEAD>
|
|
|
|
<BODY BGCOLOR="white" onload="windowTitle();">
|
|
|
|
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<A NAME="navbar_top"><!-- --></A>
|
|
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_top_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/ArgumentMatcher.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
</EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../org/mockito/ArgumentCaptor.html" title="class in org.mockito"><B>PREV CLASS</B></A>
|
|
<A HREF="../../org/mockito/BDDMockito.html" title="class in org.mockito"><B>NEXT CLASS</B></A></FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../index.html?org/mockito/ArgumentMatcher.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="ArgumentMatcher.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_top"></A>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
|
|
<HR>
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<H2>
|
|
<FONT SIZE="-1">
|
|
org.mockito</FONT>
|
|
<BR>
|
|
Class ArgumentMatcher<T></H2>
|
|
<PRE>
|
|
java.lang.Object
|
|
<IMG SRC="../../resources/inherit.gif" ALT="extended by ">org.hamcrest.BaseMatcher<T>
|
|
<IMG SRC="../../resources/inherit.gif" ALT="extended by "><B>org.mockito.ArgumentMatcher<T></B>
|
|
</PRE>
|
|
<DL>
|
|
<DT><DT><B>Type Parameters:</B><DD><CODE>T</CODE> - type of argument</DL>
|
|
<DL>
|
|
<DT><B>All Implemented Interfaces:</B> <DD>org.hamcrest.Matcher<T>, org.hamcrest.SelfDescribing</DD>
|
|
</DL>
|
|
<DL>
|
|
<DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../org/mockito/internal/matchers/And.html" title="class in org.mockito.internal.matchers">And</A>, <A HREF="../../org/mockito/internal/matchers/Any.html" title="class in org.mockito.internal.matchers">Any</A>, <A HREF="../../org/mockito/internal/matchers/AnyVararg.html" title="class in org.mockito.internal.matchers">AnyVararg</A>, <A HREF="../../org/mockito/internal/matchers/CapturingMatcher.html" title="class in org.mockito.internal.matchers">CapturingMatcher</A>, <A HREF="../../org/mockito/internal/matchers/CompareTo.html" title="class in org.mockito.internal.matchers">CompareTo</A>, <A HREF="../../org/mockito/internal/matchers/Contains.html" title="class in org.mockito.internal.matchers">Contains</A>, <A HREF="../../org/mockito/internal/matchers/EndsWith.html" title="class in org.mockito.internal.matchers">EndsWith</A>, <A HREF="../../org/mockito/internal/matchers/Equals.html" title="class in org.mockito.internal.matchers">Equals</A>, <A HREF="../../org/mockito/internal/matchers/EqualsWithDelta.html" title="class in org.mockito.internal.matchers">EqualsWithDelta</A>, <A HREF="../../org/mockito/internal/matchers/Find.html" title="class in org.mockito.internal.matchers">Find</A>, <A HREF="../../org/mockito/internal/matchers/InstanceOf.html" title="class in org.mockito.internal.matchers">InstanceOf</A>, <A HREF="../../org/mockito/internal/matchers/Matches.html" title="class in org.mockito.internal.matchers">Matches</A>, <A HREF="../../org/mockito/internal/matchers/Not.html" title="class in org.mockito.internal.matchers">Not</A>, <A HREF="../../org/mockito/internal/matchers/NotNull.html" title="class in org.mockito.internal.matchers">NotNull</A>, <A HREF="../../org/mockito/internal/matchers/Null.html" title="class in org.mockito.internal.matchers">Null</A>, <A HREF="../../org/mockito/internal/matchers/Or.html" title="class in org.mockito.internal.matchers">Or</A>, <A HREF="../../org/mockito/internal/matchers/apachecommons/ReflectionEquals.html" title="class in org.mockito.internal.matchers.apachecommons">ReflectionEquals</A>, <A HREF="../../org/mockito/internal/matchers/Same.html" title="class in org.mockito.internal.matchers">Same</A>, <A HREF="../../org/mockito/internal/matchers/StartsWith.html" title="class in org.mockito.internal.matchers">StartsWith</A></DD>
|
|
</DL>
|
|
<HR>
|
|
<DL>
|
|
<DT><PRE>public abstract class <B>ArgumentMatcher<T></B><DT>extends org.hamcrest.BaseMatcher<T></DL>
|
|
</PRE>
|
|
|
|
<P>
|
|
Allows creating customized argument matchers.
|
|
<p>
|
|
ArgumentMatcher is an hamcrest <CODE>Matcher</CODE> with predefined describeTo() method.
|
|
In case of failure, ArgumentMatcher generates description based on <b>decamelized class name</b> - to promote meaningful class names.
|
|
For example <b>StringWithStrongLanguage</b> matcher will generate 'String with strong language' description.
|
|
You can always override describeTo() method and provide detailed description.
|
|
<p>
|
|
Use <A HREF="../../org/mockito/Matchers.html#argThat(org.hamcrest.Matcher)"><CODE>Matchers.argThat(org.hamcrest.Matcher<T>)</CODE></A> method and pass an instance of hamcrest <CODE>Matcher</CODE>, e.g:
|
|
|
|
<pre>
|
|
class IsListOfTwoElements extends ArgumentMatcher<List> {
|
|
public boolean matches(Object list) {
|
|
return ((List) list).size() == 2;
|
|
}
|
|
}
|
|
|
|
List mock = mock(List.class);
|
|
|
|
when(mock.addAll(argThat(new IsListOfTwoElements()))).thenReturn(true);
|
|
|
|
mock.addAll(Arrays.asList("one", "two"));
|
|
|
|
verify(mock).addAll(argThat(new IsListOfTwoElements()));
|
|
</pre>
|
|
|
|
To keep it readable you may want to extract method, e.g:
|
|
|
|
<pre>
|
|
verify(mock).addAll(<b>argThat(new IsListOfTwoElements())</b>);
|
|
//becomes
|
|
verify(mock).addAll(<b>listOfTwoElements()</b>);
|
|
</pre>
|
|
|
|
<b>Warning:</b> Be reasonable with using complicated argument matching, especially custom argument matchers, as it can make the test less readable.
|
|
Sometimes it's better to implement equals() for arguments that are passed to mocks
|
|
(Mockito naturally uses equals() for argument matching).
|
|
This can make the test cleaner.
|
|
<p>
|
|
Also, <b>sometimes <A HREF="../../org/mockito/ArgumentCaptor.html" title="class in org.mockito"><CODE>ArgumentCaptor</CODE></A> may be a better fit</b> than custom matcher.
|
|
For example, if custom argument matcher is not likely to be reused
|
|
or you just need it to assert on argument values to complete verification of behavior.
|
|
<p>
|
|
Read more about other matchers in javadoc for <A HREF="../../org/mockito/Matchers.html" title="class in org.mockito"><CODE>Matchers</CODE></A> class
|
|
<P>
|
|
|
|
<P>
|
|
<HR>
|
|
|
|
<P>
|
|
|
|
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
|
|
|
<A NAME="constructor_summary"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
|
<B>Constructor Summary</B></FONT></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD><CODE><B><A HREF="../../org/mockito/ArgumentMatcher.html#ArgumentMatcher()">ArgumentMatcher</A></B>()</CODE>
|
|
|
|
<BR>
|
|
</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<!-- ========== METHOD SUMMARY =========== -->
|
|
|
|
<A NAME="method_summary"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
|
<B>Method Summary</B></FONT></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE> void</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../org/mockito/ArgumentMatcher.html#describeTo(org.hamcrest.Description)">describeTo</A></B>(org.hamcrest.Description description)</CODE>
|
|
|
|
<BR>
|
|
</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>abstract boolean</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../org/mockito/ArgumentMatcher.html#matches(java.lang.Object)">matches</A></B>(java.lang.Object argument)</CODE>
|
|
|
|
<BR>
|
|
Returns whether this matcher accepts the given argument.</TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="methods_inherited_from_class_org.hamcrest.BaseMatcher"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
|
|
<TH ALIGN="left"><B>Methods inherited from class org.hamcrest.BaseMatcher</B></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD><CODE>_dont_implement_Matcher___instead_extend_BaseMatcher_, toString</CODE></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
|
|
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait</CODE></TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
|
|
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
|
|
|
<A NAME="constructor_detail"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
<B>Constructor Detail</B></FONT></TH>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="ArgumentMatcher()"><!-- --></A><H3>
|
|
ArgumentMatcher</H3>
|
|
<PRE>
|
|
public <B>ArgumentMatcher</B>()</PRE>
|
|
<DL>
|
|
</DL>
|
|
|
|
<!-- ============ METHOD DETAIL ========== -->
|
|
|
|
<A NAME="method_detail"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
<B>Method Detail</B></FONT></TH>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="matches(java.lang.Object)"><!-- --></A><H3>
|
|
matches</H3>
|
|
<PRE>
|
|
public abstract boolean <B>matches</B>(java.lang.Object argument)</PRE>
|
|
<DL>
|
|
<DD>Returns whether this matcher accepts the given argument.
|
|
<p>
|
|
The method should <b>never</b> assert if the argument doesn't match. It
|
|
should only return false.
|
|
<P>
|
|
<DD><DL>
|
|
<DT><B>Parameters:</B><DD><CODE>argument</CODE> - the argument
|
|
<DT><B>Returns:</B><DD>whether this matcher accepts the given argument.</DL>
|
|
</DD>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="describeTo(org.hamcrest.Description)"><!-- --></A><H3>
|
|
describeTo</H3>
|
|
<PRE>
|
|
public void <B>describeTo</B>(org.hamcrest.Description description)</PRE>
|
|
<DL>
|
|
<DD><DL>
|
|
</DL>
|
|
</DD>
|
|
</DL>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
<HR>
|
|
|
|
|
|
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
|
<A NAME="navbar_bottom"><!-- --></A>
|
|
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_bottom_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/ArgumentMatcher.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
</EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../org/mockito/ArgumentCaptor.html" title="class in org.mockito"><B>PREV CLASS</B></A>
|
|
<A HREF="../../org/mockito/BDDMockito.html" title="class in org.mockito"><B>NEXT CLASS</B></A></FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../index.html?org/mockito/ArgumentMatcher.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="ArgumentMatcher.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_bottom"></A>
|
|
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
|
|
|
<HR>
|
|
|
|
</BODY>
|
|
</HTML>
|