Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
239   1 632   133   1,91
4   509   0,56   125
125     1,06  
1    
 
 
  EasyMock       Line # 15 239 133 100% 1.0
 
  (294)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock;
6   
7    import java.lang.reflect.Proxy;
8    import java.util.Comparator;
9   
10    import org.easymock.internal.LastControl;
11    import org.easymock.internal.MocksControl;
12    import org.easymock.internal.ObjectMethodsFilter;
13    import org.easymock.internal.matchers.*;
14   
 
15    public class EasyMock {
16   
17    /**
18    * Creates a mock object that implements the given interface, order checking
19    * is enabled by default.
20    *
21    * @param <T>
22    * the interface that the mock object should implement.
23    * @param toMock
24    * the class of the interface that the mock object should
25    * implement.
26    * @return the mock object.
27    */
 
28  15 toggle public static <T> T createStrictMock(Class<T> toMock) {
29  15 return createStrictControl().createMock(toMock);
30    }
31   
32    /**
33    * Creates a mock object that implements the given interface, order checking
34    * is enabled by default.
35    * @param name the name of the mock object.
36    * @param toMock
37    * the class of the interface that the mock object should
38    * implement.
39    * @param <T>
40    * the interface that the mock object should implement.
41    * @return the mock object.
42    * @throws IllegalArgumentException if the name is not a valid Java identifier.
43    */
 
44  1 toggle public static <T> T createStrictMock(String name, Class<T> toMock) {
45  1 return createStrictControl().createMock(name, toMock);
46    }
47   
48    /**
49    * Creates a mock object that implements the given interface, order checking
50    * is disabled by default.
51    *
52    * @param <T>
53    * the interface that the mock object should implement.
54    * @param toMock
55    * the class of the interface that the mock object should
56    * implement.
57    * @return the mock object.
58    */
 
59  65 toggle public static <T> T createMock(Class<T> toMock) {
60  65 return createControl().createMock(toMock);
61    }
62   
63    /**
64    * Creates a mock object that implements the given interface, order checking
65    * is disabled by default.
66    * @param name the name of the mock object.
67    * @param toMock
68    * the class of the interface that the mock object should
69    * implement.
70    *
71    * @param <T>
72    * the interface that the mock object should implement.
73    * @return the mock object.
74    * @throws IllegalArgumentException if the name is not a valid Java identifier.
75    */
 
76  2 toggle public static <T> T createMock(String name, Class<T> toMock) {
77  2 return createControl().createMock(name, toMock);
78    }
79   
80    /**
81    * Creates a mock object that implements the given interface, order checking
82    * is disabled by default, and the mock object will return <code>0</code>,
83    * <code>null</code> or <code>false</code> for unexpected invocations.
84    *
85    * @param <T>
86    * the interface that the mock object should implement.
87    * @param toMock
88    * the class of the interface that the mock object should
89    * implement.
90    * @return the mock object.
91    */
 
92  5 toggle public static <T> T createNiceMock(Class<T> toMock) {
93  5 return createNiceControl().createMock(toMock);
94    }
95   
96    /**
97    * Creates a mock object that implements the given interface, order checking
98    * is disabled by default, and the mock object will return <code>0</code>,
99    * <code>null</code> or <code>false</code> for unexpected invocations.
100    * @param name the name of the mock object.
101    * @param toMock
102    * the class of the interface that the mock object should
103    * implement.
104    *
105    * @param <T>
106    * the interface that the mock object should implement.
107    * @return the mock object.
108    * @throws IllegalArgumentException if the name is not a valid Java identifier.
109    */
 
110  1 toggle public static <T> T createNiceMock(String name, Class<T> toMock) {
111  1 return createNiceControl().createMock(name, toMock);
112    }
113   
114    /**
115    * Creates a control, order checking is enabled by default.
116    *
117    * @return the control.
118    */
 
119  50 toggle public static IMocksControl createStrictControl() {
120  50 return new MocksControl(MocksControl.MockType.STRICT);
121    }
122   
123    /**
124    * Creates a control, order checking is disabled by default.
125    *
126    * @return the control.
127    */
 
128  421 toggle public static IMocksControl createControl() {
129  421 return new MocksControl(MocksControl.MockType.DEFAULT);
130    }
131   
132    /**
133    * Creates a control, order checking is disabled by default, and the mock
134    * objects created by this control will return <code>0</code>,
135    * <code>null</code> or <code>false</code> for unexpected invocations.
136    *
137    * @return the control.
138    */
 
139  15 toggle public static IMocksControl createNiceControl() {
140  15 return new MocksControl(MocksControl.MockType.NICE);
141    }
142   
143    /**
144    * Returns the expectation setter for the last expected invocation in the
145    * current thread.
146    *
147    * @param value
148    * the parameter is used to transport the type to the
149    * ExpectationSetter. It allows writing the expected call as
150    * argument, i.e.
151    * <code>expect(mock.getName()).andReturn("John Doe")<code>.
152    *
153    * @return the expectation setter.
154    */
 
155  201 toggle public static <T> IExpectationSetters<T> expect(T value) {
156  201 return EasyMock.getControlForLastCall();
157    }
158   
159    /**
160    * Returns the expectation setter for the last expected invocation in the
161    * current thread. This method is used for expected invocations on void
162    * methods.
163    *
164    * @return the expectation setter.
165    */
 
166  256 toggle public static <T> IExpectationSetters<T> expectLastCall() {
167  256 return getControlForLastCall();
168    }
169   
 
170  457 toggle @SuppressWarnings("unchecked")
171    private static <T> IExpectationSetters<T> getControlForLastCall() {
172  457 MocksControl lastControl = LastControl.lastControl();
173  457 if (lastControl == null) {
174  87 throw new IllegalStateException("no last call on a mock available");
175    }
176  370 return (IExpectationSetters<T>) lastControl;
177    }
178   
179    /**
180    * Expects any boolean argument. For details, see the EasyMock
181    * documentation.
182    *
183    * @return <code>false</code>.
184    */
 
185  1 toggle public static boolean anyBoolean() {
186  1 reportMatcher(Any.ANY);
187  1 return false;
188    }
189   
190    /**
191    * Expects any byte argument. For details, see the EasyMock documentation.
192    *
193    * @return <code>0</code>.
194    */
 
195  1 toggle public static byte anyByte() {
196  1 reportMatcher(Any.ANY);
197  1 return 0;
198    }
199   
200    /**
201    * Expects any char argument. For details, see the EasyMock documentation.
202    *
203    * @return <code>0</code>.
204    */
 
205  1 toggle public static char anyChar() {
206  1 reportMatcher(Any.ANY);
207  1 return 0;
208    }
209   
210    /**
211    * Expects any int argument. For details, see the EasyMock documentation.
212    *
213    * @return <code>0</code>.
214    */
 
215  3 toggle public static int anyInt() {
216  3 reportMatcher(Any.ANY);
217  3 return 0;
218    }
219   
220    /**
221    * Expects any long argument. For details, see the EasyMock documentation.
222    *
223    * @return <code>0</code>.
224    */
 
225  1 toggle public static long anyLong() {
226  1 reportMatcher(Any.ANY);
227  1 return 0;
228    }
229   
230    /**
231    * Expects any float argument. For details, see the EasyMock documentation.
232    *
233    * @return <code>0</code>.
234    */
 
235  1 toggle public static float anyFloat() {
236  1 reportMatcher(Any.ANY);
237  1 return 0;
238    }
239   
240    /**
241    * Expects any double argument. For details, see the EasyMock documentation.
242    *
243    * @return <code>0</code>.
244    */
 
245  1 toggle public static double anyDouble() {
246  1 reportMatcher(Any.ANY);
247  1 return 0;
248    }
249   
250    /**
251    * Expects any short argument. For details, see the EasyMock documentation.
252    *
253    * @return <code>0</code>.
254    */
 
255  1 toggle public static short anyShort() {
256  1 reportMatcher(Any.ANY);
257  1 return 0;
258    }
259   
260    /**
261    * Expects any Object argument. For details, see the EasyMock documentation.
262    *
263    * @return <code>null</code>.
264    */
 
265  2 toggle public static <T> T anyObject() {
266  2 reportMatcher(Any.ANY);
267  2 return null;
268    }
269   
270    /**
271    * Expects a comparable argument greater than or equal the given value. For details, see
272    * the EasyMock documentation.
273    *
274    * @param value
275    * the given value.
276    * @return <code>null</code>.
277    */
 
278  1 toggle public static <T extends Comparable<T>> T geq(Comparable<T> value) {
279  1 reportMatcher(new GreaterOrEqual<T>(value));
280  1 return null;
281    }
282   
283    /**
284    * Expects a byte argument greater than or equal to the given value. For
285    * details, see the EasyMock documentation.
286    *
287    * @param value
288    * the given value.
289    * @return <code>0</code>.
290    */
 
291  1 toggle public static byte geq(byte value) {
292  1 reportMatcher(new GreaterOrEqual<Byte>(value));
293  1 return 0;
294    }
295   
296    /**
297    * Expects a double argument greater than or equal to the given value. For
298    * details, see the EasyMock documentation.
299    *
300    * @param value
301    * the given value.
302    * @return <code>0</code>.
303    */
 
304  1 toggle public static double geq(double value) {
305  1 reportMatcher(new GreaterOrEqual<Double>(value));
306  1 return 0;
307    }
308   
309    /**
310    * Expects a float argument greater than or equal to the given value. For
311    * details, see the EasyMock documentation.
312    *
313    * @param value
314    * the given value.
315    * @return <code>0</code>.
316    */
 
317  1 toggle public static float geq(float value) {
318  1 reportMatcher(new GreaterOrEqual<Float>(value));
319  1 return 0;
320    }
321   
322    /**
323    * Expects an int argument greater than or equal to the given value. For
324    * details, see the EasyMock documentation.
325    *
326    * @param value
327    * the given value.
328    * @return <code>0</code>.
329    */
 
330  4 toggle public static int geq(int value) {
331  4 reportMatcher(new GreaterOrEqual<Integer>(value));
332  4 return 0;
333    }
334   
335    /**
336    * Expects a long argument greater than or equal to the given value. For
337    * details, see the EasyMock documentation.
338    *
339    * @param value
340    * the given value.
341    * @return <code>0</code>.
342    */
 
343  1 toggle public static long geq(long value) {
344  1 reportMatcher(new GreaterOrEqual<Long>(value));
345  1 return 0;
346    }
347   
348    /**
349    * Expects a short argument greater than or equal to the given value. For
350    * details, see the EasyMock documentation.
351    *
352    * @param value
353    * the given value.
354    * @return <code>0</code>.
355    */
 
356  1 toggle public static short geq(short value) {
357  1 reportMatcher(new GreaterOrEqual<Short>(value));
358  1 return 0;
359    }
360   
361    /**
362    * Expects a comparable argument less than or equal the given value. For details, see
363    * the EasyMock documentation.
364    *
365    * @param value
366    * the given value.
367    * @return <code>null</code>.
368    */
 
369  1 toggle public static <T extends Comparable<T>> T leq(Comparable<T> value) {
370  1 reportMatcher(new LessOrEqual<T>(value));
371  1 return null;
372    }
373   
374    /**
375    * Expects a byte argument less than or equal to the given value. For
376    * details, see the EasyMock documentation.
377    *
378    * @param value
379    * the given value.
380    * @return <code>0</code>.
381    */
 
382  1 toggle public static byte leq(byte value) {
383  1 reportMatcher(new LessOrEqual<Byte>(value));
384  1 return 0;
385    }
386   
387    /**
388    * Expects a double argument less than or equal to the given value. For
389    * details, see the EasyMock documentation.
390    *
391    * @param value
392    * the given value.
393    * @return <code>0</code>.
394    */
 
395  1 toggle public static double leq(double value) {
396  1 reportMatcher(new LessOrEqual<Double>(value));
397  1 return 0;
398    }
399   
400    /**
401    * Expects a float argument less than or equal to the given value. For
402    * details, see the EasyMock documentation.
403    *
404    * @param value
405    * the given value.
406    * @return <code>0</code>.
407    */
 
408  1 toggle public static float leq(float value) {
409  1 reportMatcher(new LessOrEqual<Float>(value));
410  1 return 0;
411    }
412   
413    /**
414    * Expects an int argument less than or equal to the given value. For
415    * details, see the EasyMock documentation.
416    *
417    * @param value
418    * the given value.
419    * @return <code>0</code>.
420    */
 
421  4 toggle public static int leq(int value) {
422  4 reportMatcher(new LessOrEqual<Integer>(value));
423  4 return 0;
424    }
425   
426    /**
427    * Expects a long argument less than or equal to the given value. For
428    * details, see the EasyMock documentation.
429    *
430    * @param value
431    * the given value.
432    * @return <code>0</code>.
433    */
 
434  1 toggle public static long leq(long value) {
435  1 reportMatcher(new LessOrEqual<Long>(value));
436  1 return 0;
437    }
438   
439    /**
440    * Expects a short argument less than or equal to the given value. For
441    * details, see the EasyMock documentation.
442    *
443    * @param value
444    * the given value.
445    * @return <code>0</code>.
446    */
 
447  1 toggle public static short leq(short value) {
448  1 reportMatcher(new LessOrEqual<Short>(value));
449  1 return 0;
450    }
451   
452    /**
453    * Expects a comparable argument greater than the given value. For details, see
454    * the EasyMock documentation.
455    *
456    * @param value
457    * the given value.
458    * @return <code>null</code>.
459    */
 
460  1 toggle public static <T extends Comparable<T>> T gt(Comparable<T> value) {
461  1 reportMatcher(new GreaterThan<T>(value));
462  1 return null;
463    }
464   
465    /**
466    * Expects a byte argument greater than the given value. For details, see
467    * the EasyMock documentation.
468    *
469    * @param value
470    * the given value.
471    * @return <code>0</code>.
472    */
 
473  1 toggle public static byte gt(byte value) {
474  1 reportMatcher(new GreaterThan<Byte>(value));
475  1 return 0;
476    }
477   
478    /**
479    * Expects a double argument greater than the given value. For details, see
480    * the EasyMock documentation.
481    *
482    * @param value
483    * the given value.
484    * @return <code>0</code>.
485    */
 
486  1 toggle public static double gt(double value) {
487  1 reportMatcher(new GreaterThan<Double>(value));
488  1 return 0;
489    }
490   
491    /**
492    * Expects a float argument greater than the given value. For details, see
493    * the EasyMock documentation.
494    *
495    * @param value
496    * the given value.
497    * @return <code>0</code>.
498    */
 
499  1 toggle public static float gt(float value) {
500  1 reportMatcher(new GreaterThan<Float>(value));
501  1 return 0;
502    }
503   
504    /**
505    * Expects an int argument greater than the given value. For details, see
506    * the EasyMock documentation.
507    *
508    * @param value
509    * the given value.
510    * @return <code>0</code>.
511    */
 
512  3 toggle public static int gt(int value) {
513  3 reportMatcher(new GreaterThan<Integer>(value));
514  3 return 0;
515    }
516   
517    /**
518    * Expects a long argument greater than the given value. For details, see
519    * the EasyMock documentation.
520    *
521    * @param value
522    * the given value.
523    * @return <code>0</code>.
524    */
 
525  1 toggle public static long gt(long value) {
526  1 reportMatcher(new GreaterThan<Long>(value));
527  1 return 0;
528    }
529   
530    /**
531    * Expects a short argument greater than the given value. For details, see
532    * the EasyMock documentation.
533    *
534    * @param value
535    * the given value.
536    * @return <code>0</code>.
537    */
 
538  1 toggle public static short gt(short value) {
539  1 reportMatcher(new GreaterThan<Short>(value));
540  1 return 0;
541    }
542   
543    /**
544    * Expects a comparable argument less than the given value. For details, see
545    * the EasyMock documentation.
546    *
547    * @param value
548    * the given value.
549    * @return <code>null</code>.
550    */
 
551  1 toggle public static <T extends Comparable<T>> T lt(Comparable<T> value) {
552  1 reportMatcher(new LessThan<T>(value));
553  1 return null;
554    }
555   
556    /**
557    * Expects a byte argument less than the given value. For details, see the
558    * EasyMock documentation.
559    *
560    * @param value
561    * the given value.
562    * @return <code>0</code>.
563    */
 
564  1 toggle public static byte lt(byte value) {
565  1 reportMatcher(new LessThan<Byte>(value));
566  1 return 0;
567    }
568   
569    /**
570    * Expects a double argument less than the given value. For details, see the
571    * EasyMock documentation.
572    *
573    * @param value
574    * the given value.
575    * @return <code>0</code>.
576    */
 
577  1 toggle public static double lt(double value) {
578  1 reportMatcher(new LessThan<Double>(value));
579  1 return 0;
580    }
581   
582    /**
583    * Expects a float argument less than the given value. For details, see the
584    * EasyMock documentation.
585    *
586    * @param value
587    * the given value.
588    * @return <code>0</code>.
589    */
 
590  1 toggle public static float lt(float value) {
591  1 reportMatcher(new LessThan<Float>(value));
592  1 return 0;
593    }
594   
595    /**
596    * Expects an int argument less than the given value. For details, see the
597    * EasyMock documentation.
598    *
599    * @param value
600    * the given value.
601    * @return <code>0</code>.
602    */
 
603  4 toggle public static int lt(int value) {
604  4 reportMatcher(new LessThan<Integer>(value));
605  4 return 0;
606    }
607   
608    /**
609    * Expects a long argument less than the given value. For details, see the
610    * EasyMock documentation.
611    *
612    * @param value
613    * the given value.
614    * @return <code>0</code>.
615    */
 
616  1 toggle public static long lt(long value) {
617  1 reportMatcher(new LessThan<Long>(value));
618  1 return 0;
619    }
620   
621    /**
622    * Expects a short argument less than the given value. For details, see the
623    * EasyMock documentation.
624    *
625    * @param value
626    * the given value.
627    * @return <code>0</code>.
628    */
 
629  1 toggle public static short lt(short value) {
630  1 reportMatcher(new LessThan<Short>(value));
631  1 return 0;
632    }
633   
634    /**
635    * Expects an object implementing the given class. For details, see the
636    * EasyMock documentation.
637    *
638    * @param <T>
639    * the accepted type.
640    * @param clazz
641    * the class of the accepted type.
642    * @return <code>null</code>.
643    */
 
644  3 toggle public static <T> T isA(Class<T> clazz) {
645  3 reportMatcher(new InstanceOf(clazz));
646  3 return null;
647    }
648   
649    /**
650    * Expects a string that contains the given substring. For details, see the
651    * EasyMock documentation.
652    *
653    * @param substring
654    * the substring.
655    * @return <code>null</code>.
656    */
 
657  6 toggle public static String contains(String substring) {
658  6 reportMatcher(new Contains(substring));
659  6 return null;
660    }
661   
662    /**
663    * Expects a boolean that matches both given expectations.
664    *
665    * @param first
666    * placeholder for the first expectation.
667    * @param second
668    * placeholder for the second expectation.
669    * @return <code>false</code>.
670    */
 
671  1 toggle public static boolean and(boolean first, boolean second) {
672  1 LastControl.reportAnd(2);
673  1 return false;
674    }
675   
676    /**
677    * Expects a byte that matches both given expectations.
678    *
679    * @param first
680    * placeholder for the first expectation.
681    * @param second
682    * placeholder for the second expectation.
683    * @return <code>0</code>.
684    */
 
685  1 toggle public static byte and(byte first, byte second) {
686  1 LastControl.reportAnd(2);
687  1 return 0;
688    }
689   
690    /**
691    * Expects a char that matches both given expectations.
692    *
693    * @param first
694    * placeholder for the first expectation.
695    * @param second
696    * placeholder for the second expectation.
697    * @return <code>0</code>.
698    */
 
699  1 toggle public static char and(char first, char second) {
700  1 LastControl.reportAnd(2);
701  1 return 0;
702    }
703   
704    /**
705    * Expects a double that matches both given expectations.
706    *
707    * @param first
708    * placeholder for the first expectation.
709    * @param second
710    * placeholder for the second expectation.
711    * @return <code>0</code>.
712    */
 
713  1 toggle public static double and(double first, double second) {
714  1 LastControl.reportAnd(2);
715  1 return 0;
716    }
717   
718    /**
719    * Expects a float that matches both given expectations.
720    *
721    * @param first
722    * placeholder for the first expectation.
723    * @param second
724    * placeholder for the second expectation.
725    * @return <code>0</code>.
726    */
 
727  1 toggle public static float and(float first, float second) {
728  1 LastControl.reportAnd(2);
729  1 return 0;
730    }
731   
732    /**
733    * Expects an int that matches both given expectations.
734    *
735    * @param first
736    * placeholder for the first expectation.
737    * @param second
738    * placeholder for the second expectation.
739    * @return <code>0</code>.
740    */
 
741  2 toggle public static int and(int first, int second) {
742  2 LastControl.reportAnd(2);
743  2 return 0;
744    }
745   
746    /**
747    * Expects a long that matches both given expectations.
748    *
749    * @param first
750    * placeholder for the first expectation.
751    * @param second
752    * placeholder for the second expectation.
753    * @return <code>0</code>.
754    */
 
755  1 toggle public static long and(long first, long second) {
756  1 LastControl.reportAnd(2);
757  1 return 0;
758    }
759   
760    /**
761    * Expects a short that matches both given expectations.
762    *
763    * @param first
764    * placeholder for the first expectation.
765    * @param second
766    * placeholder for the second expectation.
767    * @return <code>0</code>.
768    */
 
769  1 toggle public static short and(short first, short second) {
770  1 LastControl.reportAnd(2);
771  1 return 0;
772    }
773   
774    /**
775    * Expects an Object that matches both given expectations.
776    *
777    * @param <T>
778    * the type of the object, it is passed through to prevent casts.
779    * @param first
780    * placeholder for the first expectation.
781    * @param second
782    * placeholder for the second expectation.
783    * @return <code>null</code>.
784    */
 
785  4 toggle public static <T> T and(T first, T second) {
786  4 LastControl.reportAnd(2);
787  4 return null;
788    }
789   
790    /**
791    * Expects a boolean that matches one of the given expectations.
792    *
793    * @param first
794    * placeholder for the first expectation.
795    * @param second
796    * placeholder for the second expectation.
797    * @return <code>false</code>.
798    */
 
799  1 toggle public static boolean or(boolean first, boolean second) {
800  1 LastControl.reportOr(2);
801  1 return false;
802    }
803   
804    /**
805    * Expects a byte that matches one of the given expectations.
806    *
807    * @param first
808    * placeholder for the first expectation.
809    * @param second
810    * placeholder for the second expectation.
811    * @return <code>0</code>.
812    */
 
813  1 toggle public static byte or(byte first, byte second) {
814  1 LastControl.reportOr(2);
815  1 return 0;
816    }
817   
818    /**
819    * Expects a char that matches one of the given expectations.
820    *
821    * @param first
822    * placeholder for the first expectation.
823    * @param second
824    * placeholder for the second expectation.
825    * @return <code>0</code>.
826    */
 
827  1 toggle public static char or(char first, char second) {
828  1 LastControl.reportOr(2);
829  1 return 0;
830    }
831   
832    /**
833    * Expects a double that matches one of the given expectations.
834    *
835    * @param first
836    * placeholder for the first expectation.
837    * @param second
838    * placeholder for the second expectation.
839    * @return <code>0</code>.
840    */
 
841  1 toggle public static double or(double first, double second) {
842  1 LastControl.reportOr(2);
843  1 return 0;
844    }
845   
846    /**
847    * Expects a float that matches one of the given expectations.
848    *
849    * @param first
850    * placeholder for the first expectation.
851    * @param second
852    * placeholder for the second expectation.
853    * @return <code>0</code>.
854    */
 
855  1 toggle public static float or(float first, float second) {
856  1 LastControl.reportOr(2);
857  1 return 0;
858    }
859   
860    /**
861    * Expects an int that matches one of the given expectations.
862    *
863    * @param first
864    * placeholder for the first expectation.
865    * @param second
866    * placeholder for the second expectation.
867    * @return <code>0</code>.
868    */
 
869  2 toggle public static int or(int first, int second) {
870  2 LastControl.reportOr(2);
871  2 return first;
872    }
873   
874    /**
875    * Expects a long that matches one of the given expectations.
876    *
877    * @param first
878    * placeholder for the first expectation.
879    * @param second
880    * placeholder for the second expectation.
881    * @return <code>0</code>.
882    */
 
883  1 toggle public static long or(long first, long second) {
884  1 LastControl.reportOr(2);
885  1 return 0;
886    }
887   
888    /**
889    * Expects a short that matches one of the given expectations.
890    *
891    * @param first
892    * placeholder for the first expectation.
893    * @param second
894    * placeholder for the second expectation.
895    * @return <code>0</code>.
896    */
 
897  1 toggle public static short or(short first, short second) {
898  1 LastControl.reportOr(2);
899  1 return 0;
900    }
901   
902    /**
903    * Expects an Object that matches one of the given expectations.
904    *
905    * @param <T>
906    * the type of the object, it is passed through to prevent casts.
907    * @param first
908    * placeholder for the first expectation.
909    * @param second
910    * placeholder for the second expectation.
911    * @return <code>null</code>.
912    */
 
913  3 toggle public static <T> T or(T first, T second) {
914  3 LastControl.reportOr(2);
915  2 return null;
916    }
917   
918    /**
919    * Expects a boolean that does not match the given expectation.
920    *
921    * @param first
922    * placeholder for the expectation.
923    * @return <code>false</code>.
924    */
 
925  1 toggle public static boolean not(boolean first) {
926  1 LastControl.reportNot();
927  1 return false;
928    }
929   
930    /**
931    * Expects a byte that does not match the given expectation.
932    *
933    * @param first
934    * placeholder for the expectation.
935    * @return <code>0</code>.
936    */
 
937  1 toggle public static byte not(byte first) {
938  1 LastControl.reportNot();
939  1 return 0;
940    }
941   
942    /**
943    * Expects a char that does not match the given expectation.
944    *
945    * @param first
946    * placeholder for the expectation.
947    * @return <code>0</code>.
948    */
 
949  1 toggle public static char not(char first) {
950  1 LastControl.reportNot();
951  1 return 0;
952    }
953   
954    /**
955    * Expects a double that does not match the given expectation.
956    *
957    * @param first
958    * placeholder for the expectation.
959    * @return <code>0</code>.
960    */
 
961  1 toggle public static double not(double first) {
962  1 LastControl.reportNot();
963  1 return 0;
964    }
965   
966    /**
967    * Expects a float that does not match the given expectation.
968    *
969    * @param first
970    * placeholder for the expectation.
971    * @return <code>0</code>.
972    */
 
973  1 toggle public static float not(float first) {
974  1 LastControl.reportNot();
975  1 return first;
976    }
977   
978    /**
979    * Expects an int that does not match the given expectation.
980    *
981    * @param first
982    * placeholder for the expectation.
983    * @return <code>0</code>.
984    */
 
985  1 toggle public static int not(int first) {
986  1 LastControl.reportNot();
987  1 return 0;
988    }
989   
990    /**
991    * Expects a long that does not match the given expectation.
992    *
993    * @param first
994    * placeholder for the expectation.
995    * @return <code>0</code>.
996    */
 
997  1 toggle public static long not(long first) {
998  1 LastControl.reportNot();
999  1 return 0;
1000    }
1001   
1002    /**
1003    * Expects a short that does not match the given expectation.
1004    *
1005    * @param first
1006    * placeholder for the expectation.
1007    * @return <code>0</code>.
1008    */
 
1009  1 toggle public static short not(short first) {
1010  1 LastControl.reportNot();
1011  1 return 0;
1012    }
1013   
1014    /**
1015    * Expects an Object that does not match the given expectation.
1016    *
1017    * @param <T>
1018    * the type of the object, it is passed through to prevent casts.
1019    * @param first
1020    * placeholder for the expectation.
1021    * @return <code>null</code>.
1022    */
 
1023  6 toggle public static <T> T not(T first) {
1024  6 LastControl.reportNot();
1025  5 return null;
1026    }
1027   
1028    /**
1029    * Expects a boolean that is equal to the given value.
1030    *
1031    * @param value
1032    * the given value.
1033    * @return <code>0</code>.
1034    */
 
1035  5 toggle public static boolean eq(boolean value) {
1036  5 reportMatcher(new Equals(value));
1037  5 return false;
1038    }
1039   
1040    /**
1041    * Expects a byte that is equal to the given value.
1042    *
1043    * @param value
1044    * the given value.
1045    * @return <code>0</code>.
1046    */
 
1047  5 toggle public static byte eq(byte value) {
1048  5 reportMatcher(new Equals(value));
1049  5 return 0;
1050    }
1051   
1052    /**
1053    * Expects a char that is equal to the given value.
1054    *
1055    * @param value
1056    * the given value.
1057    * @return <code>0</code>.
1058    */
 
1059  5 toggle public static char eq(char value) {
1060  5 reportMatcher(new Equals(value));
1061  5 return 0;
1062    }
1063   
1064    /**
1065    * Expects a double that is equal to the given value.
1066    *
1067    * @param value
1068    * the given value.
1069    * @return <code>0</code>.
1070    */
 
1071  5 toggle public static double eq(double value) {
1072  5 reportMatcher(new Equals(value));
1073  5 return 0;
1074    }
1075   
1076    /**
1077    * Expects a float that is equal to the given value.
1078    *
1079    * @param value
1080    * the given value.
1081    * @return <code>0</code>.
1082    */
 
1083  5 toggle public static float eq(float value) {
1084  5 reportMatcher(new Equals(value));
1085  5 return 0;
1086    }
1087   
1088    /**
1089    * Expects an int that is equal to the given value.
1090    *
1091    * @param value
1092    * the given value.
1093    * @return <code>0</code>.
1094    */
 
1095  11 toggle public static int eq(int value) {
1096  11 reportMatcher(new Equals(value));
1097  11 return 0;
1098    }
1099   
1100    /**
1101    * Expects a long that is equal to the given value.
1102    *
1103    * @param value
1104    * the given value.
1105    * @return <code>0</code>.
1106    */
 
1107  5 toggle public static long eq(long value) {
1108  5 reportMatcher(new Equals(value));
1109  5 return 0;
1110    }
1111   
1112    /**
1113    * Expects a short that is equal to the given value.
1114    *
1115    * @param value
1116    * the given value.
1117    * @return <code>0</code>.
1118    */
 
1119  5 toggle public static short eq(short value) {
1120  5 reportMatcher(new Equals(value));
1121  5 return 0;
1122    }
1123   
1124    /**
1125    * Expects an Object that is equal to the given value.
1126    *
1127    * @param value
1128    * the given value.
1129    * @return <code>null</code>.
1130    */
 
1131  14 toggle public static <T> T eq(T value) {
1132  14 reportMatcher(new Equals(value));
1133  14 return null;
1134    }
1135   
1136    /**
1137    * Expects a boolean array that is equal to the given array, i.e. it has to
1138    * have the same length, and each element has to be equal.
1139    *
1140    * @param value
1141    * the given arry.
1142    * @return <code>null</code>.
1143    */
 
1144  1 toggle public static boolean[] aryEq(boolean[] value) {
1145  1 reportMatcher(new ArrayEquals(value));
1146  1 return null;
1147    }
1148   
1149    /**
1150    * Expects a byte array that is equal to the given array, i.e. it has to
1151    * have the same length, and each element has to be equal.
1152    *
1153    * @param value
1154    * the given arry.
1155    * @return <code>null</code>.
1156    */
 
1157  1 toggle public static byte[] aryEq(byte[] value) {
1158  1 reportMatcher(new ArrayEquals(value));
1159  1 return null;
1160    }
1161   
1162    /**
1163    * Expects a char array that is equal to the given array, i.e. it has to
1164    * have the same length, and each element has to be equal.
1165    *
1166    * @param value
1167    * the given arry.
1168    * @return <code>null</code>.
1169    */
 
1170  1 toggle public static char[] aryEq(char[] value) {
1171  1 reportMatcher(new ArrayEquals(value));
1172  1 return null;
1173    }
1174   
1175    /**
1176    * Expects a double array that is equal to the given array, i.e. it has to
1177    * have the same length, and each element has to be equal.
1178    *
1179    * @param value
1180    * the given arry.
1181    * @return <code>null</code>.
1182    */
 
1183  1 toggle public static double[] aryEq(double[] value) {
1184  1 reportMatcher(new ArrayEquals(value));
1185  1 return null;
1186    }
1187   
1188    /**
1189    * Expects a float array that is equal to the given array, i.e. it has to
1190    * have the same length, and each element has to be equal.
1191    *
1192    * @param value
1193    * the given arry.
1194    * @return <code>null</code>.
1195    */
 
1196  1 toggle public static float[] aryEq(float[] value) {
1197  1 reportMatcher(new ArrayEquals(value));
1198  1 return null;
1199    }
1200   
1201    /**
1202    * Expects an int array that is equal to the given array, i.e. it has to
1203    * have the same length, and each element has to be equal.
1204    *
1205    * @param value
1206    * the given arry.
1207    * @return <code>null</code>.
1208    */
 
1209  1 toggle public static int[] aryEq(int[] value) {
1210  1 reportMatcher(new ArrayEquals(value));
1211  1 return null;
1212    }
1213   
1214    /**
1215    * Expects a long array that is equal to the given array, i.e. it has to
1216    * have the same length, and each element has to be equal.
1217    *
1218    * @param value
1219    * the given arry.
1220    * @return <code>null</code>.
1221    */
 
1222  1 toggle public static long[] aryEq(long[] value) {
1223  1 reportMatcher(new ArrayEquals(value));
1224  1 return null;
1225    }
1226   
1227    /**
1228    * Expects a short array that is equal to the given array, i.e. it has to
1229    * have the same length, and each element has to be equal.
1230    *
1231    * @param value
1232    * the given arry.
1233    * @return <code>null</code>.
1234    */
 
1235  1 toggle public static short[] aryEq(short[] value) {
1236  1 reportMatcher(new ArrayEquals(value));
1237  1 return null;
1238    }
1239   
1240    /**
1241    * Expects an Object array that is equal to the given array, i.e. it has to
1242    * have the same type, length, and each element has to be equal.
1243    *
1244    * @param <T>
1245    * the type of the array, it is passed through to prevent casts.
1246    * @param value
1247    * the given arry.
1248    * @return <code>null</code>.
1249    */
 
1250  4 toggle public static <T> T[] aryEq(T[] value) {
1251  4 reportMatcher(new ArrayEquals(value));
1252  4 return null;
1253    }
1254   
1255    /**
1256    * Expects null.
1257    *
1258    * @return <code>null</code>.
1259    */
 
1260  3 toggle public static <T> T isNull() {
1261  3 reportMatcher(Null.NULL);
1262  3 return null;
1263    }
1264   
1265    /**
1266    * Expects not null.
1267    *
1268    * @return <code>null</code>.
1269    */
 
1270  5 toggle public static <T> T notNull() {
1271  5 reportMatcher(NotNull.NOT_NULL);
1272  5 return null;
1273    }
1274   
1275    /**
1276    * Expects a string that contains a substring that matches the given regular
1277    * expression. For details, see the EasyMock documentation.
1278    *
1279    * @param regex
1280    * the regular expression.
1281    * @return <code>null</code>.
1282    */
 
1283  2 toggle public static String find(String regex) {
1284  2 reportMatcher(new Find(regex));
1285  2 return null;
1286    }
1287   
1288    /**
1289    * Expects a string that matches the given regular expression. For details,
1290    * see the EasyMock documentation.
1291    *
1292    * @param regex
1293    * the regular expression.
1294    * @return <code>null</code>.
1295    */
 
1296  2 toggle public static String matches(String regex) {
1297  2 reportMatcher(new Matches(regex));
1298  2 return null;
1299    }
1300   
1301    /**
1302    * Expects a string that starts with the given prefix. For details, see the
1303    * EasyMock documentation.
1304    *
1305    * @param prefix
1306    * the prefix.
1307    * @return <code>null</code>.
1308    */
 
1309  2 toggle public static String startsWith(String prefix) {
1310  2 reportMatcher(new StartsWith(prefix));
1311  2 return null;
1312    }
1313   
1314    /**
1315    * Expects a string that ends with the given suffix. For details, see the
1316    * EasyMock documentation.
1317    *
1318    * @param suffix
1319    * the suffix.
1320    * @return <code>null</code>.
1321    */
 
1322  2 toggle public static String endsWith(String suffix) {
1323  2 reportMatcher(new EndsWith(suffix));
1324  2 return null;
1325    }
1326   
1327    /**
1328    * Expects a double that has an absolute difference to the given value that
1329    * is less than the given delta. For details, see the EasyMock
1330    * documentation.
1331    *
1332    * @param value
1333    * the given value.
1334    * @param delta
1335    * the given delta.
1336    * @return <code>0</code>.
1337    */
 
1338  2 toggle public static double eq(double value, double delta) {
1339  2 reportMatcher(new EqualsWithDelta(value, delta));
1340  2 return 0;
1341    }
1342   
1343    /**
1344    * Expects a float that has an absolute difference to the given value that
1345    * is less than the given delta. For details, see the EasyMock
1346    * documentation.
1347    *
1348    * @param value
1349    * the given value.
1350    * @param delta
1351    * the given delta.
1352    * @return <code>0</code>.
1353    */
 
1354  3 toggle public static float eq(float value, float delta) {
1355  3 reportMatcher(new EqualsWithDelta(value, delta));
1356  3 return 0;
1357    }
1358   
1359    /**
1360    * Expects an Object that is the same as the given value. For details, see
1361    * the EasyMock documentation.
1362    *
1363    * @param <T>
1364    * the type of the object, it is passed through to prevent casts.
1365    * @param value
1366    * the given value.
1367    * @return <code>null</code>.
1368    */
 
1369  2 toggle public static <T> T same(T value) {
1370  2 reportMatcher(new Same(value));
1371  2 return null;
1372    }
1373   
1374    /**
1375    * Expects a comparable argument equals to the given value according to their
1376    * compareTo method. For details, see the EasMock documentation.
1377    *
1378    * @param value
1379    * the given value.
1380    * @return <code>null</code>.
1381    */
 
1382  1 toggle public static <T extends Comparable<T>> T cmpEq(Comparable<T> value) {
1383  1 reportMatcher(new CompareEqual<T>(value));
1384  1 return null;
1385    }
1386   
1387    /**
1388    * Expects an argument that will be compared using the provided comparator.
1389    * The following comparison will take place:
1390    * <p>
1391    * <code>comparator.compare(actual, expected) operator 0</code>
1392    * </p>
1393    * For details, see the EasyMock documentation.
1394    *
1395    * @param value the given value.
1396    * @param comparator Comparator used to compare the actual with expected value.
1397    * @param operator The comparison operator.
1398    * @return <code>null</code>
1399    */
 
1400  7 toggle public static <T> T cmp(T value, Comparator<? super T> comparator, LogicalOperator operator) {
1401  7 reportMatcher(new Compare<T>(value, comparator, operator));
1402  7 return null;
1403    }
1404   
1405   
1406    /**
1407    * Expects a byte that is equal to the given value.
1408    *
1409    * @param value
1410    * the given value.
1411    * @return <code>0</code>.
1412    */
1413   
1414   
1415    /**
1416    * Expect any object but captures it for later use.
1417    *
1418    * @param <T> Type of the captured object
1419    * @param captured Where the parameter is captured
1420    * @return <code>null</code>
1421    */
 
1422  2 toggle public static <T> T capture(Capture<T> captured) {
1423  2 reportMatcher(new Captures<T>(captured));
1424  2 return null;
1425    }
1426   
1427    /**
1428    * Expect any int but captures it for later use.
1429    *
1430    * @param captured Where the parameter is captured
1431    * @return <code>0</code>
1432    */
 
1433  3 toggle public static int capture(Capture<Integer> captured) {
1434  3 reportMatcher(new Captures<Integer>(captured));
1435  3 return 0;
1436    }
1437   
1438    /**
1439    * Expect any long but captures it for later use.
1440    *
1441    * @param captured Where the parameter is captured
1442    * @return <code>0</code>
1443    */
 
1444  1 toggle public static long capture(Capture<Long> captured) {
1445  1 reportMatcher(new Captures<Long>(captured));
1446  1 return 0;
1447    }
1448   
1449    /**
1450    * Expect any float but captures it for later use.
1451    *
1452    * @param captured Where the parameter is captured
1453    * @return <code>0</code>
1454    */
 
1455  1 toggle public static float capture(Capture<Float> captured) {
1456  1 reportMatcher(new Captures<Float>(captured));
1457  1 return 0;
1458    }
1459   
1460    /**
1461    * Expect any double but captures it for later use.
1462    *
1463    * @param captured Where the parameter is captured
1464    * @return <code>0</code>
1465    */
 
1466  1 toggle public static double capture(Capture<Double> captured) {
1467  1 reportMatcher(new Captures<Double>(captured));
1468  1 return 0;
1469    }
1470   
1471    /**
1472    * Expect any byte but captures it for later use.
1473    *
1474    * @param captured Where the parameter is captured
1475    * @return <code>0</code>
1476    */
 
1477  1 toggle public static byte capture(Capture<Byte> captured) {
1478  1 reportMatcher(new Captures<Byte>(captured));
1479  1 return 0;
1480    }
1481   
1482    /**
1483    * Expect any char but captures it for later use.
1484    *
1485    * @param captured Where the parameter is captured
1486    * @return <code>0</code>
1487    */
 
1488  1 toggle public static char capture(Capture<Character> captured) {
1489  1 reportMatcher(new Captures<Character>(captured));
1490  1 return 0;
1491    }
1492   
1493    /**
1494    * Switches the given mock objects (more exactly: the controls of the mock
1495    * objects) to replay mode. For details, see the EasyMock documentation.
1496    *
1497    * @param mocks
1498    * the mock objects.
1499    */
 
1500  85 toggle public static void replay(Object... mocks) {
1501  85 for (Object mock : mocks) {
1502  85 getControl(mock).replay();
1503    }
1504    }
1505   
1506    /**
1507    * Resets the given mock objects (more exactly: the controls of the mock
1508    * objects). For details, see the EasyMock documentation.
1509    *
1510    * @param mocks
1511    * the mock objects.
1512    */
 
1513  3 toggle public static void reset(Object... mocks) {
1514  3 for (Object mock : mocks) {
1515  3 getControl(mock).reset();
1516    }
1517    }
1518   
1519    /**
1520    * Resets the given mock objects (more exactly: the controls of the mock
1521    * objects) and turn them to a mock with nice behavior. For details, see
1522    * the EasyMock documentation.
1523    *
1524    * @param mocks
1525    * the mock objects
1526    */
 
1527  1 toggle public static void resetToNice(Object... mocks) {
1528  1 for (Object mock : mocks) {
1529  1 getControl(mock).resetToNice();
1530    }
1531    }
1532   
1533    /**
1534    * Resets the given mock objects (more exactly: the controls of the mock
1535    * objects) and turn them to a mock with default behavior. For details, see
1536    * the EasyMock documentation.
1537    *
1538    * @param mocks
1539    * the mock objects
1540    */
 
1541  1 toggle public static void resetToDefault(Object... mocks) {
1542  1 for (Object mock : mocks) {
1543  1 getControl(mock).resetToDefault();
1544    }
1545    }
1546   
1547    /**
1548    * Resets the given mock objects (more exactly: the controls of the mock
1549    * objects) and turn them to a mock with strict behavior. For details, see
1550    * the EasyMock documentation.
1551    *
1552    * @param mocks
1553    * the mock objects
1554    */
 
1555  1 toggle public static void resetToStrict(Object... mocks) {
1556  1 for (Object mock : mocks) {
1557  1 getControl(mock).resetToStrict();
1558    }
1559    }
1560   
1561    /**
1562    * Verifies the given mock objects (more exactly: the controls of the mock
1563    * objects).
1564    *
1565    * @param mocks
1566    * the mock objects.
1567    */
 
1568  65 toggle public static void verify(Object... mocks) {
1569  65 for (Object mock : mocks) {
1570  65 getControl(mock).verify();
1571    }
1572    }
1573   
1574    /**
1575    * Switches order checking of the given mock object (more exactly: the
1576    * control of the mock object) the on and off. For details, see the EasyMock
1577    * documentation.
1578    *
1579    * @param mock
1580    * the mock object.
1581    * @param state
1582    * <code>true</code> switches order checking on,
1583    * <code>false</code> switches it off.
1584    */
 
1585  3 toggle public static void checkOrder(Object mock, boolean state) {
1586  3 getControl(mock).checkOrder(state);
1587    }
1588   
1589    /**
1590    * Reports an argument matcher. This method is needed to define own argument
1591    * matchers. For details, see the EasyMock documentation.
1592    *
1593    * @param matcher
1594    */
 
1595  173 toggle public static void reportMatcher(IArgumentMatcher matcher) {
1596  173 LastControl.reportMatcher(matcher);
1597    }
1598   
 
1599  160 toggle private static MocksControl getControl(Object mock) {
1600  160 return ((ObjectMethodsFilter) Proxy
1601    .getInvocationHandler(mock)).getDelegate().getControl();
1602    }
1603   
1604    /**
1605    * Returns the arguments of the current mock method call, if inside an
1606    * <code>IAnswer</code> callback - be careful here, reordering parameters of
1607    * method changes the semantics of your tests.
1608    *
1609    * @return the arguments of the current mock method call.
1610    * @throws IllegalStateException
1611    * if called outside of <code>IAnswer</code> callbacks.
1612    */
 
1613  11 toggle public static Object[] getCurrentArguments() {
1614  11 Object[] result = LastControl.getCurrentArguments();
1615  11 if (result == null) {
1616  1 throw new IllegalStateException(
1617    "current arguments are only available when executing callback methods");
1618    }
1619  10 return result;
1620    }
1621   
1622    /**
1623    * Makes the mock thread safe. The mock will be usable in a multithreaded
1624    * environment.
1625    *
1626    * @param mock the mock to make thread safe
1627    * @param threadSafe If the mock should be thread safe or not
1628    */
 
1629  1 toggle public static void makeThreadSafe(Object mock, boolean threadSafe) {
1630  1 getControl(mock).makeThreadSafe(threadSafe);
1631    }
1632    }