/* * Copyright 2001-2009 OFFIS, Tammo Freese * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.easymock; import java.lang.reflect.Proxy; import java.util.Comparator; import org.easymock.internal.*; import org.easymock.internal.matchers.*; public class EasyMock { /** * Since EasyMock 2.4, by default, a mock wasn't allowed to be called in * multiple threads unless it was made thread-safe (See * {@link #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 ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT = "easymock.enableThreadSafetyCheckByDefault"; /** * 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 * {@link #makeThreadSafe(Object, boolean)}. */ public static final String NOT_THREAD_SAFE_BY_DEFAULT = "easymock.notThreadSafeByDefault"; /** * Creates a mock object that implements the given interface, order checking * is enabled by default. * * @param * the interface that the mock object should implement. * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. */ public static T createStrictMock(Class toMock) { return createStrictControl().createMock(toMock); } /** * Creates a mock object that implements the given interface, order checking * is enabled by default. * @param name the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * @param * the interface that the mock object should implement. * @return the mock object. * @throws IllegalArgumentException if the name is not a valid Java identifier. */ public static T createStrictMock(String name, Class toMock) { return createStrictControl().createMock(name, toMock); } /** * Creates a mock object that implements the given interface, order checking * is disabled by default. * * @param * the interface that the mock object should implement. * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. */ public static T createMock(Class toMock) { return createControl().createMock(toMock); } /** * Creates a mock object that implements the given interface, order checking * is disabled by default. * @param name the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * * @param * the interface that the mock object should implement. * @return the mock object. * @throws IllegalArgumentException if the name is not a valid Java identifier. */ public static T createMock(String name, Class toMock) { return createControl().createMock(name, 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. * * @param * the interface that the mock object should implement. * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. */ public static T createNiceMock(Class toMock) { return createNiceControl().createMock(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. * @param name the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * * @param * the interface that the mock object should implement. * @return the mock object. * @throws IllegalArgumentException if the name is not a valid Java identifier. */ public static T createNiceMock(String name, Class toMock) { return createNiceControl().createMock(name, toMock); } /** * Creates a control, order checking is enabled by default. * * @return the control. */ public static IMocksControl createStrictControl() { return new MocksControl(MocksControl.MockType.STRICT); } /** * Creates a control, order checking is disabled by default. * * @return the control. */ public static IMocksControl createControl() { return new MocksControl(MocksControl.MockType.DEFAULT); } /** * 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. * * @return the control. */ public static IMocksControl createNiceControl() { return new MocksControl(MocksControl.MockType.NICE); } /** * Returns the expectation setter for the last expected invocation in the * current thread. * * @param type returned by the expected method * @param 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"). * * @return the expectation setter. */ public static IExpectationSetters expect(T value) { return EasyMock.getControlForLastCall(); } /** * Returns the expectation setter for the last expected invocation in the * current thread. This method is used for expected invocations on void * methods. * * @param type returned by the expected method * @return the expectation setter. */ public static IExpectationSetters expectLastCall() { return getControlForLastCall(); } @SuppressWarnings("unchecked") private static IExpectationSetters getControlForLastCall() { MocksControl lastControl = LastControl.lastControl(); if (lastControl == null) { throw new IllegalStateException("no last call on a mock available"); } return (IExpectationSetters) lastControl; } /** * Expects any boolean argument. For details, see the EasyMock * documentation. * * @return false. */ public static boolean anyBoolean() { reportMatcher(Any.ANY); return false; } /** * Expects any byte argument. For details, see the EasyMock documentation. * * @return 0. */ public static byte anyByte() { reportMatcher(Any.ANY); return 0; } /** * Expects any char argument. For details, see the EasyMock documentation. * * @return 0. */ public static char anyChar() { reportMatcher(Any.ANY); return 0; } /** * Expects any int argument. For details, see the EasyMock documentation. * * @return 0. */ public static int anyInt() { reportMatcher(Any.ANY); return 0; } /** * Expects any long argument. For details, see the EasyMock documentation. * * @return 0. */ public static long anyLong() { reportMatcher(Any.ANY); return 0; } /** * Expects any float argument. For details, see the EasyMock documentation. * * @return 0. */ public static float anyFloat() { reportMatcher(Any.ANY); return 0; } /** * Expects any double argument. For details, see the EasyMock documentation. * * @return 0. */ public static double anyDouble() { reportMatcher(Any.ANY); return 0; } /** * Expects any short argument. For details, see the EasyMock documentation. * * @return 0. */ public static short anyShort() { reportMatcher(Any.ANY); return 0; } /** * Expects any Object argument. For details, see the EasyMock documentation. * * @param type of the method argument to match * @return null. */ public static T anyObject() { reportMatcher(Any.ANY); return null; } /** * Expects a comparable argument greater than or equal the given value. For details, see * the EasyMock documentation. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static > T geq(Comparable value) { reportMatcher(new GreaterOrEqual(value)); return null; } /** * Expects a byte argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static byte geq(byte value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects a double argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static double geq(double value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects a float argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static float geq(float value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects an int argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static int geq(int value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects a long argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static long geq(long value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects a short argument greater than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static short geq(short value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * Expects a comparable argument less than or equal the given value. For details, see * the EasyMock documentation. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static > T leq(Comparable value) { reportMatcher(new LessOrEqual(value)); return null; } /** * Expects a byte argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static byte leq(byte value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects a double argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static double leq(double value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects a float argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static float leq(float value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects an int argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static int leq(int value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects a long argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static long leq(long value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects a short argument less than or equal to the given value. For * details, see the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static short leq(short value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * Expects a comparable argument greater than the given value. For details, see * the EasyMock documentation. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static > T gt(Comparable value) { reportMatcher(new GreaterThan(value)); return null; } /** * Expects a byte argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static byte gt(byte value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects a double argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static double gt(double value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects a float argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static float gt(float value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects an int argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static int gt(int value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects a long argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static long gt(long value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects a short argument greater than the given value. For details, see * the EasyMock documentation. * * @param value * the given value. * @return 0. */ public static short gt(short value) { reportMatcher(new GreaterThan(value)); return 0; } /** * Expects a comparable argument less than the given value. For details, see * the EasyMock documentation. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static > T lt(Comparable value) { reportMatcher(new LessThan(value)); return null; } /** * Expects a byte argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static byte lt(byte value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects a double argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static double lt(double value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects a float argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static float lt(float value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects an int argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static int lt(int value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects a long argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static long lt(long value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects a short argument less than the given value. For details, see the * EasyMock documentation. * * @param value * the given value. * @return 0. */ public static short lt(short value) { reportMatcher(new LessThan(value)); return 0; } /** * Expects an object implementing the given class. For details, see the * EasyMock documentation. * * @param * the accepted type. * @param clazz * the class of the accepted type. * @return null. */ public static T isA(Class clazz) { reportMatcher(new InstanceOf(clazz)); return null; } /** * Expects a string that contains the given substring. For details, see the * EasyMock documentation. * * @param substring * the substring. * @return null. */ public static String contains(String substring) { reportMatcher(new Contains(substring)); return null; } /** * Expects a boolean that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return false. */ public static boolean and(boolean first, boolean second) { LastControl.reportAnd(2); return false; } /** * Expects a byte that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static byte and(byte first, byte second) { LastControl.reportAnd(2); return 0; } /** * Expects a char that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static char and(char first, char second) { LastControl.reportAnd(2); return 0; } /** * Expects a double that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static double and(double first, double second) { LastControl.reportAnd(2); return 0; } /** * Expects a float that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static float and(float first, float second) { LastControl.reportAnd(2); return 0; } /** * Expects an int that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static int and(int first, int second) { LastControl.reportAnd(2); return 0; } /** * Expects a long that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static long and(long first, long second) { LastControl.reportAnd(2); return 0; } /** * Expects a short that matches both given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static short and(short first, short second) { LastControl.reportAnd(2); return 0; } /** * Expects an Object that matches both given expectations. * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return null. */ public static T and(T first, T second) { LastControl.reportAnd(2); return null; } /** * Expects a boolean that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return false. */ public static boolean or(boolean first, boolean second) { LastControl.reportOr(2); return false; } /** * Expects a byte that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static byte or(byte first, byte second) { LastControl.reportOr(2); return 0; } /** * Expects a char that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static char or(char first, char second) { LastControl.reportOr(2); return 0; } /** * Expects a double that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static double or(double first, double second) { LastControl.reportOr(2); return 0; } /** * Expects a float that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static float or(float first, float second) { LastControl.reportOr(2); return 0; } /** * Expects an int that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static int or(int first, int second) { LastControl.reportOr(2); return first; } /** * Expects a long that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static long or(long first, long second) { LastControl.reportOr(2); return 0; } /** * Expects a short that matches one of the given expectations. * * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return 0. */ public static short or(short first, short second) { LastControl.reportOr(2); return 0; } /** * Expects an Object that matches one of the given expectations. * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the first expectation. * @param second * placeholder for the second expectation. * @return null. */ public static T or(T first, T second) { LastControl.reportOr(2); return null; } /** * Expects a boolean that does not match the given expectation. * * @param first * placeholder for the expectation. * @return false. */ public static boolean not(boolean first) { LastControl.reportNot(); return false; } /** * Expects a byte that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static byte not(byte first) { LastControl.reportNot(); return 0; } /** * Expects a char that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static char not(char first) { LastControl.reportNot(); return 0; } /** * Expects a double that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static double not(double first) { LastControl.reportNot(); return 0; } /** * Expects a float that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static float not(float first) { LastControl.reportNot(); return first; } /** * Expects an int that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static int not(int first) { LastControl.reportNot(); return 0; } /** * Expects a long that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static long not(long first) { LastControl.reportNot(); return 0; } /** * Expects a short that does not match the given expectation. * * @param first * placeholder for the expectation. * @return 0. */ public static short not(short first) { LastControl.reportNot(); return 0; } /** * Expects an Object that does not match the given expectation. * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the expectation. * @return null. */ public static T not(T first) { LastControl.reportNot(); return null; } /** * Expects a boolean that is equal to the given value. * * @param value * the given value. * @return 0. */ public static boolean eq(boolean value) { reportMatcher(new Equals(value)); return false; } /** * Expects a byte that is equal to the given value. * * @param value * the given value. * @return 0. */ public static byte eq(byte value) { reportMatcher(new Equals(value)); return 0; } /** * Expects a char that is equal to the given value. * * @param value * the given value. * @return 0. */ public static char eq(char value) { reportMatcher(new Equals(value)); return 0; } /** * Expects a double that is equal to the given value. * * @param value * the given value. * @return 0. */ public static double eq(double value) { reportMatcher(new Equals(value)); return 0; } /** * Expects a float that is equal to the given value. * * @param value * the given value. * @return 0. */ public static float eq(float value) { reportMatcher(new Equals(value)); return 0; } /** * Expects an int that is equal to the given value. * * @param value * the given value. * @return 0. */ public static int eq(int value) { reportMatcher(new Equals(value)); return 0; } /** * Expects a long that is equal to the given value. * * @param value * the given value. * @return 0. */ public static long eq(long value) { reportMatcher(new Equals(value)); return 0; } /** * Expects a short that is equal to the given value. * * @param value * the given value. * @return 0. */ public static short eq(short value) { reportMatcher(new Equals(value)); return 0; } /** * Expects an Object that is equal to the given value. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static T eq(T value) { reportMatcher(new Equals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static boolean[] aryEq(boolean[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static byte[] aryEq(byte[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static char[] aryEq(char[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static double[] aryEq(double[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static float[] aryEq(float[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static int[] aryEq(int[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static long[] aryEq(long[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param value * the given arry. * @return null. */ public static short[] aryEq(short[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. * * @param * the type of the array, it is passed through to prevent casts. * @param value * the given arry. * @return null. */ public static T[] aryEq(T[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * Expects null. * * @param type of the method argument to match * @return null. */ public static T isNull() { reportMatcher(Null.NULL); return null; } /** * Expects not null. * * @param type of the method argument to match * @return null. */ public static T notNull() { reportMatcher(NotNull.NOT_NULL); return null; } /** * Expects a string that contains a substring that matches the given regular * expression. For details, see the EasyMock documentation. * * @param regex * the regular expression. * @return null. */ public static String find(String regex) { reportMatcher(new Find(regex)); return null; } /** * Expects a string that matches the given regular expression. For details, * see the EasyMock documentation. * * @param regex * the regular expression. * @return null. */ public static String matches(String regex) { reportMatcher(new Matches(regex)); return null; } /** * Expects a string that starts with the given prefix. For details, see the * EasyMock documentation. * * @param prefix * the prefix. * @return null. */ public static String startsWith(String prefix) { reportMatcher(new StartsWith(prefix)); return null; } /** * Expects a string that ends with the given suffix. For details, see the * EasyMock documentation. * * @param suffix * the suffix. * @return null. */ public static String endsWith(String suffix) { reportMatcher(new EndsWith(suffix)); return null; } /** * 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. * * @param value * the given value. * @param delta * the given delta. * @return 0. */ public static double eq(double value, double delta) { reportMatcher(new EqualsWithDelta(value, delta)); return 0; } /** * 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. * * @param value * the given value. * @param delta * the given delta. * @return 0. */ public static float eq(float value, float delta) { reportMatcher(new EqualsWithDelta(value, delta)); return 0; } /** * Expects an Object that is the same as the given value. For details, see * the EasyMock documentation. * * @param * the type of the object, it is passed through to prevent casts. * @param value * the given value. * @return null. */ public static T same(T value) { reportMatcher(new Same(value)); return null; } /** * Expects a comparable argument equals to the given value according to their * compareTo method. For details, see the EasMock documentation. * * @param type of the method argument to match * @param value * the given value. * @return null. */ public static > T cmpEq(Comparable value) { reportMatcher(new CompareEqual(value)); return null; } /** * 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. * * @param type of the method argument to match * @param value the given value. * @param comparator Comparator used to compare the actual with expected value. * @param operator The comparison operator. * @return null */ public static T cmp(T value, Comparator comparator, LogicalOperator operator) { reportMatcher(new Compare(value, comparator, operator)); return null; } /** * Expects a byte that is equal to the given value. * * @param value * the given value. * @return 0. */ /** * Expect any object but captures it for later use. * * @param Type of the captured object * @param captured Where the parameter is captured * @return null */ public static T capture(Capture captured) { reportMatcher(new Captures(captured)); return null; } /****************************************************** * ANDROID CHANGE - comment out to fix compile error * name clash: capture(org.easymock.Capture) and * capture(org.easymock.Capture) have the same erasure */ /** * Expect any int but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static int capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /** * Expect any long but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static long capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /** * Expect any float but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static float capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /** * Expect any double but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static double capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /** * Expect any byte but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static byte capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /** * Expect any char but captures it for later use. * * @param captured Where the parameter is captured * @return 0 */ // public static char capture(Capture captured) { // reportMatcher(new Captures(captured)); // return 0; // } /********** END ANDROID CHANGE **********/ /** * Switches the given mock objects (more exactly: the controls of the mock * objects) to replay mode. For details, see the EasyMock documentation. * * @param mocks * the mock objects. */ public static void replay(Object... mocks) { for (Object mock : mocks) { getControl(mock).replay(); } } /** * Resets the given mock objects (more exactly: the controls of the mock * objects). For details, see the EasyMock documentation. * * @param mocks * the mock objects. */ public static void reset(Object... mocks) { for (Object mock : mocks) { getControl(mock).reset(); } } /** * 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. * * @param mocks * the mock objects */ public static void resetToNice(Object... mocks) { for (Object mock : mocks) { getControl(mock).resetToNice(); } } /** * 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. * * @param mocks * the mock objects */ public static void resetToDefault(Object... mocks) { for (Object mock : mocks) { getControl(mock).resetToDefault(); } } /** * 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. * * @param mocks * the mock objects */ public static void resetToStrict(Object... mocks) { for (Object mock : mocks) { getControl(mock).resetToStrict(); } } /** * Verifies the given mock objects (more exactly: the controls of the mock * objects). * * @param mocks * the mock objects. */ public static void verify(Object... mocks) { for (Object mock : mocks) { getControl(mock).verify(); } } /** * 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. * * @param mock * the mock object. * @param state * true switches order checking on, * false switches it off. */ public static void checkOrder(Object mock, boolean state) { getControl(mock).checkOrder(state); } /** * Reports an argument matcher. This method is needed to define own argument * matchers. For details, see the EasyMock documentation. * * @param matcher */ public static void reportMatcher(IArgumentMatcher matcher) { LastControl.reportMatcher(matcher); } private static MocksControl getControl(Object mock) { return ((ObjectMethodsFilter) Proxy .getInvocationHandler(mock)).getDelegate().getControl(); } /** * 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. * * @return the arguments of the current mock method call. * @throws IllegalStateException * if called outside of IAnswer callbacks. */ public static Object[] getCurrentArguments() { Invocation result = LastControl.getCurrentInvocation(); if (result == null) { throw new IllegalStateException( "current arguments are only available when executing callback methods"); } return result.getArguments(); } /** * By default, a mock is thread safe (unless * {@link #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. * * @param mock * the mock to make thread safe * @param threadSafe * If the mock should be thread safe or not */ public static void makeThreadSafe(Object mock, boolean threadSafe) { getControl(mock).makeThreadSafe(threadSafe); } /** * 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 * {@link #ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT} was set to true. * * @param mock * the mock * @param shouldBeUsedInOneThread * If the mock should be used in only one thread */ public static void checkIsUsedInOneThread(Object mock, boolean shouldBeUsedInOneThread) { getControl(mock).checkIsUsedInOneThread(shouldBeUsedInOneThread); } /** * Get the current value for an EasyMock property * * @param key * key for the property * @return the property value */ public static String getEasyMockProperty(String key) { return EasyMockProperties.getInstance().getProperty(key); } /** * 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. * * @param key * property key * @param value * property value. A null value will remove the property * @return the previous property value */ public static String setEasyMockProperty(String key, String value) { return EasyMockProperties.getInstance().setProperty(key, value); } // ///CLOVER:OFF /** Prevent instantiation but allow inheritance */ protected EasyMock() { } // ///CLOVER:ON }