org.easymock

Class EasyMock

public class EasyMock extends Object

Field Summary
static StringENABLE_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 EasyMock method).
static StringNOT_THREAD_SAFE_BY_DEFAULT
Since EasyMock 2.5, by default a mock is thread-safe.
Constructor Summary
protected EasyMock()
Prevent instantiation but allow inheritance
Method Summary
static booleanand(boolean first, boolean second)
Expects a boolean that matches both given expectations.
static byteand(byte first, byte second)
Expects a byte that matches both given expectations.
static charand(char first, char second)
Expects a char that matches both given expectations.
static doubleand(double first, double second)
Expects a double that matches both given expectations.
static floatand(float first, float second)
Expects a float that matches both given expectations.
static intand(int first, int second)
Expects an int that matches both given expectations.
static longand(long first, long second)
Expects a long that matches both given expectations.
static shortand(short first, short second)
Expects a short that matches both given expectations.
static <T> Tand(T first, T second)
Expects an Object that matches both given expectations.
static booleananyBoolean()
Expects any boolean argument.
static byteanyByte()
Expects any byte argument.
static charanyChar()
Expects any char argument.
static doubleanyDouble()
Expects any double argument.
static floatanyFloat()
Expects any float argument.
static intanyInt()
Expects any int argument.
static longanyLong()
Expects any long argument.
static <T> TanyObject()
Expects any Object argument.
static shortanyShort()
Expects any short argument.
static boolean[]aryEq(boolean[] value)
Expects a boolean array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static byte[]aryEq(byte[] value)
Expects a byte array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static char[]aryEq(char[] value)
Expects a char array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static double[]aryEq(double[] value)
Expects a double array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static float[]aryEq(float[] value)
Expects a float array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static int[]aryEq(int[] value)
Expects an int array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static long[]aryEq(long[] value)
Expects a long array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static short[]aryEq(short[] value)
Expects a short array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.
static <T> T[]aryEq(T[] value)
Expects an Object array that is equal to the given array, i.e. it has to have the same type, length, and each element has to be equal.
static <T> Tcapture(Capture<T> captured)
Expect any object but captures it for later use.
static intcapture(Capture<Integer> captured)
Expect any int but captures it for later use.
static longcapture(Capture<Long> captured)
Expect any long but captures it for later use.
static floatcapture(Capture<Float> captured)
Expect any float but captures it for later use.
static doublecapture(Capture<Double> captured)
Expect any double but captures it for later use.
static bytecapture(Capture<Byte> captured)
Expect any byte but captures it for later use.
static charcapture(Capture<Character> captured)
Expect any char but captures it for later use.
static voidcheckIsUsedInOneThread(Object mock, boolean shouldBeUsedInOneThread)
Tell that the mock should be used in only one thread.
static voidcheckOrder(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> Tcmp(T value, Comparator<? super T> comparator, LogicalOperator operator)
Expects an argument that will be compared using the provided comparator.
static <T extends Comparable<T>> TcmpEq(Comparable<T> value)
Expects a comparable argument equals to the given value according to their compareTo method.
static Stringcontains(String substring)
Expects a string that contains the given substring.
static IMocksControlcreateControl()
Creates a control, order checking is disabled by default.
static <T> TcreateMock(Class<T> toMock)
Creates a mock object that implements the given interface, order checking is disabled by default.
static <T> TcreateMock(String name, Class<T> toMock)
Creates a mock object that implements the given interface, order checking is disabled by default.
static IMocksControlcreateNiceControl()
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> TcreateNiceMock(Class<T> 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> TcreateNiceMock(String name, Class<T> 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 IMocksControlcreateStrictControl()
Creates a control, order checking is enabled by default.
static <T> TcreateStrictMock(Class<T> toMock)
Creates a mock object that implements the given interface, order checking is enabled by default.
static <T> TcreateStrictMock(String name, Class<T> toMock)
Creates a mock object that implements the given interface, order checking is enabled by default.
static StringendsWith(String suffix)
Expects a string that ends with the given suffix.
static booleaneq(boolean value)
Expects a boolean that is equal to the given value.
static byteeq(byte value)
Expects a byte that is equal to the given value.
static chareq(char value)
Expects a char that is equal to the given value.
static doubleeq(double value)
Expects a double that is equal to the given value.
static floateq(float value)
Expects a float that is equal to the given value.
static inteq(int value)
Expects an int that is equal to the given value.
static longeq(long value)
Expects a long that is equal to the given value.
static shorteq(short value)
Expects a short that is equal to the given value.
static <T> Teq(T value)
Expects an Object that is equal to the given value.
static doubleeq(double value, double delta)
Expects a double that has an absolute difference to the given value that is less than the given delta.
static floateq(float value, float delta)
Expects a float that has an absolute difference to the given value that is less than the given delta.
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 Stringfind(String regex)
Expects a string that contains a substring that matches the given regular expression.
static <T extends Comparable<T>> Tgeq(Comparable<T> value)
Expects a comparable argument greater than or equal the given value.
static bytegeq(byte value)
Expects a byte argument greater than or equal to the given value.
static doublegeq(double value)
Expects a double argument greater than or equal to the given value.
static floatgeq(float value)
Expects a float argument greater than or equal to the given value.
static intgeq(int value)
Expects an int argument greater than or equal to the given value.
static longgeq(long value)
Expects a long argument greater than or equal to the given value.
static shortgeq(short value)
Expects a short argument greater than or equal to the given value.
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 StringgetEasyMockProperty(String key)
Get the current value for an EasyMock property
static <T extends Comparable<T>> Tgt(Comparable<T> value)
Expects a comparable argument greater than the given value.
static bytegt(byte value)
Expects a byte argument greater than the given value.
static doublegt(double value)
Expects a double argument greater than the given value.
static floatgt(float value)
Expects a float argument greater than the given value.
static intgt(int value)
Expects an int argument greater than the given value.
static longgt(long value)
Expects a long argument greater than the given value.
static shortgt(short value)
Expects a short argument greater than the given value.
static <T> TisA(Class<T> clazz)
Expects an object implementing the given class.
static <T> TisNull()
Expects null.
static <T extends Comparable<T>> Tleq(Comparable<T> value)
Expects a comparable argument less than or equal the given value.
static byteleq(byte value)
Expects a byte argument less than or equal to the given value.
static doubleleq(double value)
Expects a double argument less than or equal to the given value.
static floatleq(float value)
Expects a float argument less than or equal to the given value.
static intleq(int value)
Expects an int argument less than or equal to the given value.
static longleq(long value)
Expects a long argument less than or equal to the given value.
static shortleq(short value)
Expects a short argument less than or equal to the given value.
static <T extends Comparable<T>> Tlt(Comparable<T> value)
Expects a comparable argument less than the given value.
static bytelt(byte value)
Expects a byte argument less than the given value.
static doublelt(double value)
Expects a double argument less than the given value.
static floatlt(float value)
Expects a float argument less than the given value.
static intlt(int value)
Expects an int argument less than the given value.
static longlt(long value)
Expects a long argument less than the given value.
static shortlt(short value)
Expects a short argument less than the given value.
static voidmakeThreadSafe(Object mock, boolean threadSafe)
By default, a mock is thread safe (unless NOT_THREAD_SAFE_BY_DEFAULT is set).
static Stringmatches(String regex)
Expects a string that matches the given regular expression.
static booleannot(boolean first)
Expects a boolean that does not match the given expectation.
static bytenot(byte first)
Expects a byte that does not match the given expectation.
static charnot(char first)
Expects a char that does not match the given expectation.
static doublenot(double first)
Expects a double that does not match the given expectation.
static floatnot(float first)
Expects a float that does not match the given expectation.
static intnot(int first)
Expects an int that does not match the given expectation.
static longnot(long first)
Expects a long that does not match the given expectation.
static shortnot(short first)
Expects a short that does not match the given expectation.
static <T> Tnot(T first)
Expects an Object that does not match the given expectation.
static <T> TnotNull()
Expects not null.
static booleanor(boolean first, boolean second)
Expects a boolean that matches one of the given expectations.
static byteor(byte first, byte second)
Expects a byte that matches one of the given expectations.
static charor(char first, char second)
Expects a char that matches one of the given expectations.
static doubleor(double first, double second)
Expects a double that matches one of the given expectations.
static floator(float first, float second)
Expects a float that matches one of the given expectations.
static intor(int first, int second)
Expects an int that matches one of the given expectations.
static longor(long first, long second)
Expects a long that matches one of the given expectations.
static shortor(short first, short second)
Expects a short that matches one of the given expectations.
static <T> Tor(T first, T second)
Expects an Object that matches one of the given expectations.
static voidreplay(Object... mocks)
Switches the given mock objects (more exactly: the controls of the mock objects) to replay mode.
static voidreportMatcher(IArgumentMatcher matcher)
Reports an argument matcher.
static voidreset(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock objects).
static voidresetToDefault(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 voidresetToNice(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 voidresetToStrict(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> Tsame(T value)
Expects an Object that is the same as the given value.
static StringsetEasyMockProperty(String key, String value)
Set a property to modify the default EasyMock behavior.
static StringstartsWith(String prefix)
Expects a string that starts with the given prefix.
static voidverify(Object... mocks)
Verifies the given mock objects (more exactly: the controls of the mock objects).

Field Detail

ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT

public static final 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 EasyMock method). Since EasyMock 2.5, this isn't the default anymore. For backward compatibility, this property can bring EasyMock 2.4 behavior back.

NOT_THREAD_SAFE_BY_DEFAULT

public static final String NOT_THREAD_SAFE_BY_DEFAULT
Since EasyMock 2.5, by default a mock is thread-safe. For backward compatibility, this property can change the default. A given mock still can be made thread-safe by calling EasyMock.

Constructor Detail

EasyMock

protected EasyMock()
Prevent instantiation but allow inheritance

Method Detail

and

public static boolean and(boolean first, boolean second)
Expects a boolean that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: false.

and

public static byte and(byte first, byte second)
Expects a byte that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static char and(char first, char second)
Expects a char that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static double and(double first, double second)
Expects a double that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static float and(float first, float second)
Expects a float that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static int and(int first, int second)
Expects an int that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static long and(long first, long second)
Expects a long that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static short and(short first, short second)
Expects a short that matches both given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

and

public static <T> T and(T first, T second)
Expects an Object that matches both given expectations.

Parameters: the type of the object, it is passed through to prevent casts. first placeholder for the first expectation. second placeholder for the second expectation.

Returns: null.

anyBoolean

public static boolean anyBoolean()
Expects any boolean argument. For details, see the EasyMock documentation.

Returns: false.

anyByte

public static byte anyByte()
Expects any byte argument. For details, see the EasyMock documentation.

Returns: 0.

anyChar

public static char anyChar()
Expects any char argument. For details, see the EasyMock documentation.

Returns: 0.

anyDouble

public static double anyDouble()
Expects any double argument. For details, see the EasyMock documentation.

Returns: 0.

anyFloat

public static float anyFloat()
Expects any float argument. For details, see the EasyMock documentation.

Returns: 0.

anyInt

public static int anyInt()
Expects any int argument. For details, see the EasyMock documentation.

Returns: 0.

anyLong

public static long anyLong()
Expects any long argument. For details, see the EasyMock documentation.

Returns: 0.

anyObject

public static <T> T anyObject()
Expects any Object argument. For details, see the EasyMock documentation.

Parameters: type of the method argument to match

Returns: null.

anyShort

public static short anyShort()
Expects any short argument. For details, see the EasyMock documentation.

Returns: 0.

aryEq

public static boolean[] aryEq(boolean[] value)
Expects a boolean array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static byte[] aryEq(byte[] value)
Expects a byte array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static char[] aryEq(char[] value)
Expects a char array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static double[] aryEq(double[] value)
Expects a double array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static float[] aryEq(float[] value)
Expects a float array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static int[] aryEq(int[] value)
Expects an int array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static long[] aryEq(long[] value)
Expects a long array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static short[] aryEq(short[] value)
Expects a short array that is equal to the given array, i.e. it has to have the same length, and each element has to be equal.

Parameters: value the given arry.

Returns: null.

aryEq

public static <T> T[] aryEq(T[] value)
Expects an Object array that is equal to the given array, i.e. it has to have the same type, length, and each element has to be equal.

Parameters: the type of the array, it is passed through to prevent casts. value the given arry.

Returns: null.

capture

public static <T> T capture(Capture<T> captured)
Expect any object but captures it for later use.

Parameters: Type of the captured object captured Where the parameter is captured

Returns: null

capture

public static int capture(Capture<Integer> captured)
Expect any int but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

capture

public static long capture(Capture<Long> captured)
Expect any long but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

capture

public static float capture(Capture<Float> captured)
Expect any float but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

capture

public static double capture(Capture<Double> captured)
Expect any double but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

capture

public static byte capture(Capture<Byte> captured)
Expect any byte but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

capture

public static char capture(Capture<Character> captured)
Expect any char but captures it for later use.

Parameters: captured Where the parameter is captured

Returns: 0

checkIsUsedInOneThread

public static void checkIsUsedInOneThread(Object mock, boolean shouldBeUsedInOneThread)
Tell that the mock should be used in only one thread. An exception will be thrown if that's not the case. This can be useful when mocking an object that isn't thread safe to make sure it is used correctly in a multithreaded environment. By default, no check is done unless ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT was set to true.

Parameters: mock the mock shouldBeUsedInOneThread If the mock should be used in only one thread

checkOrder

public 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. For details, see the EasyMock documentation.

Parameters: mock the mock object. state true switches order checking on, false switches it off.

cmp

public static <T> T cmp(T value, Comparator<? super T> comparator, LogicalOperator operator)
Expects an argument that will be compared using the provided comparator. The following comparison will take place:

comparator.compare(actual, expected) operator 0

For details, see the EasyMock documentation.

Parameters: type of the method argument to match value the given value. comparator Comparator used to compare the actual with expected value. operator The comparison operator.

Returns: null

cmpEq

public static <T extends Comparable<T>> T cmpEq(Comparable<T> value)
Expects a comparable argument equals to the given value according to their compareTo method. For details, see the EasMock documentation.

Parameters: type of the method argument to match value the given value.

Returns: null.

contains

public static String contains(String substring)
Expects a string that contains the given substring. For details, see the EasyMock documentation.

Parameters: substring the substring.

Returns: null.

createControl

public static IMocksControl createControl()
Creates a control, order checking is disabled by default.

Returns: the control.

createMock

public static <T> T createMock(Class<T> toMock)
Creates a mock object that implements the given interface, order checking is disabled by default.

Parameters: the interface that the mock object should implement. toMock the class of the interface that the mock object should implement.

Returns: the mock object.

createMock

public static <T> T createMock(String name, Class<T> toMock)
Creates a mock object that implements the given interface, order checking is disabled by default.

Parameters: name the name of the mock object. toMock the class of the interface that the mock object should implement. the interface that the mock object should implement.

Returns: the mock object.

Throws: IllegalArgumentException if the name is not a valid Java identifier.

createNiceControl

public 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.

Returns: the control.

createNiceMock

public static <T> T createNiceMock(Class<T> 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.

Parameters: the interface that the mock object should implement. toMock the class of the interface that the mock object should implement.

Returns: the mock object.

createNiceMock

public static <T> T createNiceMock(String name, Class<T> 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.

Parameters: name the name of the mock object. toMock the class of the interface that the mock object should implement. the interface that the mock object should implement.

Returns: the mock object.

Throws: IllegalArgumentException if the name is not a valid Java identifier.

createStrictControl

public static IMocksControl createStrictControl()
Creates a control, order checking is enabled by default.

Returns: the control.

createStrictMock

public static <T> T createStrictMock(Class<T> toMock)
Creates a mock object that implements the given interface, order checking is enabled by default.

Parameters: the interface that the mock object should implement. toMock the class of the interface that the mock object should implement.

Returns: the mock object.

createStrictMock

public static <T> T createStrictMock(String name, Class<T> toMock)
Creates a mock object that implements the given interface, order checking is enabled by default.

Parameters: name the name of the mock object. toMock the class of the interface that the mock object should implement. the interface that the mock object should implement.

Returns: the mock object.

Throws: IllegalArgumentException if the name is not a valid Java identifier.

endsWith

public static String endsWith(String suffix)
Expects a string that ends with the given suffix. For details, see the EasyMock documentation.

Parameters: suffix the suffix.

Returns: null.

eq

public static boolean eq(boolean value)
Expects a boolean that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static byte eq(byte value)
Expects a byte that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static char eq(char value)
Expects a char that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static double eq(double value)
Expects a double that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static float eq(float value)
Expects a float that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static int eq(int value)
Expects an int that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static long eq(long value)
Expects a long that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static short eq(short value)
Expects a short that is equal to the given value.

Parameters: value the given value.

Returns: 0.

eq

public static <T> T eq(T value)
Expects an Object that is equal to the given value.

Parameters: type of the method argument to match value the given value.

Returns: null.

eq

public 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. For details, see the EasyMock documentation.

Parameters: value the given value. delta the given delta.

Returns: 0.

eq

public 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. For details, see the EasyMock documentation.

Parameters: value the given value. delta the given delta.

Returns: 0.

expect

public static <T> IExpectationSetters<T> expect(T value)
Returns the expectation setter for the last expected invocation in the current thread.

Parameters: type returned by the expected method value 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").

Returns: the expectation setter.

expectLastCall

public static <T> IExpectationSetters<T> expectLastCall()
Returns the expectation setter for the last expected invocation in the current thread. This method is used for expected invocations on void methods.

Parameters: type returned by the expected method

Returns: the expectation setter.

find

public static String find(String regex)
Expects a string that contains a substring that matches the given regular expression. For details, see the EasyMock documentation.

Parameters: regex the regular expression.

Returns: null.

geq

public static <T extends Comparable<T>> T geq(Comparable<T> value)
Expects a comparable argument greater than or equal the given value. For details, see the EasyMock documentation.

Parameters: type of the method argument to match value the given value.

Returns: null.

geq

public static byte geq(byte value)
Expects a byte argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

geq

public static double geq(double value)
Expects a double argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

geq

public static float geq(float value)
Expects a float argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

geq

public static int geq(int value)
Expects an int argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

geq

public static long geq(long value)
Expects a long argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

geq

public static short geq(short value)
Expects a short argument greater than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

getCurrentArguments

public 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.

Returns: the arguments of the current mock method call.

Throws: IllegalStateException if called outside of IAnswer callbacks.

getEasyMockProperty

public static String getEasyMockProperty(String key)
Get the current value for an EasyMock property

Parameters: key key for the property

Returns: the property value

gt

public static <T extends Comparable<T>> T gt(Comparable<T> value)
Expects a comparable argument greater than the given value. For details, see the EasyMock documentation.

Parameters: type of the method argument to match value the given value.

Returns: null.

gt

public static byte gt(byte value)
Expects a byte argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

gt

public static double gt(double value)
Expects a double argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

gt

public static float gt(float value)
Expects a float argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

gt

public static int gt(int value)
Expects an int argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

gt

public static long gt(long value)
Expects a long argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

gt

public static short gt(short value)
Expects a short argument greater than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

isA

public static <T> T isA(Class<T> clazz)
Expects an object implementing the given class. For details, see the EasyMock documentation.

Parameters: the accepted type. clazz the class of the accepted type.

Returns: null.

isNull

public static <T> T isNull()
Expects null.

Parameters: type of the method argument to match

Returns: null.

leq

public static <T extends Comparable<T>> T leq(Comparable<T> value)
Expects a comparable argument less than or equal the given value. For details, see the EasyMock documentation.

Parameters: type of the method argument to match value the given value.

Returns: null.

leq

public static byte leq(byte value)
Expects a byte argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

leq

public static double leq(double value)
Expects a double argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

leq

public static float leq(float value)
Expects a float argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

leq

public static int leq(int value)
Expects an int argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

leq

public static long leq(long value)
Expects a long argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

leq

public static short leq(short value)
Expects a short argument less than or equal to the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static <T extends Comparable<T>> T lt(Comparable<T> value)
Expects a comparable argument less than the given value. For details, see the EasyMock documentation.

Parameters: type of the method argument to match value the given value.

Returns: null.

lt

public static byte lt(byte value)
Expects a byte argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static double lt(double value)
Expects a double argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static float lt(float value)
Expects a float argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static int lt(int value)
Expects an int argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static long lt(long value)
Expects a long argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

lt

public static short lt(short value)
Expects a short argument less than the given value. For details, see the EasyMock documentation.

Parameters: value the given value.

Returns: 0.

makeThreadSafe

public static void makeThreadSafe(Object mock, boolean threadSafe)
By default, a mock is thread safe (unless 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.

Parameters: mock the mock to make thread safe threadSafe If the mock should be thread safe or not

matches

public static String matches(String regex)
Expects a string that matches the given regular expression. For details, see the EasyMock documentation.

Parameters: regex the regular expression.

Returns: null.

not

public static boolean not(boolean first)
Expects a boolean that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: false.

not

public static byte not(byte first)
Expects a byte that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static char not(char first)
Expects a char that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static double not(double first)
Expects a double that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static float not(float first)
Expects a float that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static int not(int first)
Expects an int that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static long not(long first)
Expects a long that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static short not(short first)
Expects a short that does not match the given expectation.

Parameters: first placeholder for the expectation.

Returns: 0.

not

public static <T> T not(T first)
Expects an Object that does not match the given expectation.

Parameters: the type of the object, it is passed through to prevent casts. first placeholder for the expectation.

Returns: null.

notNull

public static <T> T notNull()
Expects not null.

Parameters: type of the method argument to match

Returns: null.

or

public static boolean or(boolean first, boolean second)
Expects a boolean that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: false.

or

public static byte or(byte first, byte second)
Expects a byte that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static char or(char first, char second)
Expects a char that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static double or(double first, double second)
Expects a double that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static float or(float first, float second)
Expects a float that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static int or(int first, int second)
Expects an int that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static long or(long first, long second)
Expects a long that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static short or(short first, short second)
Expects a short that matches one of the given expectations.

Parameters: first placeholder for the first expectation. second placeholder for the second expectation.

Returns: 0.

or

public static <T> T or(T first, T second)
Expects an Object that matches one of the given expectations.

Parameters: the type of the object, it is passed through to prevent casts. first placeholder for the first expectation. second placeholder for the second expectation.

Returns: null.

replay

public static void replay(Object... mocks)
Switches the given mock objects (more exactly: the controls of the mock objects) to replay mode. For details, see the EasyMock documentation.

Parameters: mocks the mock objects.

reportMatcher

public static void reportMatcher(IArgumentMatcher matcher)
Reports an argument matcher. This method is needed to define own argument matchers. For details, see the EasyMock documentation.

Parameters: matcher

reset

public static void reset(Object... mocks)
Resets the given mock objects (more exactly: the controls of the mock objects). For details, see the EasyMock documentation.

Parameters: mocks the mock objects.

resetToDefault

public 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. For details, see the EasyMock documentation.

Parameters: mocks the mock objects

resetToNice

public 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. For details, see the EasyMock documentation.

Parameters: mocks the mock objects

resetToStrict

public 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. For details, see the EasyMock documentation.

Parameters: mocks the mock objects

same

public static <T> T same(T value)
Expects an Object that is the same as the given value. For details, see the EasyMock documentation.

Parameters: the type of the object, it is passed through to prevent casts. value the given value.

Returns: null.

setEasyMockProperty

public static String setEasyMockProperty(String key, String value)
Set a property to modify the default EasyMock behavior. These properties can also be set as System properties or in easymock.properties. This method can then be called to overload them. For details and a list of available properties see the EasyMock documentation.

Note: This method is static. Setting a property will change the entire EasyMock behavior.

Parameters: key property key value property value. A null value will remove the property

Returns: the previous property value

startsWith

public static String startsWith(String prefix)
Expects a string that starts with the given prefix. For details, see the EasyMock documentation.

Parameters: prefix the prefix.

Returns: null.

verify

public static void verify(Object... mocks)
Verifies the given mock objects (more exactly: the controls of the mock objects).

Parameters: mocks the mock objects.

Copyright © 2001-2009 OFFIS, Tammo Freese, Henri Tremblay. This documentation is provided under the terms of the MIT licence.]]>