Package org.easymock
Class Capture<T>
- java.lang.Object
-
- org.easymock.Capture<T>
-
- Type Parameters:
T- Type of the captured element
- All Implemented Interfaces:
java.io.Serializable
public class Capture<T> extends java.lang.Object implements java.io.SerializableWill contain what was captured by thecapture()matcher. Knows if something was captured or not (allows to capture a null value). Implementation note: If the capture is serialized, it is the user duty to make sure the transformation used also is serializable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUIDprivate java.util.function.UnaryOperator<T>transformprivate CaptureTypetypeprivate java.util.List<T>values
-
Constructor Summary
Constructors Modifier Constructor Description privateCapture()Default constructor.privateCapture(CaptureType type)Constructor allowing to select the capture type.privateCapture(CaptureType type, java.util.function.UnaryOperator<T> transform)Constructor allowing to select the capture type and transformation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TgetValue()Return captured value.java.util.List<T>getValues()Return all captured values.booleanhasCaptured()static <T> Capture<T>newInstance()Create a new capture instance that will keep only the last captured value.static <T> Capture<T>newInstance(java.util.function.UnaryOperator<T> transform)Create a new capture instance with a specific transformation function to change the values into a different value.static <T> Capture<T>newInstance(CaptureType type)Create a new capture instance with a specificCaptureType.static <T> Capture<T>newInstance(CaptureType type, java.util.function.UnaryOperator<T> transform)Create a new capture instance with a specificCaptureTypeand a specific transformation function to change the values into a different value.voidreset()Will reset capture to a "nothing captured yet" statevoidsetValue(T value)Used internally by the EasyMock framework to add a new captured value.java.lang.StringtoString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
type
private final CaptureType type
-
transform
private final java.util.function.UnaryOperator<T> transform
-
values
private final java.util.List<T> values
-
-
Constructor Detail
-
Capture
private Capture()
Default constructor. Only the last element will be captured
-
Capture
private Capture(CaptureType type)
Constructor allowing to select the capture type.- Parameters:
type- capture type
-
Capture
private Capture(CaptureType type, java.util.function.UnaryOperator<T> transform)
Constructor allowing to select the capture type and transformation.- Parameters:
type- capture typetransform- transformation applied to the captured value
-
-
Method Detail
-
newInstance
public static <T> Capture<T> newInstance()
Create a new capture instance that will keep only the last captured value.- Type Parameters:
T- type of the class to be captured- Returns:
- the new capture object
-
newInstance
public static <T> Capture<T> newInstance(CaptureType type)
Create a new capture instance with a specificCaptureType.- Type Parameters:
T- type of the class to be captured- Parameters:
type- capture type wanted- Returns:
- the new capture object
-
newInstance
public static <T> Capture<T> newInstance(CaptureType type, java.util.function.UnaryOperator<T> transform)
Create a new capture instance with a specificCaptureTypeand a specific transformation function to change the values into a different value.- Type Parameters:
T- type of the class to be captured- Parameters:
type- capture type wantedtransform- the transform function- Returns:
- the new capture object
-
newInstance
public static <T> Capture<T> newInstance(java.util.function.UnaryOperator<T> transform)
Create a new capture instance with a specific transformation function to change the values into a different value.- Type Parameters:
T- type of the class to be captured- Parameters:
transform- the transform function- Returns:
- the new capture object
-
reset
public void reset()
Will reset capture to a "nothing captured yet" state
-
hasCaptured
public boolean hasCaptured()
- Returns:
- true if something was captured
-
getValue
public T getValue()
Return captured value.- Returns:
- The last captured value
- Throws:
java.lang.AssertionError- if nothing was captured yet or if more than one value was captured
-
getValues
public java.util.List<T> getValues()
Return all captured values. It returns the actual list so you can modify its content if needed.- Returns:
- The currently captured values
-
setValue
public void setValue(T value)
Used internally by the EasyMock framework to add a new captured value.- Parameters:
value- Value captured
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-