public class EasyMock extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DISABLE_CLASS_MOCKING
Since EasyMock 3.0, EasyMock can perform class mocking directly without
using the class extension.
|
static String |
ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT
Since EasyMock 2.4, by default, a mock wasn't allowed to be called in
multiple threads unless it was made thread-safe (See
makeThreadSafe(Object, boolean) method). |
static String |
NOT_THREAD_SAFE_BY_DEFAULT
Since EasyMock 2.5, by default a mock is thread-safe.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
and(boolean first,
boolean second)
Expects a boolean that matches both given expectations.
|
static byte |
and(byte first,
byte second)
Expects a byte that matches both given expectations.
|
static char |
and(char first,
char second)
Expects a char that matches both given expectations.
|
static double |
and(double first,
double second)
Expects a double that matches both given expectations.
|
static float |
and(float first,
float second)
Expects a float that matches both given expectations.
|
static int |
and(int first,
int second)
Expects an int that matches both given expectations.
|
static long |
and(long first,
long second)
Expects a long that matches both given expectations.
|
static short |
and(short first,
short second)
Expects a short that matches both given expectations.
|
static <T> T |
and(T first,
T second)
Expects an Object that matches both given expectations.
|
static boolean |
anyBoolean()
Expects any boolean argument.
|
static byte |
anyByte()
Expects any byte argument.
|
static char |
anyChar()
Expects any char argument.
|
static double |
anyDouble()
Expects any double argument.
|
static float |
anyFloat()
Expects any float argument.
|
static int |
anyInt()
Expects any int argument.
|
static long |
anyLong()
Expects any long argument.
|
static <T> T |
anyObject()
Expects any Object argument.
|
static <T> T |
anyObject(Class<T> clazz)
Expects any Object argument.
|
static short |
anyShort()
Expects any short argument.
|
static String |
anyString()
Expect any string whatever its content is.
|
static boolean[] |
aryEq(boolean[] value)
Expects a boolean array that is equal to the given array, i.e.
|
static byte[] |
aryEq(byte[] value)
Expects a byte array that is equal to the given array, i.e.
|
static char[] |
aryEq(char[] value)
Expects a char array that is equal to the given array, i.e.
|
static double[] |
aryEq(double[] value)
Expects a double array that is equal to the given array, i.e.
|
static float[] |
aryEq(float[] value)
Expects a float array that is equal to the given array, i.e.
|
static int[] |
aryEq(int[] value)
Expects an int array that is equal to the given array, i.e.
|
static long[] |
aryEq(long[] value)
Expects a long array that is equal to the given array, i.e.
|
static short[] |
aryEq(short[] value)
Expects a short array that is equal to the given array, i.e.
|
static <T> T[] |
aryEq(T[] value)
Expects an Object array that is equal to the given array, i.e.
|
static <T> T |
capture(Capture<T> captured)
Expect any object but captures it for later use.
|
static boolean |
captureBoolean(Capture<Boolean> captured)
Expect any boolean but captures it for later use.
|
static byte |
captureByte(Capture<Byte> captured)
Expect any byte but captures it for later use.
|
static char |
captureChar(Capture<Character> captured)
Expect any char but captures it for later use.
|
static double |
captureDouble(Capture<Double> captured)
Expect any double but captures it for later use.
|
static float |
captureFloat(Capture<Float> captured)
Expect any float but captures it for later use.
|
static int |
captureInt(Capture<Integer> captured)
Expect any int but captures it for later use.
|
static long |
captureLong(Capture<Long> captured)
Expect any long but captures it for later use.
|
static void |
checkIsUsedInOneThread(Object mock,
boolean shouldBeUsedInOneThread)
Tell that the mock should be used in only one thread.
|
static void |
checkOrder(Object mock,
boolean state)
Switches order checking of the given mock object (more exactly: the
control of the mock object) the on and off.
|
static <T> T |
cmp(T value,
Comparator<? super T> comparator,
LogicalOperator operator)
Expects an argument that will be compared using the provided comparator.
|
static <T extends Comparable<T>> |
cmpEq(T value)
Expects a comparable argument equals to the given value according to
their compareTo method.
|
static String |
contains(String substring)
Expects a string that contains the given substring.
|
static IMocksControl |
createControl()
Creates a control, order checking is disabled by default.
|
static IMocksControl |
createControl(MockType type)
Creates a control of the requested type.
|
static <T> T |
createMock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default.
|
static <T> T |
createMock(MockType type,
Class<?> toMock)
Creates a mock object, of the requested type, that implements the given interface
or extends the given class.
|
static <T> T |
createMock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default.
|
static <T> T |
createMock(String name,
MockType type,
Class<?> toMock)
Creates a mock object, of the requested type and name, that implements the given interface
or extends the given class
|
static <T> IMockBuilder<T> |
createMockBuilder(Class<?> toMock)
Create a mock builder allowing to create a partial mock for the given
class or interface.
|
static IMocksControl |
createNiceControl()
Creates a control, order checking is disabled by default, and the mock
objects created by this control will return
0 ,
null or false for unexpected invocations. |
static <T> T |
createNiceMock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default, and the mock object will return
0 ,
null or false for unexpected invocations. |
static <T> T |
createNiceMock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default, and the mock object will return
0 ,
null or false for unexpected invocations. |
static IMocksControl |
createStrictControl()
Creates a control, order checking is enabled by default.
|
static <T> T |
createStrictMock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is enabled by default.
|
static <T> T |
createStrictMock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is enabled by default.
|
static String |
endsWith(String suffix)
Expects a string that ends with the given suffix.
|
static boolean |
eq(boolean value)
Expects a boolean that is equal to the given value.
|
static byte |
eq(byte value)
Expects a byte that is equal to the given value.
|
static char |
eq(char value)
Expects a char that is equal to the given value.
|
static double |
eq(double value)
Expects a double that is equal to the given value.
|
static double |
eq(double value,
double delta)
Expects a double that has an absolute difference to the given value that
is less than the given delta.
|
static float |
eq(float value)
Expects a float that is equal to the given value.
|
static float |
eq(float value,
float delta)
Expects a float that has an absolute difference to the given value that
is less than the given delta.
|
static int |
eq(int value)
Expects an int that is equal to the given value.
|
static long |
eq(long value)
Expects a long that is equal to the given value.
|
static short |
eq(short value)
Expects a short that is equal to the given value.
|
static <T> T |
eq(T value)
Expects an Object that is equal to the given value.
|
static <T> IExpectationSetters<T> |
expect(T value)
Returns the expectation setter for the last expected invocation in the
current thread.
|
static <T> IExpectationSetters<T> |
expectLastCall()
Returns the expectation setter for the last expected invocation in the
current thread.
|
static String |
find(String regex)
Expects a string that contains a substring that matches the given regular
expression.
|
static byte |
geq(byte value)
Expects a byte argument greater than or equal to the given value.
|
static double |
geq(double value)
Expects a double argument greater than or equal to the given value.
|
static float |
geq(float value)
Expects a float argument greater than or equal to the given value.
|
static int |
geq(int value)
Expects an int argument greater than or equal to the given value.
|
static long |
geq(long value)
Expects a long argument greater than or equal to the given value.
|
static short |
geq(short value)
Expects a short argument greater than or equal to the given value.
|
static <T extends Comparable<T>> |
geq(T value)
Expects a comparable argument greater than or equal the given value.
|
static <T> T |
getCurrentArgument(int index) |
static Object[] |
getCurrentArguments()
Returns the arguments of the current mock method call, if inside an
IAnswer callback - be careful here, reordering parameters of
method changes the semantics of your tests. |
static String |
getEasyMockProperty(String key)
Get the current value for an EasyMock property
|
static byte |
gt(byte value)
Expects a byte argument greater than the given value.
|
static double |
gt(double value)
Expects a double argument greater than the given value.
|
static float |
gt(float value)
Expects a float argument greater than the given value.
|
static int |
gt(int value)
Expects an int argument greater than the given value.
|
static long |
gt(long value)
Expects a long argument greater than the given value.
|
static short |
gt(short value)
Expects a short argument greater than the given value.
|
static <T extends Comparable<T>> |
gt(T value)
Expects a comparable argument greater than the given value.
|
static <T> T |
isA(Class<T> clazz)
Expects an object implementing the given class.
|
static <T> T |
isNull()
Expects null.
|
static <T> T |
isNull(Class<T> clazz)
Expects null.
|
static byte |
leq(byte value)
Expects a byte argument less than or equal to the given value.
|
static double |
leq(double value)
Expects a double argument less than or equal to the given value.
|
static float |
leq(float value)
Expects a float argument less than or equal to the given value.
|
static int |
leq(int value)
Expects an int argument less than or equal to the given value.
|
static long |
leq(long value)
Expects a long argument less than or equal to the given value.
|
static short |
leq(short value)
Expects a short argument less than or equal to the given value.
|
static <T extends Comparable<T>> |
leq(T value)
Expects a comparable argument less than or equal the given value.
|
static byte |
lt(byte value)
Expects a byte argument less than the given value.
|
static double |
lt(double value)
Expects a double argument less than the given value.
|
static float |
lt(float value)
Expects a float argument less than the given value.
|
static int |
lt(int value)
Expects an int argument less than the given value.
|
static long |
lt(long value)
Expects a long argument less than the given value.
|
static short |
lt(short value)
Expects a short argument less than the given value.
|
static <T extends Comparable<T>> |
lt(T value)
Expects a comparable argument less than the given value.
|
static void |
makeThreadSafe(Object mock,
boolean threadSafe)
By default, a mock is thread safe (unless
NOT_THREAD_SAFE_BY_DEFAULT is set). |
static String |
matches(String regex)
Expects a string that matches the given regular expression.
|
static <T> T |
mock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default.
|
static <T> T |
mock(MockType type,
Class<?> toMock)
Creates a mock object, of the requested type, that implements the given interface
or extends the given class
|
static <T> T |
mock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default.
|
static <T> T |
mock(String name,
MockType type,
Class<?> toMock)
Creates a mock object, of the requested type and name, that implements the given interface
or extends the given class
|
static <T> Capture<T> |
newCapture()
Create a new capture instance that will keep only the last captured value.
|
static <T> Capture<T> |
newCapture(CaptureType type)
Create a new capture instance with a specific
CaptureType |
static <T> T |
niceMock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default, and the mock object will return
0 ,
null or false for unexpected invocations. |
static <T> T |
niceMock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is disabled by default, and the mock object will return
0 ,
null or false for unexpected invocations. |
static boolean |
not(boolean first)
Expects a boolean that does not match the given expectation.
|
static byte |
not(byte first)
Expects a byte that does not match the given expectation.
|
static char |
not(char first)
Expects a char that does not match the given expectation.
|
static double |
not(double first)
Expects a double that does not match the given expectation.
|
static float |
not(float first)
Expects a float that does not match the given expectation.
|
static int |
not(int first)
Expects an int that does not match the given expectation.
|
static long |
not(long first)
Expects a long that does not match the given expectation.
|
static short |
not(short first)
Expects a short that does not match the given expectation.
|
static <T> T |
not(T first)
Expects an Object that does not match the given expectation.
|
static <T> T |
notNull()
Expects not null.
|
static <T> T |
notNull(Class<T> clazz)
Expects not null.
|
static boolean |
or(boolean first,
boolean second)
Expects a boolean that matches one of the given expectations.
|
static byte |
or(byte first,
byte second)
Expects a byte that matches one of the given expectations.
|
static char |
or(char first,
char second)
Expects a char that matches one of the given expectations.
|
static double |
or(double first,
double second)
Expects a double that matches one of the given expectations.
|
static float |
or(float first,
float second)
Expects a float that matches one of the given expectations.
|
static int |
or(int first,
int second)
Expects an int that matches one of the given expectations.
|
static long |
or(long first,
long second)
Expects a long that matches one of the given expectations.
|
static short |
or(short first,
short second)
Expects a short that matches one of the given expectations.
|
static <T> T |
or(T first,
T second)
Expects an Object that matches one of the given expectations.
|
static <T> IMockBuilder<T> |
partialMockBuilder(Class<?> toMock)
Create a mock builder allowing to create a partial mock for the given
class or interface.
|
static void |
replay(Object... mocks)
Switches the given mock objects (more exactly: the controls of the mock
objects) to replay mode.
|
static void |
reportMatcher(IArgumentMatcher matcher)
Reports an argument matcher.
|
static void |
reset(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock
objects).
|
static void |
resetToDefault(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock
objects) and turn them to a mock with default behavior.
|
static void |
resetToNice(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock
objects) and turn them to a mock with nice behavior.
|
static void |
resetToStrict(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock
objects) and turn them to a mock with strict behavior.
|
static <T> T |
same(T value)
Expects an Object that is the same as the given value.
|
static String |
setEasyMockProperty(String key,
String value)
Set a property to modify the default EasyMock behavior.
|
static String |
startsWith(String prefix)
Expects a string that starts with the given prefix.
|
static <T> T |
strictMock(Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is enabled by default.
|
static <T> T |
strictMock(String name,
Class<?> toMock)
Creates a mock object that implements the given interface, order checking
is enabled by default.
|
static void |
verify(Object... mocks)
Verifies that all expectations were met and that no unexpected
call was performed on the mock objects.
|
static void |
verifyRecording(Object... mocks)
Verifies that all expectations were met.
|
static void |
verifyUnexpectedCalls(Object... mocks)
Verifies that no unexpected call was performed.
|
public static final String ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT
makeThreadSafe(Object, boolean)
method). Since EasyMock 2.5,
this isn't the default anymore. For backward compatibility, this property
can bring EasyMock 2.4 behavior back.public static final String NOT_THREAD_SAFE_BY_DEFAULT
makeThreadSafe(Object, boolean)
.public static final String DISABLE_CLASS_MOCKING
public static <T> T mock(Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T mock(String name, Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> T mock(MockType type, Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.type
- the type of the mock to be created.toMock
- the class or interface that should be mocked.public static <T> T mock(String name, MockType type, Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.type
- the type of the mock to be created.toMock
- the class or interface that should be mocked.public static <T> T strictMock(Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T strictMock(String name, Class<?> toMock)
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> T niceMock(Class<?> toMock)
0
,
null
or false
for unexpected invocations.T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T niceMock(String name, Class<?> toMock)
0
,
null
or false
for unexpected invocations.T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> IMockBuilder<T> partialMockBuilder(Class<?> toMock)
T
- the class that the mock object should extend.toMock
- the class or interface that should be mocked.public static <T> T createMock(MockType type, Class<?> toMock)
Note: This is the old version of mock(MockType, Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.type
- the type of the mock to be created.toMock
- the class or interface that should be mocked.public static <T> T createMock(String name, MockType type, Class<?> toMock)
Note: This is the old version of mock(String, MockType, Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.type
- the type of the mock to be created.toMock
- the class or interface that should be mocked.public static <T> T createStrictMock(Class<?> toMock)
Note: This is the old version of strictMock(Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T createStrictMock(String name, Class<?> toMock)
Note: This is the old version of strictMock(String, Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> T createMock(Class<?> toMock)
Note: This is the old version of mock(Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T createMock(String name, Class<?> toMock)
Note: This is the old version of mock(String, Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> T createNiceMock(Class<?> toMock)
0
,
null
or false
for unexpected invocations.
Note: This is the old version of niceMock(Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static <T> T createNiceMock(String name, Class<?> toMock)
0
,
null
or false
for unexpected invocations.
Note: This is the old version of niceMock(String, Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.name
- the name of the mock object.toMock
- the class or interface that should be mocked.IllegalArgumentException
- if the name is not a valid Java identifier.public static <T> IMockBuilder<T> createMockBuilder(Class<?> toMock)
Note: This is the old version of partialMockBuilder(Class)
, which is more completion friendly
T
- the class or interface that the mock object should extend/implement. It is expected to be of
class toMock
.toMock
- the class or interface that should be mocked.public static IMocksControl createControl(MockType type)
type
- the mock typepublic static IMocksControl createStrictControl()
public static IMocksControl createControl()
public static IMocksControl createNiceControl()
0
,
null
or false
for unexpected invocations.public static <T> IExpectationSetters<T> expect(T value)
T
- type returned by the expected methodvalue
- the parameter is used to transport the type to the
ExpectationSetter. It allows writing the expected call as
argument, i.e. expect(mock.getName()).andReturn("John Doe").public static <T> IExpectationSetters<T> expectLastCall()
T
- type returned by the expected methodpublic static boolean anyBoolean()
false
.public static byte anyByte()
0
.public static char anyChar()
0
.public static int anyInt()
0
.public static long anyLong()
0
.public static float anyFloat()
0
.public static double anyDouble()
0
.public static short anyShort()
0
.public static <T> T anyObject()
anyObject(Class)
) can be used in these three
ways:
(T)EasyMock.anyObject() // explicit cast
EasyMock.<T> anyObject() // fixing the returned generic
EasyMock.anyObject(T.class) // pass the returned type in parameter
T
- type of the method argument to matchnull
.public static <T> T anyObject(Class<T> clazz)
anyObject()
.T
- type of the method argument to matchclazz
- the class of the argument to matchnull
.public static String anyString()
anyObject()
but prevents typing issues for the much used String
type. Consider this method to be a syntactic sugar.null
.public static <T extends Comparable<T>> T geq(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static byte geq(byte value)
value
- the given value.0
.public static double geq(double value)
value
- the given value.0
.public static float geq(float value)
value
- the given value.0
.public static int geq(int value)
value
- the given value.0
.public static long geq(long value)
value
- the given value.0
.public static short geq(short value)
value
- the given value.0
.public static <T extends Comparable<T>> T leq(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static byte leq(byte value)
value
- the given value.0
.public static double leq(double value)
value
- the given value.0
.public static float leq(float value)
value
- the given value.0
.public static int leq(int value)
value
- the given value.0
.public static long leq(long value)
value
- the given value.0
.public static short leq(short value)
value
- the given value.0
.public static <T extends Comparable<T>> T gt(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static byte gt(byte value)
value
- the given value.0
.public static double gt(double value)
value
- the given value.0
.public static float gt(float value)
value
- the given value.0
.public static int gt(int value)
value
- the given value.0
.public static long gt(long value)
value
- the given value.0
.public static short gt(short value)
value
- the given value.0
.public static <T extends Comparable<T>> T lt(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static byte lt(byte value)
value
- the given value.0
.public static double lt(double value)
value
- the given value.0
.public static float lt(float value)
value
- the given value.0
.public static int lt(int value)
value
- the given value.0
.public static long lt(long value)
value
- the given value.0
.public static short lt(short value)
value
- the given value.0
.public static <T> T isA(Class<T> clazz)
T
- the accepted type.clazz
- the class of the accepted type.null
.public static String contains(String substring)
substring
- the substring.null
.public static boolean and(boolean first, boolean second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.false
.public static byte and(byte first, byte second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static char and(char first, char second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static double and(double first, double second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static float and(float first, float second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static int and(int first, int second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static long and(long first, long second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static short and(short first, short second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static <T> T and(T first, T second)
T
- the type of the object, it is passed through to prevent casts.first
- placeholder for the first expectation.second
- placeholder for the second expectation.null
.public static boolean or(boolean first, boolean second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.false
.public static byte or(byte first, byte second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static char or(char first, char second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static double or(double first, double second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static float or(float first, float second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static int or(int first, int second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static long or(long first, long second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static short or(short first, short second)
first
- placeholder for the first expectation.second
- placeholder for the second expectation.0
.public static <T> T or(T first, T second)
T
- the type of the object, it is passed through to prevent casts.first
- placeholder for the first expectation.second
- placeholder for the second expectation.null
.public static boolean not(boolean first)
first
- placeholder for the expectation.false
.public static byte not(byte first)
first
- placeholder for the expectation.0
.public static char not(char first)
first
- placeholder for the expectation.0
.public static double not(double first)
first
- placeholder for the expectation.0
.public static float not(float first)
first
- placeholder for the expectation.0
.public static int not(int first)
first
- placeholder for the expectation.0
.public static long not(long first)
first
- placeholder for the expectation.0
.public static short not(short first)
first
- placeholder for the expectation.0
.public static <T> T not(T first)
T
- the type of the object, it is passed through to prevent casts.first
- placeholder for the expectation.null
.public static boolean eq(boolean value)
value
- the given value.0
.public static byte eq(byte value)
value
- the given value.0
.public static char eq(char value)
value
- the given value.0
.public static double eq(double value)
value
- the given value.0
.public static float eq(float value)
value
- the given value.0
.public static int eq(int value)
value
- the given value.0
.public static long eq(long value)
value
- the given value.0
.public static short eq(short value)
value
- the given value.0
.public static <T> T eq(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static boolean[] aryEq(boolean[] value)
value
- the given array.null
.public static byte[] aryEq(byte[] value)
value
- the given array.null
.public static char[] aryEq(char[] value)
value
- the given array.null
.public static double[] aryEq(double[] value)
value
- the given array.null
.public static float[] aryEq(float[] value)
value
- the given array.null
.public static int[] aryEq(int[] value)
value
- the given array.null
.public static long[] aryEq(long[] value)
value
- the given array.null
.public static short[] aryEq(short[] value)
value
- the given array.null
.public static <T> T[] aryEq(T[] value)
T
- the type of the array, it is passed through to prevent casts.value
- the given array.null
.public static <T> T isNull()
isNull(Class)
) can be used in these three ways:
(T)EasyMock.isNull() // explicit cast
EasyMock.<T> isNull() // fixing the returned generic
EasyMock.isNull(T.class) // pass the returned type in parameter
T
- type of the method argument to matchnull
.public static <T> T isNull(Class<T> clazz)
isNull()
.T
- type of the method argument to matchclazz
- the class of the argument to matchnull
.isNull()
public static <T> T notNull()
notNull(Class)
) can be used in these three ways:
(T)EasyMock.notNull() // explicit cast
EasyMock.<T> notNull() // fixing the returned generic
EasyMock.notNull(T.class) // pass the returned type in parameter
T
- type of the method argument to matchnull
.public static <T> T notNull(Class<T> clazz)
notNull()
.T
- type of the method argument to matchclazz
- the class of the argument to matchnull
.notNull()
public static String find(String regex)
regex
- the regular expression.null
.public static String matches(String regex)
regex
- the regular expression.null
.public static String startsWith(String prefix)
prefix
- the prefix.null
.public static String endsWith(String suffix)
suffix
- the suffix.null
.public static double eq(double value, double delta)
value
- the given value.delta
- the given delta.0
.public static float eq(float value, float delta)
value
- the given value.delta
- the given delta.0
.public static <T> T same(T value)
T
- the type of the object, it is passed through to prevent casts.value
- the given value.null
.public static <T extends Comparable<T>> T cmpEq(T value)
T
- type of the method argument to matchvalue
- the given value.null
.public static <T> T cmp(T value, Comparator<? super T> comparator, LogicalOperator operator)
comparator.compare(actual, expected) operator 0
T
- type of the method argument to matchvalue
- the given value.comparator
- Comparator used to compare the actual with expected value.operator
- The comparison operator.null
public static <T> Capture<T> newCapture()
T
- type of the class to be capturedpublic static <T> Capture<T> newCapture(CaptureType type)
CaptureType
T
- type of the class to be capturedtype
- capture type wantedpublic static <T> T capture(Capture<T> captured)
T
- Type of the captured objectcaptured
- Where the parameter is capturednull
public static boolean captureBoolean(Capture<Boolean> captured)
captured
- Where the parameter is capturedfalse
public static int captureInt(Capture<Integer> captured)
captured
- Where the parameter is captured0
public static long captureLong(Capture<Long> captured)
captured
- Where the parameter is captured0
public static float captureFloat(Capture<Float> captured)
captured
- Where the parameter is captured0
public static double captureDouble(Capture<Double> captured)
captured
- Where the parameter is captured0
public static byte captureByte(Capture<Byte> captured)
captured
- Where the parameter is captured0
public static char captureChar(Capture<Character> captured)
captured
- Where the parameter is captured0
public static void replay(Object... mocks)
mocks
- the mock objects.public static void reset(Object... mocks)
mocks
- the mock objects.public static void resetToNice(Object... mocks)
mocks
- the mock objectspublic static void resetToDefault(Object... mocks)
mocks
- the mock objectspublic static void resetToStrict(Object... mocks)
mocks
- the mock objectspublic static void verify(Object... mocks)
IMocksControl
linked to the mock objects.
This method as same effect as calling verifyRecording(Object...)
followed by verifyUnexpectedCalls(Object...)
.
mocks
- the mock objects.public static void verifyRecording(Object... mocks)
mocks
- the mock objects.public static void verifyUnexpectedCalls(Object... mocks)
mocks
- the mock objects.public static void checkOrder(Object mock, boolean state)
mock
- the mock object.state
- true
switches order checking on,
false
switches it off.public static void reportMatcher(IArgumentMatcher matcher)
matcher
- the matcher to use to match currently mocked method argumentpublic static Object[] getCurrentArguments()
IAnswer
callback - be careful here, reordering parameters of
method changes the semantics of your tests.IllegalStateException
- if called outside of IAnswer
callbacks.public static <T> T getCurrentArgument(int index)
public static void makeThreadSafe(Object mock, boolean threadSafe)
NOT_THREAD_SAFE_BY_DEFAULT
is set). This method can change this
behavior. Two reasons are known for someone to do that: Performance or
dead-locking issues.mock
- the mock to make thread safethreadSafe
- If the mock should be thread safe or notpublic static void checkIsUsedInOneThread(Object mock, boolean shouldBeUsedInOneThread)
ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT
was set to true.mock
- the mockshouldBeUsedInOneThread
- If the mock should be used in only one threadpublic static String getEasyMockProperty(String key)
key
- key for the propertypublic static String setEasyMockProperty(String key, String value)
Note: This method is static. Setting a property will change the entire EasyMock behavior.
key
- property keyvalue
- property value. A null value will remove the propertyCopyright © 2001–2022 EasyMock contributors. All rights reserved.