1/*
2 *  Copyright 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.google.android.testing.mocking;
17
18import org.easymock.Capture;
19import org.easymock.EasyMock;
20import org.easymock.IArgumentMatcher;
21import org.easymock.IExpectationSetters;
22import org.easymock.LogicalOperator;
23
24import java.lang.reflect.Constructor;
25import java.lang.reflect.InvocationTargetException;
26import java.lang.reflect.Method;
27import java.util.ArrayList;
28import java.util.Comparator;
29import java.util.List;
30
31/**
32 * Android Mock is a wrapper for EasyMock (2.4) which allows for real Class mocking on
33 * an Android (Dalvik) VM.
34 *
35 * All methods on Android Mock are syntactically equivalent to EasyMock method
36 * calls, and will delegate calls to EasyMock, while performing the required
37 * transformations to avoid Dalvik VM troubles.
38 *
39 * Calls directly to EasyMock will work correctly only if the Class being mocked
40 * is in fact an Interface. Calls to Android Mock will work correctly for both
41 * Interfaces and concrete Classes.
42 *
43 * Android Mock requires that the code being mocked be instrumented prior to
44 * loading to the Dalvik VM by having called the MockGenerator.jar file. Try
45 * running {@code java -jar MockGenerator.jar --help} for more information.
46 *
47 * An example usage pattern is:
48 *
49 * {@code @UsesMocks(MyClass.class) public void testFoo() { MyClass
50 * mockObject = AndroidMock.createMock(MyClass.class);
51 * AndroidMock.expect(mockObject.foo(0)).andReturn(42);
52 * AndroidMock.replay(mockObject); assertEquals(42, mockObject.foo(0));
53 * AndroidMock.verify(mockObject); } * }
54 *
55 *
56 * <b>A note about parameter and return types for the <i>expects</i> style of methods.</b>
57 * The various expectation methods such as {@link #eq(boolean)}, {@link #and(boolean, boolean)},
58 * and {@link #leq(byte)} all have nonsense return values. Each of the expectation methods may only
59 * be executed under strict conditions (in order to set expectations of incoming method parameters
60 * during record mode) and thus their return types are in fact never used. The return types are set
61 * only to satisfy the compile-time parameter requirements of the methods being mocked in order to
62 * allow code such as: {@code mockObject.doFoo(anyInt());}. If {@link #anyInt()} did not return
63 * {@code int} then the compiler would not accept the preceding code fragment.
64 *
65 * Similarly, the complex expectation methods ({@code #and}, {@code #or}, and {@code not}) take
66 * various parameter types, but will throw an {@link java.lang.IllegalStateException} if anything
67 * other than an expectation method is provided.  E.g. {@code mockObject.doFoo(and(gt(5), lt(10));}
68 *
69 * The benefit of this is to make it very easy to read the test code after it has been written.
70 * Additionally, the test code is protected by type safety at compile time.
71 *
72 * The downside of this is that when writing the test code in the record phase, how to use the
73 * expectation APIs is not made clear by the method signatures of these expectation methods. In
74 * particular, it's not at all clear that {@link #and(byte, byte)} takes as parameters other
75 * expectation methods, and not just any random method that returns a {@literal byte} or even a
76 * {@literal byte} literal.
77 *
78 * @author swoodward@google.com (Stephen Woodward)
79 */
80public class AndroidMock {
81  private AndroidMock() {
82  }
83
84  /**
85   * Creates a mock object for the specified class, order checking
86   * is enabled by default. The difference between a strict mock and a normal mock is that a strict
87   * mock will not allow for invocations of the mock object to occur other than in the exact order
88   * specified during record mode.
89   *
90   * The parameter {@literal args} allows the caller to choose which constructor on the Class
91   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
92   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
93   * the caller to make calls such as {@literal createStrictMock(MyObject.class, 42, "hello!")},
94   * where {@literal MyObject} defines a constructor such as
95   * {@literal public MyObject(int answer, String greeting)}.
96   *
97   * @param <T> the class type to be mocked.
98   * @param toMock the class of the object to be mocked.
99   * @param args the arguments to pass to the constructor.
100   * @return the mock object.
101   */
102  public static <T> T createStrictMock(Class<T> toMock, Object... args) {
103    return createStrictMock(null, toMock, args);
104  }
105
106  /**
107   * Creates a mock object for the specified class, order checking
108   * is enabled by default. The difference between a strict mock and a normal mock is that a strict
109   * mock will not allow for invocations of the mock object to occur other than in the exact order
110   * specified during record mode.
111   *
112   * The parameter {@literal args} allows the caller to choose which constructor on the Class
113   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
114   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
115   * the caller to make calls such as
116   * {@literal createStrictMock("NameMyMock", MyObject.class, 42, "hello!")},
117   * where {@literal MyObject} defines a constructor such as
118   * {@literal public MyObject(int answer, String greeting)}.
119   *
120   * @param <T> the class type to be mocked.
121   * @param name the name of the mock object. This must be a valid Java identifier. This value is
122   * used as the return value from {@link #toString()} when invoked on the mock object.
123   * @param toMock the class of the object to be mocked.
124   * @param args the arguments to pass to the constructor.
125   * @return the mock object.
126   * @throws IllegalArgumentException if the name is not a valid Java identifier.
127   */
128  @SuppressWarnings("cast")
129  public static <T> T createStrictMock(String name, Class<T> toMock, Object... args) {
130    if (toMock.isInterface()) {
131      return EasyMock.createStrictMock(name, toMock);
132    }
133    Object mockedInterface = EasyMock.createStrictMock(name, getInterfaceFor(toMock));
134    return (T) getSubclassFor(toMock, getInterfaceFor(toMock), mockedInterface, args);
135  }
136
137  /**
138   * Creates a mock object for the specified class, order checking
139   * is disabled by default. A normal mock with order checking disabled will allow you to record
140   * the method invocations during record mode in any order. If order is important, use
141   * {@link #createStrictMock(Class, Object...)} instead.
142   *
143   * The parameter {@literal args} allows the caller to choose which constructor on the Class
144   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
145   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
146   * the caller to make calls such as
147   * {@literal createMock(MyObject.class, 42, "hello!")},
148   * where {@literal MyObject} defines a constructor such as
149   * {@literal public MyObject(int answer, String greeting)}.
150   *
151   * @param <T> the type of the class to be mocked.
152   * @param toMock the class object representing the class to be mocked.
153   * @param args the arguments to pass to the constructor.
154   * @return the mock object.
155   */
156  public static <T> T createMock(Class<T> toMock, Object... args) {
157    return createMock(null, toMock, args);
158  }
159
160  /**
161   * Creates a mock object for the specified class, order checking
162   * is disabled by default. A normal mock with order checking disabled will allow you to record
163   * the method invocations during record mode in any order. If order is important, use
164   * {@link #createStrictMock(Class, Object...)} instead.
165   *
166   * The parameter {@literal args} allows the caller to choose which constructor on the Class
167   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
168   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
169   * the caller to make calls such as
170   * {@literal createMock("NameMyMock", MyObject.class, 42, "hello!")},
171   * where {@literal MyObject} defines a constructor such as
172   * {@literal public MyObject(int answer, String greeting)}.
173   *
174   * @param <T> the type of the class to be mocked.
175   * @param name the name of the mock object. This must be a valid Java identifier. This value is
176   * used as the return value from {@link #toString()} when invoked on the mock object.
177   * @param toMock the class object representing the class to be mocked.
178   * @param args the arguments to pass to the constructor.
179   * @return the mock object.
180   * @throws IllegalArgumentException if the name is not a valid Java identifier.
181   */
182  @SuppressWarnings("cast")
183  public static <T> T createMock(String name, Class<T> toMock, Object... args) {
184    if (toMock.isInterface()) {
185      return EasyMock.createMock(name, toMock);
186    }
187    Object mockedInterface = EasyMock.createMock(name, getInterfaceFor(toMock));
188    return (T) getSubclassFor(toMock, getInterfaceFor(toMock), mockedInterface, args);
189  }
190
191  /**
192   * Creates a mock object for the specified class, order checking
193   * is disabled by default, and the mock object will return {@code 0},
194   * {@code null} or {@code false} for unexpected invocations.
195   *
196   * The parameter {@literal args} allows the caller to choose which constructor on the Class
197   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
198   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
199   * the caller to make calls such as
200   * {@literal createNiceMock(MyObject.class, 42, "hello!")},
201   * where {@literal MyObject} defines a constructor such as
202   * {@literal public MyObject(int answer, String greeting)}.
203   *
204   * @param <T> the type of the class to be mocked.
205   * @param toMock the class object representing the class to be mocked.
206   * @param args the arguments to pass to the constructor.
207   * @return the mock object.
208   */
209  public static <T> T createNiceMock(Class<T> toMock, Object... args) {
210    return createNiceMock(null, toMock, args);
211  }
212
213  /**
214   * Creates a mock object for the specified class, order checking
215   * is disabled by default, and the mock object will return {@code 0},
216   * {@code null} or {@code false} for unexpected invocations.
217   *
218   * The parameter {@literal args} allows the caller to choose which constructor on the Class
219   * specified by {@literal toMock} to be called when constructing the Mock object. If a constructor
220   * takes primitive values, Java Auto-boxing/unboxing will take care of it automatically, allowing
221   * the caller to make calls such as
222   * {@literal createNiceMock("NameMyMock", MyObject.class, 42, "hello!")},
223   * where {@literal MyObject} defines a constructor such as
224   * {@literal public MyObject(int answer, String greeting)}.
225   *
226   * @param <T> the type of the class to be mocked.
227   * @param name the name of the mock object. This must be a valid Java identifier. This value is
228   * used as the return value from {@link #toString()} when invoked on the mock object.
229   * @param toMock the class object representing the class to be mocked.
230   * @param args the arguments to pass to the constructor.
231   * @throws IllegalArgumentException if the name is not a valid Java identifier.
232   */
233  @SuppressWarnings("cast")
234  public static <T> T createNiceMock(String name, Class<T> toMock, Object... args) {
235    if (toMock.isInterface()) {
236      return EasyMock.createNiceMock(name, toMock);
237    }
238    Object mockedInterface = EasyMock.createNiceMock(name, getInterfaceFor(toMock));
239    return (T) getSubclassFor(toMock, getInterfaceFor(toMock), mockedInterface, args);
240  }
241
242  /**
243   * Returns the expectation setter for the last expected invocation in the current thread.
244   * Expectation setters are used during the recording phase to specify what method calls
245   * will be expected during the replay phase, and with which parameters. Parameters may be
246   * specified as literal values (e.g. {@code expect(mock.foo(42));  expect(mock.foo("hello"));})
247   * or according to parameter expectation criteria. Some examples of parameter expectation
248   * criteria include {@link #anyObject()}, {@link #leq(int)}, {@link #contains(String)},
249   * {@link #isA(Class)} and also the more complex {@link #and(char, char)},
250   * {@link #or(boolean, boolean)}, and {@link #not(double)}.
251   *
252   * An {@link org.easymock.IExpectationSetters} object has methods which allow you to define
253   * the expected behaviour of the mocked method and the expected number of invocations,
254   * e.g. {@link org.easymock.IExpectationSetters#andReturn(Object)},
255   * {@link org.easymock.IExpectationSetters#andThrow(Throwable)}, and
256   * {@link org.easymock.IExpectationSetters#atLeastOnce()}.
257   *
258   * @param expectedValue the parameter is used to transport the type to the ExpectationSetter.
259   * It allows writing the expected call as an argument,
260   * e.g. {@code expect(mock.getName()).andReturn("John Doe")}.
261   * @return the expectation setter.
262   */
263  public static <T> IExpectationSetters<T> expect(T expectedValue) {
264    return EasyMock.expect(expectedValue);
265  }
266
267  /**
268   * Returns the expectation setter for the last expected invocation in the
269   * current thread. This method is used for expected invocations on void
270   * methods. Use this for things such as
271   * {@link org.easymock.IExpectationSetters#andThrow(Throwable)}
272   * on void methods.
273   * E.g.
274   * {@code mock.doFoo();
275   * AndroidMock.expectLastCall().andThrow(new IllegalStateException());}
276   *
277   * @see #expect(Object) for more details about {@link org.easymock.IExpectationSetters}
278   * @return the expectation setter.
279   */
280  public static <T> IExpectationSetters<T> expectLastCall() {
281    return EasyMock.expectLastCall();
282  }
283
284  /**
285   * Expects any {@code boolean} argument as a parameter to a mocked method.
286   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
287   *
288   * If this method is used for anything other than to set a parameter expectation as part of a
289   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
290   *
291   * E.g.
292   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyBoolean())).andReturn("hello world");}
293   *
294   * @return {@code false}. The return value is always ignored.
295   */
296  public static boolean anyBoolean() {
297    return EasyMock.anyBoolean();
298  }
299
300  /**
301   * Expects any {@code byte} argument as a parameter to a mocked method.
302   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
303   *
304   * If this method is used for anything other than to set a parameter expectation as part of a
305   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
306   *
307   * E.g.
308   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyByte())).andReturn("hello world");}
309   *
310   * @return {@code 0}. The return value is always ignored.
311   */
312  public static byte anyByte() {
313    return EasyMock.anyByte();
314  }
315
316  /**
317   * Expects any {@code char} argument as a parameter to a mocked method.
318   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
319   *
320   * If this method is used for anything other than to set a parameter expectation as part of a
321   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
322   *
323   * E.g.
324   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyChar())).andReturn("hello world");}
325   *
326   * @return {@code 0}. The return value is always ignored.
327   */
328  public static char anyChar() {
329    return EasyMock.anyChar();
330  }
331
332  /**
333   * Expects any {@code int} argument as a parameter to a mocked method.
334   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
335   *
336   * If this method is used for anything other than to set a parameter expectation as part of a
337   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
338   *
339   * E.g.
340   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyInt())).andReturn("hello world");}
341   *
342   * @return {@code 0}. The return value is always ignored.
343   */
344  public static int anyInt() {
345    return EasyMock.anyInt();
346  }
347
348  /**
349   * Expects any {@code long} argument as a parameter to a mocked method.
350   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
351   *
352   * If this method is used for anything other than to set a parameter expectation as part of a
353   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
354   *
355   * E.g.
356   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyLong())).andReturn("hello world");}
357   *
358   * @return {@code 0}. The return value is always ignored.
359   */
360  public static long anyLong() {
361    return EasyMock.anyLong();
362  }
363
364  /**
365   * Expects any {@code float} argument as a parameter to a mocked method.
366   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
367   *
368   * If this method is used for anything other than to set a parameter expectation as part of a
369   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
370   *
371   * E.g.
372   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyFloat())).andReturn("hello world");}
373   *
374   * @return {@code 0}. The return value is always ignored.
375   */
376  public static float anyFloat() {
377    return EasyMock.anyFloat();
378  }
379
380  /**
381   * Expects any {@code double} argument as a parameter to a mocked method.
382   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
383   *
384   * If this method is used for anything other than to set a parameter expectation as part of a
385   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
386   *
387   * E.g.
388   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyDouble())).andReturn("hello world");}
389   *
390   * @return {@code 0}. The return value is always ignored.   */
391  public static double anyDouble() {
392    return EasyMock.anyDouble();
393  }
394
395  /**
396   * Expects any {@code short} argument as a parameter to a mocked method.
397   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
398   *
399   * If this method is used for anything other than to set a parameter expectation as part of a
400   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
401   *
402   * E.g.
403   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyShort())).andReturn("hello world");}
404   *
405   * @return {@code 0}. The return value is always ignored.   */
406  public static short anyShort() {
407    return EasyMock.anyShort();
408  }
409
410  /**
411   * Expects any {@code java.lang.Object} (or subclass) argument as a parameter to a mocked method.
412   * Note that this includes Arrays (since an array {@literal is an Object})
413   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
414   *
415   * If this method is used for anything other than to set a parameter expectation as part of a
416   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
417   *
418   * E.g.
419   * {@code AndroidMock.expect(mock.getString(AndroidMock.anyLong())).andReturn("hello world");}
420   *
421   * @return {@code 0}. The return value is always ignored.
422   */
423  @SuppressWarnings("unchecked")
424  public static <T> T anyObject() {
425    return (T) EasyMock.anyObject();
426  }
427
428  /**
429   * Expects a {@code Comparable} argument greater than or equal to the given value as a parameter
430   * to a mocked method.
431   *
432   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
433   *
434   * If this method is used for anything other than to set a parameter expectation as part of a
435   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
436   *
437   * E.g.
438   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq("hi"))).andReturn("hello");}
439   *
440   * @param expectedValue the value to which the specified incoming parameter to the mocked method
441   * must be greater than or equal.
442   * @return {@code null}. The return value is always ignored.
443   */
444  public static <T extends Comparable<T>> T geq(Comparable<T> expectedValue) {
445    return EasyMock.geq(expectedValue);
446  }
447
448  /**
449   * Expects a {@code byte} argument greater than or equal to the given value as a parameter
450   * to a mocked method.
451   *
452   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
453   *
454   * If this method is used for anything other than to set a parameter expectation as part of a
455   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
456   *
457   * E.g.
458   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq((byte)42))).andReturn("hello");}
459   *
460   * @param expectedValue the value to which the specified incoming parameter to the mocked method
461   * must be greater than or equal.
462   * @return {@code 0}. The return value is always ignored.
463   */
464  public static byte geq(byte expectedValue) {
465    return EasyMock.geq(expectedValue);
466  }
467
468  /**
469   * Expects a {@code double} argument greater than or equal to the given value as a parameter
470   * to a mocked method.
471   *
472   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
473   *
474   * If this method is used for anything other than to set a parameter expectation as part of a
475   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
476   *
477   * E.g.
478   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq(42.0))).andReturn("hello");}
479   *
480   * @param expectedValue the value to which the specified incoming parameter to the mocked method
481   * must be greater than or equal.
482   * @return {@code 0}. The return value is always ignored.
483   */
484  public static double geq(double expectedValue) {
485    return EasyMock.geq(expectedValue);
486  }
487
488  /**
489   * Expects a {@code float} argument greater than or equal to the given value as a parameter
490   * to a mocked method.
491   *
492   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
493   *
494   * If this method is used for anything other than to set a parameter expectation as part of a
495   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
496   *
497   * E.g.
498   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq(42.0f))).andReturn("hello");}
499   *
500   * @param expectedValue the value to which the specified incoming parameter to the mocked method
501   * must be greater than or equal.
502   * @return {@code 0}. The return value is always ignored.
503   */
504  public static float geq(float expectedValue) {
505    return EasyMock.geq(expectedValue);
506  }
507
508  /**
509   * Expects an {@code int} argument greater than or equal to the given value as a parameter
510   * to a mocked method.
511   *
512   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
513   *
514   * If this method is used for anything other than to set a parameter expectation as part of a
515   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
516   *
517   * E.g.
518   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq(42))).andReturn("hello");}
519   *
520   * @param expectedValue the value to which the specified incoming parameter to the mocked method
521   * must be greater than or equal.
522   * @return {@code 0}. The return value is always ignored.
523   */
524  public static int geq(int expectedValue) {
525    return EasyMock.geq(expectedValue);
526  }
527
528  /**
529   * Expects a {@code long} argument greater than or equal to the given value as a parameter
530   * to a mocked method.
531   *
532   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
533   *
534   * If this method is used for anything other than to set a parameter expectation as part of a
535   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
536   *
537   * E.g.
538   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq(42l))).andReturn("hello");}
539   *
540   * @param expectedValue the value to which the specified incoming parameter to the mocked method
541   * must be greater than or equal.
542   * @return {@code 0}. The return value is always ignored.
543   */
544  public static long geq(long expectedValue) {
545    return EasyMock.geq(expectedValue);
546  }
547
548  /**
549   * Expects a {@code short} argument greater than or equal to the given value as a parameter
550   * to a mocked method.
551   *
552   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
553   *
554   * If this method is used for anything other than to set a parameter expectation as part of a
555   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
556   *
557   * E.g.
558   * {@code AndroidMock.expect(mock.getString(AndroidMock.geq((short)42))).andReturn("hello");}
559   *
560   * @param expectedValue the value to which the specified incoming parameter to the mocked method
561   * must be greater than or equal.
562   * @return {@code 0}. The return value is always ignored.
563   */
564  public static short geq(short expectedValue) {
565    return EasyMock.geq(expectedValue);
566  }
567
568  /**
569   * Expects a {@code Comparable} argument less than or equal to the given value as a parameter
570   * to a mocked method.
571   *
572   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
573   *
574   * If this method is used for anything other than to set a parameter expectation as part of a
575   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
576   *
577   * E.g.
578   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq("hi"))).andReturn("hello");}
579   *
580   * @param expectedValue the value to which the specified incoming parameter to the mocked method
581   * must be less than or equal.
582   * @return {@code null}. The return value is always ignored.
583   */
584  public static <T extends Comparable<T>> T leq(Comparable<T> expectedValue) {
585    return EasyMock.leq(expectedValue);
586  }
587
588  /**
589   * Expects a {@code byte} argument less than or equal to the given value as a parameter
590   * to a mocked method.
591   *
592   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
593   *
594   * If this method is used for anything other than to set a parameter expectation as part of a
595   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
596   *
597   * E.g.
598   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq((byte)42))).andReturn("hello");}
599   *
600   * @param expectedValue the value to which the specified incoming parameter to the mocked method
601   * must be less than or equal.
602   * @return {@code 0}. The return value is always ignored.
603   */
604  public static byte leq(byte expectedValue) {
605    return EasyMock.leq(expectedValue);
606  }
607
608  /**
609   * Expects a {@code double} argument less than or equal to the given value as a parameter
610   * to a mocked method.
611   *
612   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
613   *
614   * If this method is used for anything other than to set a parameter expectation as part of a
615   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
616   *
617   * E.g.
618   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq(42.0))).andReturn("hello");}
619   *
620   * @param expectedValue the value to which the specified incoming parameter to the mocked method
621   * must be less than or equal.
622   * @return {@code 0}. The return value is always ignored.
623   */
624  public static double leq(double expectedValue) {
625    return EasyMock.leq(expectedValue);
626  }
627
628  /**
629   * Expects a {@code float} argument less than or equal to the given value as a parameter
630   * to a mocked method.
631   *
632   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
633   *
634   * If this method is used for anything other than to set a parameter expectation as part of a
635   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
636   *
637   * E.g.
638   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq(42.0f))).andReturn("hello");}
639   *
640   * @param expectedValue the value to which the specified incoming parameter to the mocked method
641   * must be less than or equal.
642   * @return {@code 0}. The return value is always ignored.
643   */
644  public static float leq(float expectedValue) {
645    return EasyMock.leq(expectedValue);
646  }
647
648  /**
649   * Expects an {@code int} argument less than or equal to the given value as a parameter
650   * to a mocked method.
651   *
652   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
653   *
654   * If this method is used for anything other than to set a parameter expectation as part of a
655   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
656   *
657   * E.g.
658   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq(42))).andReturn("hello");}
659   *
660   * @param expectedValue the value to which the specified incoming parameter to the mocked method
661   * must be less than or equal.
662   * @return {@code 0}. The return value is always ignored.
663   */
664  public static int leq(int expectedValue) {
665    return EasyMock.leq(expectedValue);
666  }
667
668  /**
669   * Expects a {@code long} argument less than or equal to the given value as a parameter
670   * to a mocked method.
671   *
672   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
673   *
674   * If this method is used for anything other than to set a parameter expectation as part of a
675   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
676   *
677   * E.g.
678   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq(42l))).andReturn("hello");}
679   *
680   * @param expectedValue the value to which the specified incoming parameter to the mocked method
681   * must be less than or equal.
682   * @return {@code 0}. The return value is always ignored.
683   */
684  public static long leq(long expectedValue) {
685    return EasyMock.leq(expectedValue);
686  }
687
688  /**
689   * Expects a {@code short} argument less than or equal to the given value as a parameter
690   * to a mocked method.
691   *
692   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
693   *
694   * If this method is used for anything other than to set a parameter expectation as part of a
695   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
696   *
697   * E.g.
698   * {@code AndroidMock.expect(mock.getString(AndroidMock.leq((short)42))).andReturn("hello");}
699   *
700   * @param expectedValue the value to which the specified incoming parameter to the mocked method
701   * must be less than or equal.
702   * @return {@code 0}. The return value is always ignored.
703   */
704  public static short leq(short expectedValue) {
705    return EasyMock.leq(expectedValue);
706  }
707
708  /**
709   * Expects a {@code Comparable} argument greater than the given value as a parameter
710   * to a mocked method.
711   *
712   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
713   *
714   * If this method is used for anything other than to set a parameter expectation as part of a
715   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
716   *
717   * E.g.
718   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt("hi"))).andReturn("hello");}
719   *
720   * @param expectedValue the value to which the specified incoming parameter to the mocked method
721   * must be greater than.
722   * @return {@code null}. The return value is always ignored.
723   */
724  public static <T extends Comparable<T>> T gt(Comparable<T> expectedValue) {
725    return EasyMock.gt(expectedValue);
726  }
727
728  /**
729   * Expects a {@code byte} argument greater than the given value as a parameter
730   * to a mocked method.
731   *
732   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
733   *
734   * If this method is used for anything other than to set a parameter expectation as part of a
735   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
736   *
737   * E.g.
738   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt((byte)42))).andReturn("hello");}
739   *
740   * @param expectedValue the value to which the specified incoming parameter to the mocked method
741   * must be greater than.
742   * @return {@code 0}. The return value is always ignored.
743   */
744  public static byte gt(byte expectedValue) {
745    return EasyMock.gt(expectedValue);
746  }
747
748  /**
749   * Expects a {@code double} argument greater than the given value as a parameter
750   * to a mocked method.
751   *
752   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
753   *
754   * If this method is used for anything other than to set a parameter expectation as part of a
755   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
756   *
757   * E.g.
758   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt(42.0))).andReturn("hello");}
759   *
760   * @param expectedValue the value to which the specified incoming parameter to the mocked method
761   * must be greater than.
762   * @return {@code 0}. The return value is always ignored.
763   */
764  public static double gt(double expectedValue) {
765    return EasyMock.gt(expectedValue);
766  }
767
768  /**
769   * Expects a {@code float} argument greater than the given value as a parameter
770   * to a mocked method.
771   *
772   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
773   *
774   * If this method is used for anything other than to set a parameter expectation as part of a
775   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
776   *
777   * E.g.
778   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt(42.0f))).andReturn("hello");}
779   *
780   * @param expectedValue the value to which the specified incoming parameter to the mocked method
781   * must be greater than.
782   * @return {@code 0}. The return value is always ignored.
783   */
784  public static float gt(float expectedValue) {
785    return EasyMock.gt(expectedValue);
786  }
787
788  /**
789   * Expects an {@code int} argument greater than the given value as a parameter
790   * to a mocked method.
791   *
792   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
793   *
794   * If this method is used for anything other than to set a parameter expectation as part of a
795   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
796   *
797   * E.g.
798   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt(42))).andReturn("hello");}
799   *
800   * @param expectedValue the value to which the specified incoming parameter to the mocked method
801   * must be greater than.
802   * @return {@code 0}. The return value is always ignored.
803   */
804  public static int gt(int expectedValue) {
805    return EasyMock.gt(expectedValue);
806  }
807
808  /**
809   * Expects a {@code long} argument greater than the given value as a parameter
810   * to a mocked method.
811   *
812   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
813   *
814   * If this method is used for anything other than to set a parameter expectation as part of a
815   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
816   *
817   * E.g.
818   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt(42l))).andReturn("hello");}
819   *
820   * @param expectedValue the value to which the specified incoming parameter to the mocked method
821   * must be greater than.
822   * @return {@code 0}. The return value is always ignored.
823   */
824  public static long gt(long expectedValue) {
825    return EasyMock.gt(expectedValue);
826  }
827
828  /**
829   * Expects a {@code short} argument greater than the given value as a parameter
830   * to a mocked method.
831   *
832   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
833   *
834   * If this method is used for anything other than to set a parameter expectation as part of a
835   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
836   *
837   * E.g.
838   * {@code AndroidMock.expect(mock.getString(AndroidMock.gt((short)42))).andReturn("hello");}
839   *
840   * @param expectedValue the value to which the specified incoming parameter to the mocked method
841   * must be greater than.
842   * @return {@code 0}. The return value is always ignored.
843   */
844  public static short gt(short expectedValue) {
845    return EasyMock.gt(expectedValue);
846  }
847
848  /**
849   * Expects a {@code Comparable} argument less than the given value as a parameter
850   * to a mocked method.
851   *
852   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
853   *
854   * If this method is used for anything other than to set a parameter expectation as part of a
855   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
856   *
857   * E.g.
858   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt("hi"))).andReturn("hello");}
859   *
860   * @param expectedValue the value to which the specified incoming parameter to the mocked method
861   * must be less than.
862   * @return {@code null}. The return value is always ignored.
863   */
864  public static <T extends Comparable<T>> T lt(Comparable<T> expectedValue) {
865    return EasyMock.lt(expectedValue);
866  }
867
868  /**
869   * Expects a {@code byte} argument less than the given value as a parameter
870   * to a mocked method.
871   *
872   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
873   *
874   * If this method is used for anything other than to set a parameter expectation as part of a
875   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
876   *
877   * E.g.
878   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt((byte)42))).andReturn("hello");}
879   *
880   * @param expectedValue the value to which the specified incoming parameter to the mocked method
881   * must be less than.
882   * @return {@code 0}. The return value is always ignored.
883   */
884  public static byte lt(byte expectedValue) {
885    return EasyMock.lt(expectedValue);
886  }
887
888  /**
889   * Expects a {@code double} argument less than the given value as a parameter
890   * to a mocked method.
891   *
892   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
893   *
894   * If this method is used for anything other than to set a parameter expectation as part of a
895   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
896   *
897   * E.g.
898   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt(42.0))).andReturn("hello");}
899   *
900   * @param expectedValue the value to which the specified incoming parameter to the mocked method
901   * must be less than.
902   * @return {@code 0}. The return value is always ignored.
903   */
904  public static double lt(double expectedValue) {
905    return EasyMock.lt(expectedValue);
906  }
907
908  /**
909   * Expects a {@code float} argument less than the given value as a parameter
910   * to a mocked method.
911   *
912   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
913   *
914   * If this method is used for anything other than to set a parameter expectation as part of a
915   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
916   *
917   * E.g.
918   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt(42.0f))).andReturn("hello");}
919   *
920   * @param expectedValue the value to which the specified incoming parameter to the mocked method
921   * must be less than.
922   * @return {@code 0}. The return value is always ignored.
923   */
924  public static float lt(float expectedValue) {
925    return EasyMock.lt(expectedValue);
926  }
927
928  /**
929   * Expects an {@code int} argument less than the given value as a parameter
930   * to a mocked method.
931   *
932   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
933   *
934   * If this method is used for anything other than to set a parameter expectation as part of a
935   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
936   *
937   * E.g.
938   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt(42))).andReturn("hello");}
939   *
940   * @param expectedValue the value to which the specified incoming parameter to the mocked method
941   * must be less than.
942   * @return {@code 0}. The return value is always ignored.
943   */
944  public static int lt(int expectedValue) {
945    return EasyMock.lt(expectedValue);
946  }
947
948  /**
949   * Expects a {@code long} argument less than the given value as a parameter
950   * to a mocked method.
951   *
952   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
953   *
954   * If this method is used for anything other than to set a parameter expectation as part of a
955   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
956   *
957   * E.g.
958   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt(42l))).andReturn("hello");}
959   *
960   * @param expectedValue the value to which the specified incoming parameter to the mocked method
961   * must be less than.
962   * @return {@code 0}. The return value is always ignored.
963   */
964  public static long lt(long expectedValue) {
965    return EasyMock.lt(expectedValue);
966  }
967
968  /**
969   * Expects a {@code short} argument less than the given value as a parameter
970   * to a mocked method.
971   *
972   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
973   *
974   * If this method is used for anything other than to set a parameter expectation as part of a
975   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
976   *
977   * E.g.
978   * {@code AndroidMock.expect(mock.getString(AndroidMock.lt((short)42))).andReturn("hello");}
979   *
980   * @param expectedValue the value to which the specified incoming parameter to the mocked method
981   * must be less than.
982   * @return {@code 0}. The return value is always ignored.
983   */
984  public static short lt(short expectedValue) {
985    return EasyMock.lt(expectedValue);
986  }
987
988  /**
989   * Expects an object implementing the given class as a parameter to a mocked method. During
990   * replay mode, the mocked method call will accept any {@code Object} that is an instance of
991   * the specified class or one of its subclasses. Specifically, any {@code non-null} parameter for
992   * which the {@code java.lang.Class.isAssignableFrom(Class)} will return true will be accepted by
993   * this matcher during the replay phase.
994   *
995   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
996   *
997   * If this method is used for anything other than to set a parameter expectation as part of a
998   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
999   *
1000   * E.g.
1001   * {@code AndroidMock.expect(mock.getString(AndroidMock.isA(HashMap.class))).andReturn("hello");}
1002   *
1003   * @param <T> the expected Class type.
1004   * @param clazz the class of the accepted type.
1005   * @return {@code null}. The return value is always ignored.
1006   */
1007  public static <T> T isA(Class<T> clazz) {
1008    return EasyMock.isA(clazz);
1009  }
1010
1011  /**
1012   * Expects a string that contains the given substring as a parameter to a mocked method.
1013   * During replay mode, the mocked method will accept any {@code non-null String} which contains
1014   * the provided {@code substring}.
1015   *
1016   * Use this to loosen the expectations of acceptable parameters for a mocked method call.
1017   *
1018   * If this method is used for anything other than to set a parameter expectation as part of a
1019   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1020   *
1021   * E.g.
1022   * {@code AndroidMock.expect(mock.getString(AndroidMock.substring("hi"))).andReturn("hello");}
1023   *
1024   * @param substring the substring which any incoming parameter to the mocked method must contain.
1025   * @return {@code null}.
1026   */
1027  public static String contains(String substring) {
1028    return EasyMock.contains(substring);
1029  }
1030
1031  /**
1032   * Expects a {@code boolean} parameter that matches both of the provided expectations. During
1033   * replay mode, the mocked method will accept any {@code boolean} that matches both of the
1034   * provided expectations. Possible expectations for {@code first} and {@code second} include (but
1035   * are not limited to) {@link #anyBoolean()} and {@link #eq(boolean)}.
1036   *
1037   * E.g.
1038   * {@code AndroidMock.expect(mock.getString(
1039   *        AndroidMock.and(AndroidMock.anyBoolean(), AndroidMock.eq(true)))).andReturn("hello");}
1040   *
1041   * Or, for illustration purposes (using static imports)
1042   *
1043   * {@code expect(mock.getString(and(anyBoolean(), eq(true)))).andReturn("hello");}
1044   *
1045   * If this method is used for anything other than to set a parameter expectation as part of a
1046   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1047   *
1048   * @param first the first expectation to test.
1049   * @param second the second expectation to test.
1050   * @return {@code false}. The return value is always ignored.
1051   */
1052  public static boolean and(boolean first, boolean second) {
1053    return EasyMock.and(first, second);
1054  }
1055
1056  /**
1057   * Expects a {@code byte} parameter that matches both of the provided expectations. During replay
1058   * mode, the mocked method will accept any {@code byte} that matches both of the provided
1059   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1060   * limited to) {@link #anyByte()}, {@link #leq(byte)} and {@link #eq(byte)}.
1061   *
1062   * E.g.
1063   * {@code AndroidMock.expect(mock.getString(AndroidMock.and(
1064   *        AndroidMock.gt((byte)0), AndroidMock.lt((byte)42)))).andReturn("hello");}
1065   *
1066   * Or, for illustration purposes (using static imports)
1067   *
1068   * {@code expect(mock.getString(and(gt((byte)0), lt((byte)42)))).andReturn("hello");}
1069   *
1070   * If this method is used for anything other than to set a parameter expectation as part of a
1071   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1072   *
1073   * @param first the first expectation to test.
1074   * @param second the second expectation to test.
1075   * @return {@code 0}. The return value is always ignored.
1076   */
1077  public static byte and(byte first, byte second) {
1078    return EasyMock.and(first, second);
1079  }
1080
1081  /**
1082   * Expects a {@code char} parameter that matches both of the provided expectations. During replay
1083   * mode, the mocked method will accept any {@code char} that matches both of the provided
1084   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1085   * limited to) {@link #anyChar()} and {@link #eq(char)}.
1086   *
1087   * E.g.
1088   * {@code AndroidMock.expect(mock.getString(
1089   *        AndroidMock.and(AndroidMock.geq('a'), AndroidMock.lt('q')))).andReturn("hello");}
1090   *
1091   * Or, for illustration purposes (using static imports)
1092   *
1093   * {@code expect(mock.getString(and(eq('a'), anyChar()))).andReturn("hello");}
1094   *
1095   * If this method is used for anything other than to set a parameter expectation as part of a
1096   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1097   *
1098   * @param first the first expectation to test.
1099   * @param second the second expectation to test.
1100   * @return {@code 0}. The return value is always ignored.
1101   */
1102  public static char and(char first, char second) {
1103    return EasyMock.and(first, second);
1104  }
1105
1106  /**
1107   * Expects a {@code double} parameter that matches both of the provided expectations. During
1108   * replay mode, the mocked method will accept any {@code double} that matches both of the provided
1109   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1110   * limited to) {@link #anyDouble()}, {@link #leq(double)} and {@link #eq(double)}.
1111   *
1112   * E.g.
1113   * {@code AndroidMock.expect(mock.getString(
1114   *        AndroidMock.and(AndroidMock.gt(0.0), AndroidMock.lt(42.0)))).andReturn("hello");}
1115   *
1116   * Or, for illustration purposes (using static imports)
1117   *
1118   * {@code expect(mock.getString(and(gt(0.0), lt(42.0)))).andReturn("hello");}
1119   *
1120   * If this method is used for anything other than to set a parameter expectation as part of a
1121   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1122   *
1123   * @param first the first expectation to test.
1124   * @param second the second expectation to test.
1125   * @return {@code 0}. The return value is always ignored.
1126   */
1127  public static double and(double first, double second) {
1128    return EasyMock.and(first, second);
1129  }
1130
1131  /**
1132   * Expects a {@code float} parameter that matches both of the provided expectations. During
1133   * replay mode, the mocked method will accept any {@code float} that matches both of the provided
1134   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1135   * limited to) {@link #anyFloat()}, {@link #leq(float)} and {@link #eq(float)}.
1136   *
1137   * E.g.
1138   * {@code AndroidMock.expect(mock.getString(
1139   *        AndroidMock.and(AndroidMock.gt(0.0f), AndroidMock.lt(42.0f)))).andReturn("hello");}
1140   *
1141   * Or, for illustration purposes (using static imports)
1142   *
1143   * {@code expect(mock.getString(and(gt(0.0f), lt(42.0f)))).andReturn("hello");}
1144   *
1145   * If this method is used for anything other than to set a parameter expectation as part of a
1146   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1147   *
1148   * @param first the first expectation to test.
1149   * @param second the second expectation to test.
1150   * @return {@code 0}. The return value is always ignored.
1151   */
1152  public static float and(float first, float second) {
1153    return EasyMock.and(first, second);
1154  }
1155
1156  /**
1157   * Expects an {@code int} parameter that matches both of the provided expectations. During
1158   * replay mode, the mocked method will accept any {@code int} that matches both of the provided
1159   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1160   * limited to) {@link #anyInt()}, {@link #leq(int)} and {@link #eq(int)}.
1161   *
1162   * E.g.
1163   * {@code AndroidMock.expect(mock.getString(
1164   *        AndroidMock.and(AndroidMock.gt(0), AndroidMock.lt(42)))).andReturn("hello");}
1165   *
1166   * Or, for illustration purposes (using static imports)
1167   *
1168   * {@code expect(mock.getString(and(gt(0), lt(42)))).andReturn("hello");}
1169   *
1170   * If this method is used for anything other than to set a parameter expectation as part of a
1171   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1172   *
1173   * @param first the first expectation to test.
1174   * @param second the second expectation to test.
1175   * @return {@code 0}. The return value is always ignored.
1176   */
1177  public static int and(int first, int second) {
1178    return EasyMock.and(first, second);
1179  }
1180
1181  /**
1182   * Expects a {@code long} parameter that matches both of the provided expectations. During
1183   * replay mode, the mocked method will accept any {@code long} that matches both of the provided
1184   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1185   * limited to) {@link #anyLong()}, {@link #leq(long)} and {@link #eq(long)}.
1186   *
1187   * E.g.
1188   * {@code AndroidMock.expect(mock.getString(
1189   *        AndroidMock.and(AndroidMock.gt(0l), AndroidMock.lt(42l)))).andReturn("hello");}
1190   *
1191   * Or, for illustration purposes (using static imports)
1192   *
1193   * {@code expect(mock.getString(and(gt(0l), lt(42l)))).andReturn("hello");}
1194   *
1195   * If this method is used for anything other than to set a parameter expectation as part of a
1196   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1197   *
1198   * @param first the first expectation to test.
1199   * @param second the second expectation to test.
1200   * @return {@code 0}. The return value is always ignored.
1201   */
1202  public static long and(long first, long second) {
1203    return EasyMock.and(first, second);
1204  }
1205
1206  /**
1207   * Expects a {@code short} parameter that matches both of the provided expectations. During
1208   * replay mode, the mocked method will accept any {@code short} that matches both of the provided
1209   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1210   * limited to) {@link #anyShort()}, {@link #leq(short)} and {@link #eq(short)}.
1211   *
1212   * E.g.
1213   * {@code AndroidMock.expect(mock.getString(AndroidMock.and(
1214   *        AndroidMock.gt((short)0), AndroidMock.lt((short)42)))).andReturn("hello");}
1215   *
1216   * Or, for illustration purposes (using static imports)
1217   *
1218   * {@code expect(mock.getString(and(gt((short)0), lt((short)42)))).andReturn("hello");}
1219   *
1220   * If this method is used for anything other than to set a parameter expectation as part of a
1221   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1222   *
1223   * @param first the first expectation to test.
1224   * @param second the second expectation to test.
1225   * @return {@code 0}. The return value is always ignored.
1226   */
1227  public static short and(short first, short second) {
1228    return EasyMock.and(first, second);
1229  }
1230
1231  /**
1232   * Expects an {@code Object} parameter that matches both of the provided expectations. During
1233   * replay mode, the mocked method will accept any {@code Object} that matches both of the provided
1234   * expectations. Possible expectations for {@code first} and {@code second} include (but are not
1235   * limited to) {@link #anyObject()}, {@link #isA(Class)} and {@link #contains(String)}.
1236   *
1237   * E.g.
1238   * {@code AndroidMock.expect(mock.getString(
1239   *        AndroidMock.and(
1240   *            AndroidMock.contains("hi"), AndroidMock.contains("world")))).andReturn("hello");}
1241   *
1242   * Or, for illustration purposes (using static imports)
1243   *
1244   * {@code expect(mock.getString(and(contains("hi"), contains("world")))).andReturn("hello");}
1245   *
1246   * If this method is used for anything other than to set a parameter expectation as part of a
1247   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1248   *
1249   * @param first the first expectation to test.
1250   * @param second the second expectation to test.
1251   * @return {@code 0}. The return value is always ignored.
1252   */
1253  public static <T> T and(T first, T second) {
1254    return EasyMock.and(first, second);
1255  }
1256
1257  /**
1258   * Expects a {@code boolean} parameter that matches one or both of the provided expectations.
1259   * During replay mode, the mocked method will accept any {@code boolean} that matches one of the
1260   * provided expectations, or both of them. Possible expectations for {@code first} and
1261   * {@code second} include (but are not limited to) {@link #anyBoolean()} and {@link #eq(boolean)}.
1262   *
1263   * E.g.
1264   * {@code AndroidMock.expect(mock.getString(
1265   *        AndroidMock.or(AndroidMock.eq(true), AndroidMock.anyBoolean()))).andReturn("hello");}
1266   *
1267   * Or, for illustration purposes (using static imports)
1268   *
1269   * {@code expect(mock.getString(and(eq(true), anyBoolean()))).andReturn("hello");}
1270   *
1271   * If this method is used for anything other than to set a parameter expectation as part of a
1272   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1273   *
1274   * @param first the first expectation to test.
1275   * @param second the second expectation to test.
1276   * @return {@code false}. The return value is always ignored.
1277   */
1278  public static boolean or(boolean first, boolean second) {
1279    return EasyMock.or(first, second);
1280  }
1281
1282  /**
1283   * Expects a {@code byte} parameter that matches one or both of the provided expectations.
1284   * During replay mode, the mocked method will accept any {@code byte} that matches one of the
1285   * provided expectations, or both of them. Possible expectations for {@code first} and
1286   * {@code second} include (but are not limited to) {@link #anyByte()}, {@link #eq(byte)},
1287   * and {@link #lt(byte)}.
1288   *
1289   * E.g.
1290   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1291   *        AndroidMock.geq((byte)0), AndroidMock.lt((byte)42)))).andReturn("hello");}
1292   *
1293   * Or, for illustration purposes (using static imports)
1294   *
1295   * {@code expect(mock.getString(or(geq((byte)0), lt((byte)42)))).andReturn("hello");}
1296   *
1297   * If this method is used for anything other than to set a parameter expectation as part of a
1298   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1299   *
1300   * @param first the first expectation to test.
1301   * @param second the second expectation to test.
1302   * @return {@code 0}. The return value is always ignored.
1303   */
1304  public static byte or(byte first, byte second) {
1305    return EasyMock.or(first, second);
1306  }
1307
1308  /**
1309   * Expects a {@code char} parameter that matches one or both of the provided expectations.
1310   * During replay mode, the mocked method will accept any {@code char} that matches one of the
1311   * provided expectations, or both of them. Possible expectations for {@code first} and
1312   * {@code second} include (but are not limited to) {@link #anyChar()} and {@link #eq(char)}.
1313   *
1314   * E.g.
1315   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1316   *        AndroidMock.eq('a'), AndroidMock.eq('z')))).andReturn("hello");}
1317   *
1318   * Or, for illustration purposes (using static imports)
1319   *
1320   * {@code expect(mock.getString(or(eq('a'), eq('z')))).andReturn("hello");}
1321   *
1322   * If this method is used for anything other than to set a parameter expectation as part of a
1323   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1324   *
1325   * @param first the first expectation to test.
1326   * @param second the second expectation to test.
1327   * @return {@code 0}. The return value is always ignored.
1328   */
1329  public static char or(char first, char second) {
1330    return EasyMock.or(first, second);
1331  }
1332
1333  /**
1334   * Expects a {@code double} parameter that matches one or both of the provided expectations.
1335   * During replay mode, the mocked method will accept any {@code double} that matches one of the
1336   * provided expectations, or both of them. Possible expectations for {@code first} and
1337   * {@code second} include (but are not limited to) {@link #anyDouble()}, {@link #eq(double)}
1338   * and {@link #lt(double)}.
1339   *
1340   * E.g.
1341   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1342   *        AndroidMock.eq(0.0), AndroidMock.geq(42.0)))).andReturn("hello");}
1343   *
1344   * Or, for illustration purposes (using static imports)
1345   *
1346   * {@code expect(mock.getString(or(eq(0.0), geq(42.0)))).andReturn("hello");}
1347   *
1348   * If this method is used for anything other than to set a parameter expectation as part of a
1349   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1350   *
1351   * @param first the first expectation to test.
1352   * @param second the second expectation to test.
1353   * @return {@code 0}. The return value is always ignored.
1354   */
1355  public static double or(double first, double second) {
1356    return EasyMock.or(first, second);
1357  }
1358
1359  /**
1360   * Expects a {@code float} parameter that matches one or both of the provided expectations.
1361   * During replay mode, the mocked method will accept any {@code float} that matches one of the
1362   * provided expectations, or both of them. Possible expectations for {@code first} and
1363   * {@code second} include (but are not limited to) {@link #anyFloat()}, {@link #eq(float)}
1364   * and {@link #lt(float)}.
1365   *
1366   * E.g.
1367   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1368   *        AndroidMock.eq(0.0f), AndroidMock.geq(42.0f)))).andReturn("hello");}
1369   *
1370   * Or, for illustration purposes (using static imports)
1371   *
1372   * {@code expect(mock.getString(or(eq(0.0f), geq(42.0f)))).andReturn("hello");}
1373   *
1374   * If this method is used for anything other than to set a parameter expectation as part of a
1375   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1376   *
1377   * @param first the first expectation to test.
1378   * @param second the second expectation to test.
1379   * @return {@code 0}. The return value is always ignored.
1380   */
1381  public static float or(float first, float second) {
1382    return EasyMock.or(first, second);
1383  }
1384
1385  /**
1386   * Expects an {@code int} parameter that matches one or both of the provided expectations.
1387   * During replay mode, the mocked method will accept any {@code int} that matches one of the
1388   * provided expectations, or both of them. Possible expectations for {@code first} and
1389   * {@code second} include (but are not limited to) {@link #anyInt()}, {@link #eq(int)}
1390   * and {@link #lt(int)}.
1391   *
1392   * E.g.
1393   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1394   *        AndroidMock.eq(0), AndroidMock.geq(42)))).andReturn("hello");}
1395   *
1396   * Or, for illustration purposes (using static imports)
1397   *
1398   * {@code expect(mock.getString(or(eq(0), geq(42)))).andReturn("hello");}
1399   *
1400   * If this method is used for anything other than to set a parameter expectation as part of a
1401   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1402   *
1403   * @param first the first expectation to test.
1404   * @param second the second expectation to test.
1405   * @return {@code 0}. The return value is always ignored.
1406   */
1407  public static int or(int first, int second) {
1408    return EasyMock.or(first, second);
1409  }
1410
1411  /**
1412   * Expects a {@code long} parameter that matches one or both of the provided expectations.
1413   * During replay mode, the mocked method will accept any {@code long} that matches one of the
1414   * provided expectations, or both of them. Possible expectations for {@code first} and
1415   * {@code second} include (but are not limited to) {@link #anyLong()}, {@link #eq(long)}
1416   * and {@link #lt(long)}.
1417   *
1418   * E.g.
1419   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1420   *        AndroidMock.eq(0l), AndroidMock.geq(42l)))).andReturn("hello");}
1421   *
1422   * Or, for illustration purposes (using static imports)
1423   *
1424   * {@code expect(mock.getString(or(eq(0l), geq(42l)))).andReturn("hello");}
1425   *
1426   * If this method is used for anything other than to set a parameter expectation as part of a
1427   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1428   *
1429   * @param first the first expectation to test.
1430   * @param second the second expectation to test.
1431   * @return {@code 0}. The return value is always ignored.
1432   */
1433  public static long or(long first, long second) {
1434    return EasyMock.or(first, second);
1435  }
1436
1437  /**
1438   * Expects a {@code short} parameter that matches one or both of the provided expectations.
1439   * During replay mode, the mocked method will accept any {@code short} that matches one of the
1440   * provided expectations, or both of them. Possible expectations for {@code first} and
1441   * {@code second} include (but are not limited to) {@link #anyShort()}, {@link #eq(short)}
1442   * and {@link #lt(short)}.
1443   *
1444   * E.g.
1445   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1446   *        AndroidMock.eq((short)0), AndroidMock.geq((short)42)))).andReturn("hello");}
1447   *
1448   * Or, for illustration purposes (using static imports)
1449   *
1450   * {@code expect(mock.getString(or(eq((short)0), geq((short)42)))).andReturn("hello");}
1451   *
1452   * If this method is used for anything other than to set a parameter expectation as part of a
1453   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1454   *
1455   * @param first the first expectation to test.
1456   * @param second the second expectation to test.
1457   * @return {@code 0}. The return value is always ignored.
1458   */
1459  public static short or(short first, short second) {
1460    return EasyMock.or(first, second);
1461  }
1462
1463  /**
1464   * Expects an {@code Object} parameter that matches one or both of the provided expectations.
1465   * During replay mode, the mocked method will accept any {@code Object} that matches one of the
1466   * provided expectations, or both of them. Possible expectations for {@code first} and
1467   * {@code second} include (but are not limited to) {@link #anyObject()}, {@link #eq(Class)}
1468   * and {@link #lt(Comparable)}.
1469   *
1470   * E.g.
1471   * {@code AndroidMock.expect(mock.getString(AndroidMock.or(
1472   *        AndroidMock.notNull(), AndroidMock.geq(fortyTwo)))).andReturn("hello");}
1473   *
1474   * Or, for illustration purposes (using static imports)
1475   *
1476   * {@code expect(mock.getString(or(notNull(), geq(fortyTwo)))).andReturn("hello");}
1477   *
1478   * If this method is used for anything other than to set a parameter expectation as part of a
1479   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1480   *
1481   * @param first the first expectation to test.
1482   * @param second the second expectation to test.
1483   * @return {@code null}. The return value is always ignored.
1484   */
1485  public static <T> T or(T first, T second) {
1486    return EasyMock.or(first, second);
1487  }
1488
1489  /**
1490   * Expects a {@code boolean} parameter that does not match the provided expectation.
1491   * During replay mode, the mocked method will accept any {@code boolean} that does not match
1492   * the provided expectation. Possible expectations for {@code expectation}
1493   * include (but are not limited to) {@link #anyBoolean()} and {@link #eq(boolean)}.
1494   *
1495   * E.g.
1496   * {@code AndroidMock.expect(mock.getString(
1497   *        AndroidMock.not(AndroidMock.eq(true)))).andReturn("hello");}
1498   *
1499   * Or, for illustration purposes (using static imports)
1500   *
1501   * {@code expect(mock.getString(not(eq(true)))).andReturn("hello");}
1502   *
1503   * If this method is used for anything other than to set a parameter expectation as part of a
1504   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1505   *
1506   * @param expectation the expectation to test.
1507   * @return {@code false}. The return value is always ignored.
1508   */
1509  public static boolean not(boolean expectation) {
1510    return EasyMock.not(expectation);
1511  }
1512
1513  /**
1514   * Expects a {@code byte} parameter that does not match the provided expectation.
1515   * During replay mode, the mocked method will accept any {@code byte} that does not match
1516   * the provided expectation. Possible expectations for {@code expectation}
1517   * include (but are not limited to) {@link #anyByte()}, {@link #eq(byte)} and
1518   * {@link #lt(byte)}.
1519   *
1520   * E.g.
1521   * {@code AndroidMock.expect(mock.getString(
1522   *        AndroidMock.not(AndroidMock.eq((byte)42)))).andReturn("hello");}
1523   *
1524   * Or, for illustration purposes (using static imports)
1525   *
1526   * {@code expect(mock.getString(not(eq((byte)42)))).andReturn("hello");}
1527   *
1528   * If this method is used for anything other than to set a parameter expectation as part of a
1529   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1530   *
1531   * @param expectation the expectation to test.
1532   * @return {@code 0}. The return value is always ignored.
1533   */
1534  public static byte not(byte expectation) {
1535    return EasyMock.not(expectation);
1536  }
1537
1538  /**
1539   * Expects a {@code char} parameter that does not match the provided expectation.
1540   * During replay mode, the mocked method will accept any {@code char} that does not match
1541   * the provided expectation. Possible expectations for {@code expectation}
1542   * include (but are not limited to) {@link #anyChar()} and {@link #eq(char)}.
1543   *
1544   * E.g.
1545   * {@code AndroidMock.expect(mock.getString(
1546   *        AndroidMock.not(AndroidMock.eq('a')))).andReturn("hello");}
1547   *
1548   * Or, for illustration purposes (using static imports)
1549   *
1550   * {@code expect(mock.getString(not(eq('a')))).andReturn("hello");}
1551   *
1552   * If this method is used for anything other than to set a parameter expectation as part of a
1553   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1554   *
1555   * @param expectation the expectation to test.
1556   * @return {@code 0}. The return value is always ignored.
1557   */
1558  public static char not(char expectation) {
1559    return EasyMock.not(expectation);
1560  }
1561
1562  /**
1563   * Expects a {@code double} parameter that does not match the provided expectation.
1564   * During replay mode, the mocked method will accept any {@code double} that does not match
1565   * the provided expectation. Possible expectations for {@code expectation}
1566   * include (but are not limited to) {@link #anyDouble()}, {@link #eq(double)} and
1567   * {@link #lt(double)}.
1568   *
1569   * E.g.
1570   * {@code AndroidMock.expect(mock.getString(
1571   *        AndroidMock.not(AndroidMock.eq(42.0)))).andReturn("hello");}
1572   *
1573   * Or, for illustration purposes (using static imports)
1574   *
1575   * {@code expect(mock.getString(not(eq(42.0)))).andReturn("hello");}
1576   *
1577   * If this method is used for anything other than to set a parameter expectation as part of a
1578   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1579   *
1580   * @param expectation the expectation to test.
1581   * @return {@code 0}. The return value is always ignored.
1582   */
1583  public static double not(double expectation) {
1584    return EasyMock.not(expectation);
1585  }
1586
1587  /**
1588   * Expects a {@code float} parameter that does not match the provided expectation.
1589   * During replay mode, the mocked method will accept any {@code float} that does not match
1590   * the provided expectation. Possible expectations for {@code expectation}
1591   * include (but are not limited to) {@link #anyFloat()}, {@link #eq(float)} and
1592   * {@link #lt(float)}.
1593   *
1594   * E.g.
1595   * {@code AndroidMock.expect(mock.getString(
1596   *        AndroidMock.not(AndroidMock.eq(42.0f)))).andReturn("hello");}
1597   *
1598   * Or, for illustration purposes (using static imports)
1599   *
1600   * {@code expect(mock.getString(not(eq(42.0f)))).andReturn("hello");}
1601   *
1602   * If this method is used for anything other than to set a parameter expectation as part of a
1603   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1604   *
1605   * @param expectation the expectation to test.
1606   * @return {@code 0}. The return value is always ignored.
1607   */
1608  public static float not(float expectation) {
1609    return EasyMock.not(expectation);
1610  }
1611
1612  /**
1613   * Expects a {@code int} parameter that does not match the provided expectation.
1614   * During replay mode, the mocked method will accept any {@code int} that does not match
1615   * the provided expectation. Possible expectations for {@code expectation}
1616   * include (but are not limited to) {@link #anyInt()}, {@link #eq(int)} and
1617   * {@link #lt(int)}.
1618   *
1619   * E.g.
1620   * {@code AndroidMock.expect(mock.getString(
1621   *        AndroidMock.not(AndroidMock.eq(42)))).andReturn("hello");}
1622   *
1623   * Or, for illustration purposes (using static imports)
1624   *
1625   * {@code expect(mock.getString(not(eq(42)))).andReturn("hello");}
1626   *
1627   * If this method is used for anything other than to set a parameter expectation as part of a
1628   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1629   *
1630   * @param expectation the expectation to test.
1631   * @return {@code 0}. The return value is always ignored.
1632   */
1633  public static int not(int expectation) {
1634    return EasyMock.not(expectation);
1635  }
1636
1637  /**
1638   * Expects a {@code long} parameter that does not match the provided expectation.
1639   * During replay mode, the mocked method will accept any {@code long} that does not match
1640   * the provided expectation. Possible expectations for {@code expectation}
1641   * include (but are not limited to) {@link #anyLong()}, {@link #eq(long)} and
1642   * {@link #lt(long)}.
1643   *
1644   * E.g.
1645   * {@code AndroidMock.expect(mock.getString(
1646   *        AndroidMock.not(AndroidMock.eq(42l)))).andReturn("hello");}
1647   *
1648   * Or, for illustration purposes (using static imports)
1649   *
1650   * {@code expect(mock.getString(not(eq(42l)))).andReturn("hello");}
1651   *
1652   * If this method is used for anything other than to set a parameter expectation as part of a
1653   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1654   *
1655   * @param expectation the expectation to test.
1656   * @return {@code 0}. The return value is always ignored.
1657   */
1658  public static long not(long expectation) {
1659    return EasyMock.not(expectation);
1660  }
1661
1662  /**
1663   * Expects a {@code short} parameter that does not match the provided expectation.
1664   * During replay mode, the mocked method will accept any {@code short} that does not match
1665   * the provided expectation. Possible expectations for {@code expectation}
1666   * include (but are not limited to) {@link #anyShort()}, {@link #eq(short)} and
1667   * {@link #lt(short)}.
1668   *
1669   * E.g.
1670   * {@code AndroidMock.expect(mock.getString(
1671   *        AndroidMock.not(AndroidMock.eq((short)42)))).andReturn("hello");}
1672   *
1673   * Or, for illustration purposes (using static imports)
1674   *
1675   * {@code expect(mock.getString(not(eq((short)42)))).andReturn("hello");}
1676   *
1677   * If this method is used for anything other than to set a parameter expectation as part of a
1678   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1679   *
1680   * @param expectation the expectation to test.
1681   * @return {@code 0}. The return value is always ignored.
1682   */
1683  public static short not(short expectation) {
1684    return EasyMock.not(expectation);
1685  }
1686
1687  /**
1688   * Expects an {@code Object} parameter that does not match the given expectation.
1689   * During replay mode, the mocked method will accept any {@code Object} that does not match
1690   * the provided expectation. Possible expectations for {@code expectation}
1691   * include (but are not limited to) {@link #anyObject()}, {@link #leq(Comparable)} and
1692   * {@link #isNull()}.
1693   *
1694   * E.g.
1695   * {@code AndroidMock.expect(mock.getString(
1696   *        AndroidMock.not(AndroidMock.eq(fortyTwo)))).andReturn("hello");}
1697   *
1698   * Or, for illustration purposes (using static imports)
1699   *
1700   * {@code expect(mock.getString(not(eq(fortyTwo)))).andReturn("hello");}
1701   *
1702   * If this method is used for anything other than to set a parameter expectation as part of a
1703   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1704   *
1705   * @param expectation the expectation to test.
1706   * @return {@code 0}. The return value is always ignored.
1707   */
1708  public static <T> T not(T expectation) {
1709    return EasyMock.not(expectation);
1710  }
1711
1712  /**
1713   * Expects a {@code boolean} parameter that is equal to the provided {@code value}.
1714   * During replay mode, the mocked method will accept any {@code boolean} that matches the
1715   * value of {@code expectedValue}.
1716   *
1717   * E.g.
1718   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(true))).andReturn("hello");}
1719   *
1720   * Or, for illustration purposes (using static imports)
1721   *
1722   * {@code expect(mock.getString(eq(true))).andReturn("hello");}
1723   *
1724   * If this method is used for anything other than to set a parameter expectation as part of a
1725   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1726   *
1727   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1728   * must be equal.
1729   * @return {@code false}. The return value is always ignored.
1730   */
1731  public static boolean eq(boolean expectedValue) {
1732    return EasyMock.eq(expectedValue);
1733  }
1734
1735  /**
1736   * Expects a {@code byte} parameter that is equal to the provided {@code expectedValue}.
1737   * During replay mode, the mocked method will accept any {@code byte} that matches the
1738   * value of {@code expectedValue}.
1739   *
1740   * E.g.
1741   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq((byte)0))).andReturn("hello");}
1742   *
1743   * Or, for illustration purposes (using static imports)
1744   *
1745   * {@code expect(mock.getString(eq((byte)0))).andReturn("hello");}
1746   *
1747   * If this method is used for anything other than to set a parameter expectation as part of a
1748   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1749   *
1750   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1751   * must be equal.
1752   * @return {@code false}. The return value is always ignored.
1753   */
1754  public static byte eq(byte expectedValue) {
1755    return EasyMock.eq(expectedValue);
1756  }
1757
1758  /**
1759   * Expects a {@code char} parameter that is equal to the provided {@code expectedValue}.
1760   * During replay mode, the mocked method will accept any {@code char} that matches the
1761   * value of {@code expectedValue}.
1762   *
1763   * E.g.
1764   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq('a'))).andReturn("hello");}
1765   *
1766   * Or, for illustration purposes (using static imports)
1767   *
1768   * {@code expect(mock.getString(eq('a'))).andReturn("hello");}
1769   *
1770   * If this method is used for anything other than to set a parameter expectation as part of a
1771   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1772   *
1773   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1774   * must be equal.
1775   * @return {@code 0}. The return value is always ignored.
1776   */
1777  public static char eq(char expectedValue) {
1778    return EasyMock.eq(expectedValue);
1779  }
1780
1781  /**
1782   * Expects a {@code double} parameter that is equal to the provided {@code expectedValue}.
1783   * During replay mode, the mocked method will accept any {@code double} that matches the
1784   * value of {@code expectedValue}.
1785   *
1786   * E.g.
1787   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(0.0))).andReturn("hello");}
1788   *
1789   * Or, for illustration purposes (using static imports)
1790   *
1791   * {@code expect(mock.getString(eq(0.0))).andReturn("hello");}
1792   *
1793   * If this method is used for anything other than to set a parameter expectation as part of a
1794   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1795   *
1796   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1797   * must be equal.
1798   * @return {@code 0}. The return value is always ignored.
1799   */
1800  public static double eq(double expectedValue) {
1801    return EasyMock.eq(expectedValue);
1802  }
1803
1804  /**
1805   * Expects a {@code float} parameter that is equal to the provided {@code expectedValue}.
1806   * During replay mode, the mocked method will accept any {@code float} that matches the
1807   * value of {@code expectedValue}.
1808   *
1809   * E.g.
1810   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(0.0f))).andReturn("hello");}
1811   *
1812   * Or, for illustration purposes (using static imports)
1813   *
1814   * {@code expect(mock.getString(eq(0.0f))).andReturn("hello");}
1815   *
1816   * If this method is used for anything other than to set a parameter expectation as part of a
1817   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1818   *
1819   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1820   * must be equal.
1821   * @return {@code 0}. The return value is always ignored.
1822   */
1823  public static float eq(float expectedValue) {
1824    return EasyMock.eq(expectedValue);
1825  }
1826
1827  /**
1828   * Expects an {@code int} parameter that is equal to the provided {@code expectedValue}.
1829   * During replay mode, the mocked method will accept any {@code int} that matches the
1830   * value of {@code expectedValue}.
1831   *
1832   * E.g.
1833   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(0))).andReturn("hello");}
1834   *
1835   * Or, for illustration purposes (using static imports)
1836   *
1837   * {@code expect(mock.getString(eq(0))).andReturn("hello");}
1838   *
1839   * If this method is used for anything other than to set a parameter expectation as part of a
1840   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1841   *
1842   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1843   * must be equal.
1844   * @return {@code 0}. The return value is always ignored.
1845   */
1846  public static int eq(int expectedValue) {
1847    return EasyMock.eq(expectedValue);
1848  }
1849
1850  /**
1851   * Expects a {@code long} parameter that is equal to the provided {@code expectedValue}.
1852   * During replay mode, the mocked method will accept any {@code long} that matches the
1853   * value of {@code expectedValue}.
1854   *
1855   * E.g.
1856   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(0l))).andReturn("hello");}
1857   *
1858   * Or, for illustration purposes (using static imports)
1859   *
1860   * {@code expect(mock.getString(eq(0l))).andReturn("hello");}
1861   *
1862   * If this method is used for anything other than to set a parameter expectation as part of a
1863   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1864   *
1865   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1866   * must be equal.
1867   * @return {@code 0}. The return value is always ignored.
1868   */
1869  public static long eq(long expectedValue) {
1870    return EasyMock.eq(expectedValue);
1871  }
1872
1873  /**
1874   * Expects a {@code short} parameter that is equal to the provided {@code expectedValue}.
1875   * During replay mode, the mocked method will accept any {@code short} that matches the
1876   * value of {@code expectedValue}.
1877   *
1878   * E.g.
1879   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq((short)0))).andReturn("hello");}
1880   *
1881   * Or, for illustration purposes (using static imports)
1882   *
1883   * {@code expect(mock.getString(eq((short)0))).andReturn("hello");}
1884   *
1885   * If this method is used for anything other than to set a parameter expectation as part of a
1886   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1887   *
1888   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1889   * must be equal.
1890   * @return {@code 0}. The return value is always ignored.
1891   */
1892  public static short eq(short expectedValue) {
1893    return EasyMock.eq(expectedValue);
1894  }
1895
1896  /**
1897   * Expects an {@code Object} parameter that is equal to the provided {@code expectedValue}.
1898   * During replay mode, the mocked method will accept any {@code Object} that matches the
1899   * value of {@code expectedValue} according to its {@code equals(Object)} method.
1900   *
1901   * E.g.
1902   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq("hi"))).andReturn("hello");}
1903   *
1904   * Or, for illustration purposes (using static imports)
1905   *
1906   * {@code expect(mock.getString(eq("hi"))).andReturn("hello");}
1907   *
1908   * If this method is used for anything other than to set a parameter expectation as part of a
1909   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1910   *
1911   * @param expectedValue the value to which the specified incoming parameter to the mocked method
1912   * must be equal.
1913   * @return {@code 0}. The return value is always ignored.
1914   */
1915  public static <T> T eq(T expectedValue) {
1916    return EasyMock.eq(expectedValue);
1917  }
1918
1919  /**
1920   * Expects a {@code boolean} array parameter that is equal to the given array, i.e. it has to
1921   * have the same length, and each element has to be equal.
1922   *
1923   * E.g.
1924   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myBooleanArray))).andReturn("hello");}
1925   *
1926   * Or, for illustration purposes (using static imports)
1927   *
1928   * {@code expect(mock.getString(eq(myBooleanArray))).andReturn("hello");}
1929   *
1930   * If this method is used for anything other than to set a parameter expectation as part of a
1931   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1932   *
1933   * @param expectedValue the array to which the specified incoming parameter to the mocked method
1934   * must have equal contents.
1935   * @return {@code null}. The return value is always ignored.
1936   */
1937  public static boolean[] aryEq(boolean[] expectedValue) {
1938    return EasyMock.aryEq(expectedValue);
1939  }
1940
1941  /**
1942   * Expects a {@code byte} array parameter that is equal to the given array, i.e. it has to
1943   * have the same length, and each element has to be equal.
1944   *
1945   * E.g.
1946   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myByteArray))).andReturn("hello");}
1947   *
1948   * Or, for illustration purposes (using static imports)
1949   *
1950   * {@code expect(mock.getString(eq(myByteArray))).andReturn("hello");}
1951   *
1952   * If this method is used for anything other than to set a parameter expectation as part of a
1953   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1954   *
1955   * @param expectedValue the array to which the specified incoming parameter to the mocked method
1956   * must have equal contents.
1957   * @return {@code null}. The return value is always ignored.
1958   */
1959  public static byte[] aryEq(byte[] expectedValue) {
1960    return EasyMock.aryEq(expectedValue);
1961  }
1962
1963  /**
1964   * Expects a {@code char} array parameter that is equal to the given array, i.e. it has to
1965   * have the same length, and each element has to be equal.
1966   *
1967   * E.g.
1968   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myCharArray))).andReturn("hello");}
1969   *
1970   * Or, for illustration purposes (using static imports)
1971   *
1972   * {@code expect(mock.getString(eq(myCharArray))).andReturn("hello");}
1973   *
1974   * If this method is used for anything other than to set a parameter expectation as part of a
1975   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1976   *
1977   * @param expectedValue the array to which the specified incoming parameter to the mocked method
1978   * must have equal contents.
1979   * @return {@code null}. The return value is always ignored.
1980   */
1981  public static char[] aryEq(char[] expectedValue) {
1982    return EasyMock.aryEq(expectedValue);
1983  }
1984
1985  /**
1986   * Expects a {@code double} array parameter that is equal to the given array, i.e. it has to
1987   * have the same length, and each element has to be equal.
1988   *
1989   * E.g.
1990   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myDoubleArray))).andReturn("hello");}
1991   *
1992   * Or, for illustration purposes (using static imports)
1993   *
1994   * {@code expect(mock.getString(eq(myDoubleArray))).andReturn("hello");}
1995   *
1996   * If this method is used for anything other than to set a parameter expectation as part of a
1997   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
1998   *
1999   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2000   * must have equal contents.
2001   * @return {@code null}. The return value is always ignored.
2002   */
2003  public static double[] aryEq(double[] expectedValue) {
2004    return EasyMock.aryEq(expectedValue);
2005  }
2006
2007  /**
2008   * Expects a {@code float} array parameter that is equal to the given array, i.e. it has to
2009   * have the same length, and each element has to be equal.
2010   *
2011   * E.g.
2012   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myFloatrArray))).andReturn("hello");}
2013   *
2014   * Or, for illustration purposes (using static imports)
2015   *
2016   * {@code expect(mock.getString(eq(myFloatArray))).andReturn("hello");}
2017   *
2018   * If this method is used for anything other than to set a parameter expectation as part of a
2019   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2020   *
2021   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2022   * must have equal contents.
2023   * @return {@code null}. The return value is always ignored.
2024   */
2025  public static float[] aryEq(float[] expectedValue) {
2026    return EasyMock.aryEq(expectedValue);
2027  }
2028
2029  /**
2030   * Expects an {@code int} array parameter that is equal to the given array, i.e. it has to
2031   * have the same length, and each element has to be equal.
2032   *
2033   * E.g.
2034   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myIntArray))).andReturn("hello");}
2035   *
2036   * Or, for illustration purposes (using static imports)
2037   *
2038   * {@code expect(mock.getString(eq(myIntArray))).andReturn("hello");}
2039   *
2040   * If this method is used for anything other than to set a parameter expectation as part of a
2041   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2042   *
2043   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2044   * must have equal contents.
2045   * @return {@code null}. The return value is always ignored.
2046   */
2047  public static int[] aryEq(int[] expectedValue) {
2048    return EasyMock.aryEq(expectedValue);
2049  }
2050
2051  /**
2052   * Expects a {@code long} array parameter that is equal to the given array, i.e. it has to
2053   * have the same length, and each element has to be equal.
2054   *
2055   * E.g.
2056   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myLongArray))).andReturn("hello");}
2057   *
2058   * Or, for illustration purposes (using static imports)
2059   *
2060   * {@code expect(mock.getString(eq(myLongArray))).andReturn("hello");}
2061   *
2062   * If this method is used for anything other than to set a parameter expectation as part of a
2063   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2064   *
2065   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2066   * must have equal contents.
2067   * @return {@code null}. The return value is always ignored.
2068   */
2069  public static long[] aryEq(long[] expectedValue) {
2070    return EasyMock.aryEq(expectedValue);
2071  }
2072
2073  /**
2074   * Expects a {@code short} array parameter that is equal to the given array, i.e. it has to
2075   * have the same length, and each element has to be equal.
2076   *
2077   * E.g.
2078   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myShortArray))).andReturn("hello");}
2079   *
2080   * Or, for illustration purposes (using static imports)
2081   *
2082   * {@code expect(mock.getString(eq(myShortArray))).andReturn("hello");}
2083   *
2084   * If this method is used for anything other than to set a parameter expectation as part of a
2085   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2086   *
2087   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2088   * must have equal contents.
2089   * @return {@code null}. The return value is always ignored.
2090   */
2091  public static short[] aryEq(short[] expectedValue) {
2092    return EasyMock.aryEq(expectedValue);
2093  }
2094
2095  /**
2096   * Expects a {@code Object} array parameter that is equal to the given array, i.e. it has to
2097   * have the same length, and each element has to be equal.
2098   *
2099   * E.g.
2100   * {@code AndroidMock.expect(mock.getString(AndroidMock.eq(myObjectArray))).andReturn("hello");}
2101   *
2102   * Or, for illustration purposes (using static imports)
2103   *
2104   * {@code expect(mock.getString(eq(myObjectArray))).andReturn("hello");}
2105   *
2106   * If this method is used for anything other than to set a parameter expectation as part of a
2107   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2108   *
2109   * @param <T> the type of the array, it is passed through to prevent casts.
2110   * @param expectedValue the array to which the specified incoming parameter to the mocked method
2111   * must have equal contents.
2112   * @return {@code null}. The return value is always ignored.
2113   */
2114  public static <T> T[] aryEq(T[] expectedValue) {
2115    return EasyMock.aryEq(expectedValue);
2116  }
2117
2118  /**
2119   * Expects any {@code null} Object as a parameter.
2120   *
2121   * If this method is used for anything other than to set a parameter expectation as part of a
2122   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2123   *
2124   * @return {@code null}. The return value is always ignored.
2125   */
2126  @SuppressWarnings("unchecked")
2127  public static <T> T isNull() {
2128    return (T) EasyMock.isNull();
2129  }
2130
2131  /**
2132   * Expects any {@code non-null} Object parameter.
2133   *
2134   * If this method is used for anything other than to set a parameter expectation as part of a
2135   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2136   *
2137   * @return {@code null}. The return value is always ignored.
2138   */
2139  @SuppressWarnings("unchecked")
2140  public static <T> T notNull() {
2141    return (T) EasyMock.notNull();
2142  }
2143
2144  /**
2145   * Expects a {@code String} that contains a substring that matches the given regular
2146   * expression as a parameter to the mocked method.
2147   *
2148   * See {@link java.util.regex.Matcher#find()} for more details.
2149   *
2150   * If this method is used for anything other than to set a parameter expectation as part of a
2151   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2152   *
2153   * @param regex the regular expression which must match some substring of the incoming parameter
2154   * to the mocked method.
2155   * @return {@code null}. The return value is always ignored.
2156   */
2157  public static String find(String regex) {
2158    return EasyMock.find(regex);
2159  }
2160
2161  /**
2162   * Expects a {@code String} as a parameter to the mocked method, the entire length of which must
2163   * match the given regular expression. This is not to be confused with {@link #find(String)} which
2164   * matches the regular expression against any substring of the incoming parameter to the mocked
2165   * method.
2166   *
2167   * See {@link java.util.regex.Matcher#matches()} for more details.
2168   *
2169   * If this method is used for anything other than to set a parameter expectation as part of a
2170   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2171   *
2172   * @param regex the regular expression against which the entire incoming parameter to the
2173   * mocked method must match.
2174   * @return {@code null}. The return value is always ignored.
2175   */
2176  public static String matches(String regex) {
2177    return EasyMock.matches(regex);
2178  }
2179
2180  /**
2181   * Expects a {@code String} as a parameter to the mocked method that starts with the given prefix.
2182   *
2183   * See {@link java.lang.String#startsWith(String)} for more details.
2184   *
2185   * If this method is used for anything other than to set a parameter expectation as part of a
2186   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2187   *
2188   * @param prefix the string that is expected to match against the start of any incoming
2189   * parameter to the mocked method.
2190   * @return {@code null}. The return value is always ignored.
2191   */
2192  public static String startsWith(String prefix) {
2193    return EasyMock.startsWith(prefix);
2194  }
2195
2196  /**
2197   * Expects a {@code String} as a parameter to the mocked method that ends with the given
2198   * {@code suffix}.
2199   *
2200   * See {@link java.lang.String#startsWith(String)} for more details.
2201   *
2202   * If this method is used for anything other than to set a parameter expectation as part of a
2203   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2204   *
2205   * @param suffix the string that is expected to match against the end of any incoming
2206   * parameter to the mocked method.
2207   * @return {@code null}. The return value is always ignored.
2208   */
2209  public static String endsWith(String suffix) {
2210    return EasyMock.endsWith(suffix);
2211  }
2212
2213  /**
2214   * Expects a {@code double} as a parameter to the mocked method that has an absolute difference to
2215   * the given {@code expectedValue} that is less than the given {@code delta}.
2216   *
2217   * The acceptable range of values is theoretically defined as any value {@code x} which satisfies
2218   * the following inequality: {@code expectedValue - delta &lt;= x &lt;= expectedValue + delta}.
2219   *
2220   * In practice, this is only true when {@code expectedValue + delta} and
2221   * {@code expectedValue - delta} fall exactly on a precisely representable {@code double} value.
2222   * Normally, the acceptable range of values is defined as any value {@code x} which satisfies the
2223   * following inequality:
2224   * {@code expectedValue - delta &lt; x &lt; expectedValue + delta}.
2225   *
2226   * E.g. {@code AndroidMock.expect(mockObject.getString(
2227   *    AndroidMock.eq(42.0, 0.1))).andReturn("hello world");}
2228   *
2229   * The code snippet above will expect any {@code double} value greater than 41.9 and
2230   * less than 42.1.
2231   *
2232   * If this method is used for anything other than to set a parameter expectation as part of a
2233   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2234   *
2235   * @param expectedValue the center value of the expected range of values.
2236   * @param delta the acceptable level of inaccuracy before this expectation fails.
2237   * @return {@code 0}. The return value is always ignored.
2238   */
2239  public static double eq(double expectedValue, double delta) {
2240    return EasyMock.eq(expectedValue, delta);
2241  }
2242
2243  /**
2244   * Expects a {@code float} as a parameter to the mocked method that has an absolute difference to
2245   * the given {@code expectedValue} that is less than the given {@code delta}.
2246   *
2247   * The acceptable range of values is theoretically defined as any value {@code x} which satisfies
2248   * the following inequality: {@code expectedValue - delta &lt;= x &lt;= expectedValue + delta}.
2249   *
2250   * In practice, this is only true when {@code expectedValue + delta} and
2251   * {@code expectedValue - delta} fall exactly on a precisely representable {@code float} value.
2252   * Normally, the acceptable range of values is defined as any value {@code x} which satisfies the
2253   * following inequality:
2254   * {@code expectedValue - delta &lt; x &lt; expectedValue + delta}.
2255   *
2256   * E.g. {@code AndroidMock.expect(mockObject.getString(
2257   *    AndroidMock.eq(42.0f, 0.1f))).andReturn("hello world");}
2258   *
2259   * The code snippet above will expect any {@code float} value greater than 41.9 and
2260   * less than 42.1.
2261   *
2262   * If this method is used for anything other than to set a parameter expectation as part of a
2263   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2264   *
2265   * @param expectedValue the center value of the expected range of values.
2266   * @param delta the acceptable level of inaccuracy before this expectation fails.
2267   * @return {@code 0}. The return value is always ignored.
2268   */
2269  public static float eq(float expectedValue, float delta) {
2270    return EasyMock.eq(expectedValue, delta);
2271  }
2272
2273  /**
2274   * Expects an {@code Object} as a parameter to the mocked method that is the same as the given
2275   * value. This expectation will fail unless the incoming parameter is {@code ==} to the
2276   * {@code expectedValue} provided (i.e. the same {@code Object} reference).
2277   *
2278   * If this method is used for anything other than to set a parameter expectation as part of a
2279   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2280   *
2281   * @param <T> the type of the object, it is passed through to prevent casts.
2282   * @param expectedValue the exact object which is expected during replay.
2283   * @return {@code null}. The return value is always ignored.
2284   */
2285  public static <T> T same(T expectedValue) {
2286    return EasyMock.same(expectedValue);
2287  }
2288
2289  /**
2290   * Expects a {@link java.lang.Comparable} argument equal to the given value according to
2291   * its {@link java.lang.Comparable#compareTo(Object)} method.
2292   *
2293   * If this method is used for anything other than to set a parameter expectation as part of a
2294   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2295   *
2296   * @param expectedValue the {@link java.lang.Comparable} value which is expected to be equal to
2297   * the incoming parameter to the mocked method according to the
2298   * {@link java.lang.Comparable#compareTo(Object)} method.
2299   * @return {@code null}. The return value is always ignored.
2300   */
2301  public static <T extends Comparable<T>> T cmpEq(Comparable<T> expectedValue) {
2302    return EasyMock.cmpEq(expectedValue);
2303  }
2304
2305  /**
2306   * Expects an argument that will be compared using the provided {@link java.util.Comparator}, the
2307   * result of which will then be applied to the provided {@link org.easymock.LogicalOperator}
2308   * (e.g. {@link org.easymock.LogicalOperator#LESS_THAN},
2309   * {@link org.easymock.LogicalOperator#EQUAL},
2310   * {@link org.easymock.LogicalOperator#GREATER_OR_EQUAL}).
2311   *
2312   * The following comparison will take place:
2313   * {@code comparator.compare(actual, expected) operator 0}
2314   *
2315   * E.g.
2316   * For illustration purposes (using static imports):
2317   *
2318   * {@code
2319   * expect(mockObject.getString(cmp("hi", CASE_INSENSITIVE_ORDER, LESS_THAN))).andReturn("hello");}
2320   *
2321   * {@code
2322   * AndroidMock.expect(mockObject.getString(AndroidMock.cmp("hi", String.CASE_INSENSITIVE_ORDER,
2323   *    LogicalOperator.LESS_THAN))).andReturn("hello");}
2324   *
2325   *
2326   * The above invocation indicates that the call to {@code mockObject.getString(String)} is
2327   * expecting any String which is lexically before "hi" (in a case insensitive ordering).
2328   *
2329   * If this method is used for anything other than to set a parameter expectation as part of a
2330   * mock object's recording phase, then an {@code IllegalStateException} will be thrown.
2331   *
2332   * @param expectedValue the expected value against which the incoming method parameter will be
2333   * compared.
2334   * @param comparator {@link java.util.Comparator} used to perform the comparison between the
2335   * expected value and the incoming parameter to the mocked method.
2336   * @param operator The comparison operator, usually one of
2337   * {@link org.easymock.LogicalOperator#LESS_THAN},
2338   * {@link org.easymock.LogicalOperator#LESS_OR_EQUAL},
2339   * {@link org.easymock.LogicalOperator#EQUAL}, {@link org.easymock.LogicalOperator#GREATER},
2340   * {@link org.easymock.LogicalOperator#GREATER_OR_EQUAL}
2341   * @return {@code null}. The return value is always ignored.
2342   */
2343  public static <T> T cmp(T expectedValue, Comparator<? super T> comparator,
2344      LogicalOperator operator) {
2345    return EasyMock.cmp(expectedValue, comparator, operator);
2346  }
2347
2348  /**
2349   * Expect any {@code Object} as a parameter to the mocked method, but capture it for later use.
2350   *
2351   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2352   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2353   *
2354   * @param <T> Type of the captured object
2355   * @param captured a container to hold the captured value, retrieved by
2356   * {@link org.easymock.Capture#getValue()}
2357   * @return {@code null}. The return value is always ignored.
2358   */
2359  public static <T> T capture(Capture<T> captured) {
2360    return EasyMock.capture(captured);
2361  }
2362
2363  /**
2364   * Expect any {@code int/Integer} as a parameter to the mocked method, but capture it for later
2365   * use.
2366   *
2367   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2368   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2369   *
2370   * @param captured a container to hold the captured value, retrieved by
2371   * {@link org.easymock.Capture#getValue()}
2372   * @return {@code 0}. The return value is always ignored.
2373   */
2374  public static int capture(Capture<Integer> captured) {
2375    return EasyMock.capture(captured);
2376  }
2377
2378  /**
2379   * Expect any {@code long/Long} as a parameter to the mocked method, but capture it for later
2380   * use.
2381   *
2382   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2383   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2384   *
2385   * @param captured a container to hold the captured value, retrieved by
2386   * {@link org.easymock.Capture#getValue()}
2387   * @return {@code 0}. The return value is always ignored.
2388   */
2389  public static long capture(Capture<Long> captured) {
2390    return EasyMock.capture(captured);
2391  }
2392
2393  /**
2394   * Expect any {@code float/Float} as a parameter to the mocked method, but capture it for later
2395   * use.
2396   *
2397   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2398   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2399   *
2400   * @param captured a container to hold the captured value, retrieved by
2401   * {@link org.easymock.Capture#getValue()}
2402   * @return {@code 0}. The return value is always ignored.
2403   */
2404  public static float capture(Capture<Float> captured) {
2405    return EasyMock.capture(captured);
2406  }
2407
2408  /**
2409   * Expect any {@code double/Double} as a parameter to the mocked method, but capture it for later
2410   * use.
2411   *
2412   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2413   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2414   *
2415   * @param captured a container to hold the captured value, retrieved by
2416   * {@link org.easymock.Capture#getValue()}
2417   * @return {@code 0}. The return value is always ignored.
2418   */
2419  public static double capture(Capture<Double> captured) {
2420    return EasyMock.capture(captured);
2421  }
2422
2423  /**
2424   * Expect any {@code byte/Byte} as a parameter to the mocked method, but capture it for later
2425   * use.
2426   *
2427   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2428   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2429   *
2430   * @param captured a container to hold the captured value, retrieved by
2431   * {@link org.easymock.Capture#getValue()}
2432   * @return {@code 0}
2433   */
2434  public static byte capture(Capture<Byte> captured) {
2435    return EasyMock.capture(captured);
2436  }
2437
2438  /**
2439   * Expect any {@code char/Character} as a parameter to the mocked method, but capture it for later
2440   * use.
2441   *
2442   * {@link org.easymock.Capture} allows for capturing of the incoming value. Use
2443   * {@link org.easymock.Capture#getValue()} to retrieve the captured value.
2444   *
2445   * @param captured a container to hold the captured value, retrieved by
2446   * {@link org.easymock.Capture#getValue()}
2447   * @return {@code 0}
2448   */
2449  public static char capture(Capture<Character> captured) {
2450    return EasyMock.capture(captured);
2451  }
2452
2453  /**
2454   * Switches the given mock objects (more exactly: the controls of the mock
2455   * objects) to replay mode.
2456   *
2457   * @param mocks the mock objects.
2458   */
2459  public static void replay(Object... mocks) {
2460    for (Object mockObject : mocks) {
2461      if (mockObject instanceof MockObject) {
2462        EasyMock.replay(((MockObject) mockObject).getDelegate___AndroidMock());
2463      } else {
2464        EasyMock.replay(mockObject);
2465      }
2466    }
2467  }
2468
2469  /**
2470   * Resets the given mock objects (more exactly: the controls of the mock
2471   * objects) allowing the mock objects to be reused.
2472   *
2473   * @param mocks the mock objects.
2474   */
2475  public static void reset(Object... mocks) {
2476    for (Object mockObject : mocks) {
2477      if (mockObject instanceof MockObject) {
2478        EasyMock.reset(((MockObject) mockObject).getDelegate___AndroidMock());
2479      } else {
2480        EasyMock.reset(mockObject);
2481      }
2482    }
2483  }
2484
2485  /**
2486   * Resets the given mock objects (more exactly: the controls of the mock
2487   * objects) and change them in to mocks with nice behavior.
2488   * {@link #createNiceMock(Class, Object...)} has more details.
2489   *
2490   * @param mocks the mock objects
2491   */
2492  public static void resetToNice(Object... mocks) {
2493    for (Object mockObject : mocks) {
2494      if (mockObject instanceof MockObject) {
2495        EasyMock.resetToNice(((MockObject) mockObject).getDelegate___AndroidMock());
2496      } else {
2497        EasyMock.resetToNice(mockObject);
2498      }
2499    }
2500  }
2501
2502  /**
2503   * Resets the given mock objects (more exactly: the controls of the mock
2504   * objects) and turn them to a mock with default behavior. {@link #createMock(Class, Object...)}
2505   * has more details.
2506   *
2507   * @param mocks the mock objects
2508   */
2509  public static void resetToDefault(Object... mocks) {
2510    for (Object mockObject : mocks) {
2511      if (mockObject instanceof MockObject) {
2512        EasyMock.resetToDefault(((MockObject) mockObject).getDelegate___AndroidMock());
2513      } else {
2514        EasyMock.resetToDefault(mockObject);
2515      }
2516    }
2517  }
2518
2519  /**
2520   * Resets the given mock objects (more exactly: the controls of the mock
2521   * objects) and turn them to a mock with strict behavior.
2522   * {@link #createStrictMock(Class, Object...)} has more details.
2523   *
2524   * @param mocks the mock objects
2525   */
2526  public static void resetToStrict(Object... mocks) {
2527    for (Object mockObject : mocks) {
2528      if (mockObject instanceof MockObject) {
2529        EasyMock.resetToStrict(((MockObject) mockObject).getDelegate___AndroidMock());
2530      } else {
2531        EasyMock.resetToStrict(mockObject);
2532      }
2533    }
2534  }
2535
2536  /**
2537   * Verifies that all of the expected method calls for the given mock objects (more exactly: the
2538   * controls of the mock objects) have been executed.
2539   *
2540   * The {@code verify} method captures the scenario where several methods were invoked correctly,
2541   * but some invocations did not occur. Typically, the {@code verify} method is the final thing
2542   * invoked in a test.
2543   *
2544   * @param mocks the mock objects.
2545   */
2546  public static void verify(Object... mocks) {
2547    for (Object mockObject : mocks) {
2548      if (mockObject instanceof MockObject) {
2549        EasyMock.verify(((MockObject) mockObject).getDelegate___AndroidMock());
2550      } else {
2551        EasyMock.verify(mockObject);
2552      }
2553    }
2554  }
2555
2556  /**
2557   * Switches order checking of the given mock object (more exactly: the control
2558   * of the mock object) on or off. When order checking is on, the mock will expect the method
2559   * invokations to occur exactly in the order in which they appeared during the recording phase.
2560   *
2561   * @param mock the mock object.
2562   * @param orderCheckingOn {@code true} to turn order checking on, {@code false} to turn it off.
2563   */
2564  public static void checkOrder(Object mock, boolean orderCheckingOn) {
2565    if (mock instanceof MockObject) {
2566      EasyMock.checkOrder(((MockObject) mock).getDelegate___AndroidMock(), orderCheckingOn);
2567    } else {
2568      EasyMock.checkOrder(mock, orderCheckingOn);
2569    }
2570  }
2571
2572  /**
2573   * Reports an argument matcher. This method is needed to define custom argument
2574   * matchers.
2575   *
2576   * For example:
2577   *
2578   * {@code
2579   * AndroidMock.reportMatcher(new IntIsFortyTwo());
2580   * AndroidMock.expect(mockObject.getString(null)).andReturn("hello world");}
2581   *
2582   * This example will expect a parameter for {@code mockObject.getString(int)} that matches the
2583   * conditions required by the {@code matches} method as defined by
2584   * {@link org.easymock.IArgumentMatcher#matches(Object)}.
2585   *
2586   * @param matcher the matcher whose {@code matches} method will be applied to the incoming
2587   * parameter to the mocked method.
2588   */
2589  public static void reportMatcher(IArgumentMatcher matcher) {
2590    EasyMock.reportMatcher(matcher);
2591  }
2592
2593  /**
2594   * Returns the arguments of the current mock method call, if inside an
2595   * {@code IAnswer} callback - be careful here, reordering parameters of a
2596   * method changes the semantics of your tests.
2597   *
2598   * This method is only usable within an {@link org.easymock.IAnswer} instance. Attach an
2599   * {@link org.easymock.IAnswer} to an expectation by using the
2600   * {@link org.easymock.IExpectationSetters#andAnswer(org.easymock.IAnswer)} method.
2601   *
2602   * E.g.
2603   * {@code AndroidMock.expect(mockObject.getString()).andAnswer(myAnswerCallback);}
2604   *
2605   * @return the arguments of the current mock method call.
2606   * @throws IllegalStateException if called outside of {@code IAnswer}
2607   *         callbacks.
2608   */
2609  public static Object[] getCurrentArguments() {
2610    return EasyMock.getCurrentArguments();
2611  }
2612
2613  /**
2614   * Makes the mock thread safe. The mock will be usable in a multithreaded
2615   * environment.
2616   *
2617   * @param mock the mock to make thread safe.
2618   * @param threadSafe If the mock should be thread safe or not.
2619   */
2620  public static void makeThreadSafe(Object mock, boolean threadSafe) {
2621    if (mock instanceof MockObject) {
2622      EasyMock.makeThreadSafe(((MockObject) mock).getDelegate___AndroidMock(), threadSafe);
2623    } else {
2624      EasyMock.makeThreadSafe(mock, threadSafe);
2625    }
2626  }
2627
2628  @SuppressWarnings("unchecked")
2629  private static <T, S> T getSubclassFor(Class<? super T> clazz, Class<S> delegateInterface,
2630      Object realMock, Object... args) {
2631    Class<T> subclass;
2632    String className = null;
2633    try {
2634      if (isAndroidClass(clazz)) {
2635        className = FileUtils.getSubclassNameFor(clazz, SdkVersion.getCurrentVersion());
2636      } else {
2637        className = FileUtils.getSubclassNameFor(clazz, SdkVersion.UNKNOWN);
2638      }
2639      subclass = (Class<T>) Class.forName(className);
2640    } catch (ClassNotFoundException e) {
2641      throw new RuntimeException("Could not find class for " + className
2642          + " which likely means that the mock-instrumented jar has not been created or else"
2643          + " is not being used in the current runtime environment. Try running MockGeneratorMain"
2644          + " in MockGenerator_deploy.jar or using the output of that execution as the input to"
2645          + " the dex/apk generation.", e);
2646    }
2647    Constructor<T> constructor = getConstructorFor(subclass, args);
2648    T newObject;
2649    try {
2650      newObject = constructor.newInstance(args);
2651    } catch (InstantiationException e) {
2652      throw new RuntimeException("Internal error instantiating new mock subclass"
2653          + subclass.getName(), e);
2654    } catch (IllegalAccessException e) {
2655      throw new RuntimeException(
2656          "Internal error - the new mock subclass' constructor was inaccessible", e);
2657    } catch (InvocationTargetException e) {
2658      throw new ExceptionInInitializerError(e);
2659    }
2660    Method[] methods = subclass.getMethods();
2661    Method setMethod;
2662    try {
2663      setMethod = subclass.getMethod("setDelegate___AndroidMock", delegateInterface);
2664    } catch (NoSuchMethodException e) {
2665      throw new RuntimeException("Internal error - No setDelegate method found for " + "class "
2666          + subclass.getName() + " and param " + delegateInterface.getName(), e);
2667    }
2668    try {
2669      setMethod.invoke(newObject, realMock);
2670    } catch (IllegalArgumentException e) {
2671      throw new IllegalArgumentException("Internal error setting the delegate, expected "
2672          + newObject.getClass() + " to be subclass of " + clazz.getName());
2673    } catch (InvocationTargetException e) {
2674      throw new RuntimeException("Severe internal error, setDelegate threw an exception", e);
2675    } catch (IllegalAccessException e) {
2676      throw new RuntimeException("Internal error, setDelegate method was inaccessible", e);
2677    }
2678    return newObject;
2679  }
2680
2681  static boolean isUnboxableToPrimitive(Class<?> clazz, Object arg, boolean exactMatch) {
2682    if (!clazz.isPrimitive()) {
2683      throw new IllegalArgumentException(
2684          "Internal Error - The class to test against is not a primitive");
2685    }
2686    Class<?> unboxedType = null;
2687    if (arg.getClass().equals(Integer.class)) {
2688      unboxedType = Integer.TYPE;
2689    } else if (arg.getClass().equals(Long.class)) {
2690      unboxedType = Long.TYPE;
2691    } else if (arg.getClass().equals(Byte.class)) {
2692      unboxedType = Byte.TYPE;
2693    } else if (arg.getClass().equals(Short.class)) {
2694      unboxedType = Short.TYPE;
2695    } else if (arg.getClass().equals(Character.class)) {
2696      unboxedType = Character.TYPE;
2697    } else if (arg.getClass().equals(Float.class)) {
2698      unboxedType = Float.TYPE;
2699    } else if (arg.getClass().equals(Double.class)) {
2700      unboxedType = Double.TYPE;
2701    } else if (arg.getClass().equals(Boolean.class)) {
2702      unboxedType = Boolean.TYPE;
2703    } else {
2704      return false;
2705    }
2706    if (exactMatch) {
2707      return clazz == unboxedType;
2708    }
2709    return isAssignable(clazz, unboxedType);
2710  }
2711
2712  private static boolean isAssignable(Class<?> to, Class<?> from) {
2713    if (to == Byte.TYPE) {
2714      return from == Byte.TYPE;
2715    } else if (to == Short.TYPE){
2716      return from == Byte.TYPE || from == Short.TYPE || from == Character.TYPE;
2717    } else if (to == Integer.TYPE || to == Character.TYPE) {
2718      return from == Byte.TYPE || from == Short.TYPE || from == Integer.TYPE
2719          || from == Character.TYPE;
2720    } else if (to == Long.TYPE) {
2721      return from == Byte.TYPE || from == Short.TYPE || from == Integer.TYPE || from == Long.TYPE
2722          || from == Character.TYPE;
2723    } else if (to == Float.TYPE) {
2724      return from == Byte.TYPE || from == Short.TYPE || from == Integer.TYPE
2725          || from == Character.TYPE || from == Float.TYPE;
2726    } else if (to == Double.TYPE) {
2727      return from == Byte.TYPE || from == Short.TYPE || from == Integer.TYPE || from == Long.TYPE
2728          || from == Character.TYPE || from == Float.TYPE || from == Double.TYPE;
2729    } else if (to == Boolean.TYPE) {
2730      return from == Boolean.TYPE;
2731    } else {
2732      return to.isAssignableFrom(from);
2733    }
2734  }
2735
2736  @SuppressWarnings("unchecked")
2737  static <T> Constructor<T> getConstructorFor(Class<T> clazz, Object... args)
2738      throws SecurityException {
2739    Constructor<T>[] constructors = (Constructor<T>[]) clazz.getConstructors();
2740    Constructor<T> compatibleConstructor = null;
2741    for (Constructor<T> constructor : constructors) {
2742      Class<?>[] params = constructor.getParameterTypes();
2743      if (params.length == args.length) {
2744        boolean exactMatch = true;
2745        boolean compatibleMatch = true;
2746        for (int i = 0; i < params.length; ++i) {
2747          Object arg = args[i];
2748          if (arg == null) {
2749            arg = Void.TYPE;
2750          }
2751          if (!params[i].isAssignableFrom(arg.getClass())) {
2752            if (params[i].isPrimitive()) {
2753              exactMatch &= isUnboxableToPrimitive(params[i], arg, true);
2754              compatibleMatch &= isUnboxableToPrimitive(params[i], arg, false);
2755            } else {
2756              exactMatch = false;
2757              compatibleMatch = false;
2758            }
2759          }
2760        }
2761        if (exactMatch) {
2762          return constructor;
2763        } else if (compatibleMatch) {
2764          compatibleConstructor = constructor;
2765        }
2766      }
2767    }
2768    if (compatibleConstructor != null) {
2769      return compatibleConstructor;
2770    }
2771    List<String> argTypes = new ArrayList<String>(args.length);
2772    for (Object arg : args) {
2773      argTypes.add(arg == null ? "<null>" : arg.getClass().toString());
2774    }
2775    throw new IllegalArgumentException("Could not find the specified Constructor: "
2776        + clazz.getName() + "(" + argTypes + ")");
2777  }
2778
2779  @SuppressWarnings("unchecked")
2780  private static <T> Class<T> getInterfaceFor(Class<T> clazz) {
2781    try {
2782      String className;
2783      if (isAndroidClass(clazz)) {
2784        className = FileUtils.getInterfaceNameFor(clazz, SdkVersion.getCurrentVersion());
2785      } else {
2786        className = FileUtils.getInterfaceNameFor(clazz, SdkVersion.UNKNOWN);
2787      }
2788      return (Class<T>) Class.forName(className);
2789    } catch (ClassNotFoundException e) {
2790      throw new RuntimeException("Could not find mock for " + clazz.getName()
2791          + "  -- Make sure to run the MockGenerator.jar on your test jar, and to "
2792          + "build the Android test APK using the modified jar created by MockGenerator", e);
2793    }
2794  }
2795
2796  static boolean isAndroidClass(Class<?> clazz) {
2797    String packageName = clazz.getPackage().getName();
2798    return packageName.startsWith("android.") || packageName.startsWith("dalvik.")
2799        || packageName.startsWith("java.") || packageName.startsWith("javax.")
2800        || packageName.startsWith("org.xml.sax") || packageName.startsWith("org.xmlpull.v1")
2801        || packageName.startsWith("org.w3c.dom") || packageName.startsWith("org.apache.http")
2802        || packageName.startsWith("junit.");
2803  }
2804}
2805