Package org.mockito.internal.matchers
Class CapturingMatcher<T>
- java.lang.Object
-
- org.mockito.internal.matchers.CapturingMatcher<T>
-
- All Implemented Interfaces:
java.io.Serializable
,ArgumentMatcher<T>
,CapturesArguments
public class CapturingMatcher<T> extends java.lang.Object implements ArgumentMatcher<T>, CapturesArguments, java.io.Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CapturingMatcher(java.lang.Class<? extends T> clazz)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
captureFrom(java.lang.Object argument)
java.util.List<T>
getAllValues()
T
getLastValue()
boolean
matches(java.lang.Object argument)
Informs if this matcher accepts the given argument.java.lang.String
toString()
java.lang.Class<?>
type()
The type of the argument this matcher matches.
-
-
-
Field Detail
-
clazz
private final java.lang.Class<? extends T> clazz
-
arguments
private final java.util.List<T> arguments
-
lock
private final java.util.concurrent.locks.ReadWriteLock lock
-
readLock
private final java.util.concurrent.locks.Lock readLock
-
writeLock
private final java.util.concurrent.locks.Lock writeLock
-
-
Constructor Detail
-
CapturingMatcher
public CapturingMatcher(java.lang.Class<? extends T> clazz)
-
-
Method Detail
-
matches
public boolean matches(java.lang.Object argument)
Description copied from interface:ArgumentMatcher
Informs if this matcher accepts the given argument.The method should never assert if the argument doesn't match. It should only return false.
See the example in the top level javadoc for
ArgumentMatcher
- Specified by:
matches
in interfaceArgumentMatcher<T>
- Parameters:
argument
- the argument- Returns:
- true if this matcher accepts the given argument.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getLastValue
public T getLastValue()
-
getAllValues
public java.util.List<T> getAllValues()
-
captureFrom
public void captureFrom(java.lang.Object argument)
- Specified by:
captureFrom
in interfaceCapturesArguments
-
type
public java.lang.Class<?> type()
Description copied from interface:ArgumentMatcher
The type of the argument this matcher matches.This method is used to differentiate between a matcher used to match a raw vararg array parameter from a matcher used to match a single value passed as a vararg parameter.
Where the matcher:
- is at the parameter index of a vararg parameter
- is the last matcher passed
- this method returns a type assignable to the vararg parameter's raw type, i.e. its array type.
For example:
// Given vararg method with signature: int someVarargMethod(String... args); // The following will match invocations with any number of parameters, i.e. any number of elements in the raw array. mock.someVarargMethod(isA(String[].class)); // The following will match invocations with a single parameter, i.e. one string in the raw array. mock.someVarargMethod(isA(String.class)); // The following will match invocations with two parameters, i.e. two strings in the raw array mock.someVarargMethod(isA(String.class), isA(String.class));
Only matcher implementations that can conceptually match a raw vararg parameter should override this method.
- Specified by:
type
in interfaceArgumentMatcher<T>
- Returns:
- the type this matcher handles. The default value of
Void
means the type is not known.
-
-