EasyMock 2.3

Clover coverage report - EasyMock 2.3
Coverage timestamp: mar. juil. 10 2007 02:46:04 CEST
FRAMES NO FRAMES

file stats: | LOC: | 1 492 |  | Methods: | 114
| NCLOC: | 464 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

EasyMock.java

100%

100%

100%

100%

1 |  | /*
2 |  | * Copyright (c) 2001-2007 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 | 14 | public static <T> T createStrictMock(Class<T> toMock) {
29 | 14 | 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 | 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 | 43 | public static <T> T createMock(Class<T> toMock) {
60 | 43 | 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 | 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 | 4 | public static <T> T createNiceMock(Class<T> toMock) {
93 | 4 | 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 | 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 | 49 | public static IMocksControl createStrictControl() {
120 | 49 | 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 | 398 | public static IMocksControl createControl() {
129 | 398 | 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 | 14 | public static IMocksControl createNiceControl() {
140 | 14 | 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 | 172 | @SuppressWarnings("unchecked")
156 |  | public static <T> IExpectationSetters<T> expect(T value) {
157 | 172 | return getControlForLastCall();
158 |  | }
159 |  |
160 |  | /**
161 |  | * Returns the expectation setter for the last expected invocation in the
162 |  | * current thread. This method is used for expected invocations on void
163 |  | * methods.
164 |  | *
165 |  | * @return the expectation setter.
166 |  | */
167 | 257 | @SuppressWarnings("unchecked")
168 |  | public static IExpectationSetters<Object> expectLastCall() {
169 | 257 | return getControlForLastCall();
170 |  | }
171 |  |
172 | 429 | private static IExpectationSetters getControlForLastCall() {
173 | 429 | MocksControl lastControl = LastControl.lastControl();
174 | 429 | if (lastControl == null) {
175 | 87 | throw new IllegalStateException("no last call on a mock available");
176 |  | }
177 | 342 | return lastControl;
178 |  | }
179 |  |
180 |  | /**
181 |  | * Expects any boolean argument. For details, see the EasyMock
182 |  | * documentation.
183 |  | *
184 |  | * @return <code>false</code>.
185 |  | */
186 | 1 | public static boolean anyBoolean() {
187 | 1 | reportMatcher(Any.ANY);
188 | 1 | return false;
189 |  | }
190 |  |
191 |  | /**
192 |  | * Expects any byte argument. For details, see the EasyMock documentation.
193 |  | *
194 |  | * @return <code>0</code>.
195 |  | */
196 | 1 | public static byte anyByte() {
197 | 1 | reportMatcher(Any.ANY);
198 | 1 | return 0;
199 |  | }
200 |  |
201 |  | /**
202 |  | * Expects any char argument. For details, see the EasyMock documentation.
203 |  | *
204 |  | * @return <code>0</code>.
205 |  | */
206 | 1 | public static char anyChar() {
207 | 1 | reportMatcher(Any.ANY);
208 | 1 | return 0;
209 |  | }
210 |  |
211 |  | /**
212 |  | * Expects any int argument. For details, see the EasyMock documentation.
213 |  | *
214 |  | * @return <code>0</code>.
215 |  | */
216 | 3 | public static int anyInt() {
217 | 3 | reportMatcher(Any.ANY);
218 | 3 | return 0;
219 |  | }
220 |  |
221 |  | /**
222 |  | * Expects any long argument. For details, see the EasyMock documentation.
223 |  | *
224 |  | * @return <code>0</code>.
225 |  | */
226 | 1 | public static long anyLong() {
227 | 1 | reportMatcher(Any.ANY);
228 | 1 | return 0;
229 |  | }
230 |  |
231 |  | /**
232 |  | * Expects any float argument. For details, see the EasyMock documentation.
233 |  | *
234 |  | * @return <code>0</code>.
235 |  | */
236 | 1 | public static float anyFloat() {
237 | 1 | reportMatcher(Any.ANY);
238 | 1 | return 0;
239 |  | }
240 |  |
241 |  | /**
242 |  | * Expects any double argument. For details, see the EasyMock documentation.
243 |  | *
244 |  | * @return <code>0</code>.
245 |  | */
246 | 1 | public static double anyDouble() {
247 | 1 | reportMatcher(Any.ANY);
248 | 1 | return 0;
249 |  | }
250 |  |
251 |  | /**
252 |  | * Expects any short argument. For details, see the EasyMock documentation.
253 |  | *
254 |  | * @return <code>0</code>.
255 |  | */
256 | 1 | public static short anyShort() {
257 | 1 | reportMatcher(Any.ANY);
258 | 1 | return 0;
259 |  | }
260 |  |
261 |  | /**
262 |  | * Expects any Object argument. For details, see the EasyMock documentation.
263 |  | *
264 |  | * @return <code>null</code>.
265 |  | */
266 | 2 | public static Object anyObject() {
267 | 2 | reportMatcher(Any.ANY);
268 | 2 | return null;
269 |  | }
270 |  |
271 |  | /**
272 |  | * Expects a comparable argument greater than or equal the given value. For details, see
273 |  | * the EasyMock documentation.
274 |  | *
275 |  | * @param value
276 |  | * the given value.
277 |  | * @return <code>null</code>.
278 |  | */
279 | 1 | public static <T extends Comparable<T>> T geq(Comparable<T> value) {
280 | 1 | reportMatcher(new GreaterOrEqual<T>(value));
281 | 1 | return null;
282 |  | }
283 |  |
284 |  | /**
285 |  | * Expects a byte argument greater than or equal to the given value. For
286 |  | * details, see the EasyMock documentation.
287 |  | *
288 |  | * @param value
289 |  | * the given value.
290 |  | * @return <code>0</code>.
291 |  | */
292 | 1 | public static byte geq(byte value) {
293 | 1 | reportMatcher(new GreaterOrEqual<Byte>(value));
294 | 1 | return 0;
295 |  | }
296 |  |
297 |  | /**
298 |  | * Expects a double argument greater than or equal to the given value. For
299 |  | * details, see the EasyMock documentation.
300 |  | *
301 |  | * @param value
302 |  | * the given value.
303 |  | * @return <code>0</code>.
304 |  | */
305 | 1 | public static double geq(double value) {
306 | 1 | reportMatcher(new GreaterOrEqual<Double>(value));
307 | 1 | return 0;
308 |  | }
309 |  |
310 |  | /**
311 |  | * Expects a float argument greater than or equal to the given value. For
312 |  | * details, see the EasyMock documentation.
313 |  | *
314 |  | * @param value
315 |  | * the given value.
316 |  | * @return <code>0</code>.
317 |  | */
318 | 1 | public static float geq(float value) {
319 | 1 | reportMatcher(new GreaterOrEqual<Float>(value));
320 | 1 | return 0;
321 |  | }
322 |  |
323 |  | /**
324 |  | * Expects an int argument greater than or equal to the given value. For
325 |  | * details, see the EasyMock documentation.
326 |  | *
327 |  | * @param value
328 |  | * the given value.
329 |  | * @return <code>0</code>.
330 |  | */
331 | 4 | public static int geq(int value) {
332 | 4 | reportMatcher(new GreaterOrEqual<Integer>(value));
333 | 4 | return 0;
334 |  | }
335 |  |
336 |  | /**
337 |  | * Expects a long argument greater than or equal to the given value. For
338 |  | * details, see the EasyMock documentation.
339 |  | *
340 |  | * @param value
341 |  | * the given value.
342 |  | * @return <code>0</code>.
343 |  | */
344 | 1 | public static long geq(long value) {
345 | 1 | reportMatcher(new GreaterOrEqual<Long>(value));
346 | 1 | return 0;
347 |  | }
348 |  |
349 |  | /**
350 |  | * Expects a short argument greater than or equal to the given value. For
351 |  | * details, see the EasyMock documentation.
352 |  | *
353 |  | * @param value
354 |  | * the given value.
355 |  | * @return <code>0</code>.
356 |  | */
357 | 1 | public static short geq(short value) {
358 | 1 | reportMatcher(new GreaterOrEqual<Short>(value));
359 | 1 | return 0;
360 |  | }
361 |  |
362 |  | /**
363 |  | * Expects a comparable argument less than or equal the given value. For details, see
364 |  | * the EasyMock documentation.
365 |  | *
366 |  | * @param value
367 |  | * the given value.
368 |  | * @return <code>null</code>.
369 |  | */
370 | 1 | public static <T extends Comparable<T>> T leq(Comparable<T> value) {
371 | 1 | reportMatcher(new LessOrEqual<T>(value));
372 | 1 | return null;
373 |  | }
374 |  |
375 |  | /**
376 |  | * Expects a byte argument less than or equal to the given value. For
377 |  | * details, see the EasyMock documentation.
378 |  | *
379 |  | * @param value
380 |  | * the given value.
381 |  | * @return <code>0</code>.
382 |  | */
383 | 1 | public static byte leq(byte value) {
384 | 1 | reportMatcher(new LessOrEqual<Byte>(value));
385 | 1 | return 0;
386 |  | }
387 |  |
388 |  | /**
389 |  | * Expects a double argument less than or equal to the given value. For
390 |  | * details, see the EasyMock documentation.
391 |  | *
392 |  | * @param value
393 |  | * the given value.
394 |  | * @return <code>0</code>.
395 |  | */
396 | 1 | public static double leq(double value) {
397 | 1 | reportMatcher(new LessOrEqual<Double>(value));
398 | 1 | return 0;
399 |  | }
400 |  |
401 |  | /**
402 |  | * Expects a float argument less than or equal to the given value. For
403 |  | * details, see the EasyMock documentation.
404 |  | *
405 |  | * @param value
406 |  | * the given value.
407 |  | * @return <code>0</code>.
408 |  | */
409 | 1 | public static float leq(float value) {
410 | 1 | reportMatcher(new LessOrEqual<Float>(value));
411 | 1 | return 0;
412 |  | }
413 |  |
414 |  | /**
415 |  | * Expects an int argument less than or equal to the given value. For
416 |  | * details, see the EasyMock documentation.
417 |  | *
418 |  | * @param value
419 |  | * the given value.
420 |  | * @return <code>0</code>.
421 |  | */
422 | 4 | public static int leq(int value) {
423 | 4 | reportMatcher(new LessOrEqual<Integer>(value));
424 | 4 | return 0;
425 |  | }
426 |  |
427 |  | /**
428 |  | * Expects a long argument less than or equal to the given value. For
429 |  | * details, see the EasyMock documentation.
430 |  | *
431 |  | * @param value
432 |  | * the given value.
433 |  | * @return <code>0</code>.
434 |  | */
435 | 1 | public static long leq(long value) {
436 | 1 | reportMatcher(new LessOrEqual<Long>(value));
437 | 1 | return 0;
438 |  | }
439 |  |
440 |  | /**
441 |  | * Expects a short argument less than or equal to the given value. For
442 |  | * details, see the EasyMock documentation.
443 |  | *
444 |  | * @param value
445 |  | * the given value.
446 |  | * @return <code>0</code>.
447 |  | */
448 | 1 | public static short leq(short value) {
449 | 1 | reportMatcher(new LessOrEqual<Short>(value));
450 | 1 | return 0;
451 |  | }
452 |  |
453 |  | /**
454 |  | * Expects a comparable argument greater than the given value. For details, see
455 |  | * the EasyMock documentation.
456 |  | *
457 |  | * @param value
458 |  | * the given value.
459 |  | * @return <code>null</code>.
460 |  | */
461 | 1 | public static <T extends Comparable<T>> T gt(Comparable<T> value) {
462 | 1 | reportMatcher(new GreaterThan<T>(value));
463 | 1 | return null;
464 |  | }
465 |  |
466 |  | /**
467 |  | * Expects a byte argument greater than the given value. For details, see
468 |  | * the EasyMock documentation.
469 |  | *
470 |  | * @param value
471 |  | * the given value.
472 |  | * @return <code>0</code>.
473 |  | */
474 | 1 | public static byte gt(byte value) {
475 | 1 | reportMatcher(new GreaterThan<Byte>(value));
476 | 1 | return 0;
477 |  | }
478 |  |
479 |  | /**
480 |  | * Expects a double argument greater than the given value. For details, see
481 |  | * the EasyMock documentation.
482 |  | *
483 |  | * @param value
484 |  | * the given value.
485 |  | * @return <code>0</code>.
486 |  | */
487 | 1 | public static double gt(double value) {
488 | 1 | reportMatcher(new GreaterThan<Double>(value));
489 | 1 | return 0;
490 |  | }
491 |  |
492 |  | /**
493 |  | * Expects a float argument greater than the given value. For details, see
494 |  | * the EasyMock documentation.
495 |  | *
496 |  | * @param value
497 |  | * the given value.
498 |  | * @return <code>0</code>.
499 |  | */
500 | 1 | public static float gt(float value) {
501 | 1 | reportMatcher(new GreaterThan<Float>(value));
502 | 1 | return 0;
503 |  | }
504 |  |
505 |  | /**
506 |  | * Expects an int argument greater than the given value. For details, see
507 |  | * the EasyMock documentation.
508 |  | *
509 |  | * @param value
510 |  | * the given value.
511 |  | * @return <code>0</code>.
512 |  | */
513 | 3 | public static int gt(int value) {
514 | 3 | reportMatcher(new GreaterThan<Integer>(value));
515 | 3 | return 0;
516 |  | }
517 |  |
518 |  | /**
519 |  | * Expects a long argument greater than the given value. For details, see
520 |  | * the EasyMock documentation.
521 |  | *
522 |  | * @param value
523 |  | * the given value.
524 |  | * @return <code>0</code>.
525 |  | */
526 | 1 | public static long gt(long value) {
527 | 1 | reportMatcher(new GreaterThan<Long>(value));
528 | 1 | return 0;
529 |  | }
530 |  |
531 |  | /**
532 |  | * Expects a short argument greater than the given value. For details, see
533 |  | * the EasyMock documentation.
534 |  | *
535 |  | * @param value
536 |  | * the given value.
537 |  | * @return <code>0</code>.
538 |  | */
539 | 1 | public static short gt(short value) {
540 | 1 | reportMatcher(new GreaterThan<Short>(value));
541 | 1 | return 0;
542 |  | }
543 |  |
544 |  | /**
545 |  | * Expects a comparable argument less than the given value. For details, see
546 |  | * the EasyMock documentation.
547 |  | *
548 |  | * @param value
549 |  | * the given value.
550 |  | * @return <code>null</code>.
551 |  | */
552 | 1 | public static <T extends Comparable<T>> T lt(Comparable<T> value) {
553 | 1 | reportMatcher(new LessThan<T>(value));
554 | 1 | return null;
555 |  | }
556 |  |
557 |  | /**
558 |  | * Expects a byte argument less than the given value. For details, see the
559 |  | * EasyMock documentation.
560 |  | *
561 |  | * @param value
562 |  | * the given value.
563 |  | * @return <code>0</code>.
564 |  | */
565 | 1 | public static byte lt(byte value) {
566 | 1 | reportMatcher(new LessThan<Byte>(value));
567 | 1 | return 0;
568 |  | }
569 |  |
570 |  | /**
571 |  | * Expects a double argument less than the given value. For details, see the
572 |  | * EasyMock documentation.
573 |  | *
574 |  | * @param value
575 |  | * the given value.
576 |  | * @return <code>0</code>.
577 |  | */
578 | 1 | public static double lt(double value) {
579 | 1 | reportMatcher(new LessThan<Double>(value));
580 | 1 | return 0;
581 |  | }
582 |  |
583 |  | /**
584 |  | * Expects a float argument less than the given value. For details, see the
585 |  | * EasyMock documentation.
586 |  | *
587 |  | * @param value
588 |  | * the given value.
589 |  | * @return <code>0</code>.
590 |  | */
591 | 1 | public static float lt(float value) {
592 | 1 | reportMatcher(new LessThan<Float>(value));
593 | 1 | return 0;
594 |  | }
595 |  |
596 |  | /**
597 |  | * Expects an int argument less than the given value. For details, see the
598 |  | * EasyMock documentation.
599 |  | *
600 |  | * @param value
601 |  | * the given value.
602 |  | * @return <code>0</code>.
603 |  | */
604 | 4 | public static int lt(int value) {
605 | 4 | reportMatcher(new LessThan<Integer>(value));
606 | 4 | return 0;
607 |  | }
608 |  |
609 |  | /**
610 |  | * Expects a long argument less than the given value. For details, see the
611 |  | * EasyMock documentation.
612 |  | *
613 |  | * @param value
614 |  | * the given value.
615 |  | * @return <code>0</code>.
616 |  | */
617 | 1 | public static long lt(long value) {
618 | 1 | reportMatcher(new LessThan<Long>(value));
619 | 1 | return 0;
620 |  | }
621 |  |
622 |  | /**
623 |  | * Expects a short argument less than the given value. For details, see the
624 |  | * EasyMock documentation.
625 |  | *
626 |  | * @param value
627 |  | * the given value.
628 |  | * @return <code>0</code>.
629 |  | */
630 | 1 | public static short lt(short value) {
631 | 1 | reportMatcher(new LessThan<Short>(value));
632 | 1 | return 0;
633 |  | }
634 |  |
635 |  | /**
636 |  | * Expects an object implementing the given class. For details, see the
637 |  | * EasyMock documentation.
638 |  | *
639 |  | * @param <T>
640 |  | * the accepted type.
641 |  | * @param clazz
642 |  | * the class of the accepted type.
643 |  | * @return <code>null</code>.
644 |  | */
645 | 3 | public static <T> T isA(Class<T> clazz) {
646 | 3 | reportMatcher(new InstanceOf(clazz));
647 | 3 | return null;
648 |  | }
649 |  |
650 |  | /**
651 |  | * Expects a string that contains the given substring. For details, see the
652 |  | * EasyMock documentation.
653 |  | *
654 |  | * @param substring
655 |  | * the substring.
656 |  | * @return <code>null</code>.
657 |  | */
658 | 6 | public static String contains(String substring) {
659 | 6 | reportMatcher(new Contains(substring));
660 | 6 | return null;
661 |  | }
662 |  |
663 |  | /**
664 |  | * Expects a boolean that matches both given expectations.
665 |  | *
666 |  | * @param first
667 |  | * placeholder for the first expectation.
668 |  | * @param second
669 |  | * placeholder for the second expectation.
670 |  | * @return <code>false</code>.
671 |  | */
672 | 1 | public static boolean and(boolean first, boolean second) {
673 | 1 | LastControl.reportAnd(2);
674 | 1 | return false;
675 |  | }
676 |  |
677 |  | /**
678 |  | * Expects a byte that matches both given expectations.
679 |  | *
680 |  | * @param first
681 |  | * placeholder for the first expectation.
682 |  | * @param second
683 |  | * placeholder for the second expectation.
684 |  | * @return <code>0</code>.
685 |  | */
686 | 1 | public static byte and(byte first, byte second) {
687 | 1 | LastControl.reportAnd(2);
688 | 1 | return 0;
689 |  | }
690 |  |
691 |  | /**
692 |  | * Expects a char that matches both given expectations.
693 |  | *
694 |  | * @param first
695 |  | * placeholder for the first expectation.
696 |  | * @param second
697 |  | * placeholder for the second expectation.
698 |  | * @return <code>0</code>.
699 |  | */
700 | 1 | public static char and(char first, char second) {
701 | 1 | LastControl.reportAnd(2);
702 | 1 | return 0;
703 |  | }
704 |  |
705 |  | /**
706 |  | * Expects a double that matches both given expectations.
707 |  | *
708 |  | * @param first
709 |  | * placeholder for the first expectation.
710 |  | * @param second
711 |  | * placeholder for the second expectation.
712 |  | * @return <code>0</code>.
713 |  | */
714 | 1 | public static double and(double first, double second) {
715 | 1 | LastControl.reportAnd(2);
716 | 1 | return 0;
717 |  | }
718 |  |
719 |  | /**
720 |  | * Expects a float that matches both given expectations.
721 |  | *
722 |  | * @param first
723 |  | * placeholder for the first expectation.
724 |  | * @param second
725 |  | * placeholder for the second expectation.
726 |  | * @return <code>0</code>.
727 |  | */
728 | 1 | public static float and(float first, float second) {
729 | 1 | LastControl.reportAnd(2);
730 | 1 | return 0;
731 |  | }
732 |  |
733 |  | /**
734 |  | * Expects an int that matches both given expectations.
735 |  | *
736 |  | * @param first
737 |  | * placeholder for the first expectation.
738 |  | * @param second
739 |  | * placeholder for the second expectation.
740 |  | * @return <code>0</code>.
741 |  | */
742 | 2 | public static int and(int first, int second) {
743 | 2 | LastControl.reportAnd(2);
744 | 2 | return 0;
745 |  | }
746 |  |
747 |  | /**
748 |  | * Expects a long that matches both given expectations.
749 |  | *
750 |  | * @param first
751 |  | * placeholder for the first expectation.
752 |  | * @param second
753 |  | * placeholder for the second expectation.
754 |  | * @return <code>0</code>.
755 |  | */
756 | 1 | public static long and(long first, long second) {
757 | 1 | LastControl.reportAnd(2);
758 | 1 | return 0;
759 |  | }
760 |  |
761 |  | /**
762 |  | * Expects a short that matches both given expectations.
763 |  | *
764 |  | * @param first
765 |  | * placeholder for the first expectation.
766 |  | * @param second
767 |  | * placeholder for the second expectation.
768 |  | * @return <code>0</code>.
769 |  | */
770 | 1 | public static short and(short first, short second) {
771 | 1 | LastControl.reportAnd(2);
772 | 1 | return 0;
773 |  | }
774 |  |
775 |  | /**
776 |  | * Expects an Object that matches both given expectations.
777 |  | *
778 |  | * @param <T>
779 |  | * the type of the object, it is passed through to prevent casts.
780 |  | * @param first
781 |  | * placeholder for the first expectation.
782 |  | * @param second
783 |  | * placeholder for the second expectation.
784 |  | * @return <code>null</code>.
785 |  | */
786 | 2 | public static <T> T and(T first, T second) {
787 | 2 | LastControl.reportAnd(2);
788 | 2 | return null;
789 |  | }
790 |  |
791 |  | /**
792 |  | * Expects a boolean that matches one of the given expectations.
793 |  | *
794 |  | * @param first
795 |  | * placeholder for the first expectation.
796 |  | * @param second
797 |  | * placeholder for the second expectation.
798 |  | * @return <code>false</code>.
799 |  | */
800 | 1 | public static boolean or(boolean first, boolean second) {
801 | 1 | LastControl.reportOr(2);
802 | 1 | return false;
803 |  | }
804 |  |
805 |  | /**
806 |  | * Expects a byte that matches one of the given expectations.
807 |  | *
808 |  | * @param first
809 |  | * placeholder for the first expectation.
810 |  | * @param second
811 |  | * placeholder for the second expectation.
812 |  | * @return <code>0</code>.
813 |  | */
814 | 1 | public static byte or(byte first, byte second) {
815 | 1 | LastControl.reportOr(2);
816 | 1 | return 0;
817 |  | }
818 |  |
819 |  | /**
820 |  | * Expects a char that matches one of the given expectations.
821 |  | *
822 |  | * @param first
823 |  | * placeholder for the first expectation.
824 |  | * @param second
825 |  | * placeholder for the second expectation.
826 |  | * @return <code>0</code>.
827 |  | */
828 | 1 | public static char or(char first, char second) {
829 | 1 | LastControl.reportOr(2);
830 | 1 | return 0;
831 |  | }
832 |  |
833 |  | /**
834 |  | * Expects a double that matches one of the given expectations.
835 |  | *
836 |  | * @param first
837 |  | * placeholder for the first expectation.
838 |  | * @param second
839 |  | * placeholder for the second expectation.
840 |  | * @return <code>0</code>.
841 |  | */
842 | 1 | public static double or(double first, double second) {
843 | 1 | LastControl.reportOr(2);
844 | 1 | return 0;
845 |  | }
846 |  |
847 |  | /**
848 |  | * Expects a float that matches one of the given expectations.
849 |  | *
850 |  | * @param first
851 |  | * placeholder for the first expectation.
852 |  | * @param second
853 |  | * placeholder for the second expectation.
854 |  | * @return <code>0</code>.
855 |  | */
856 | 1 | public static float or(float first, float second) {
857 | 1 | LastControl.reportOr(2);
858 | 1 | return 0;
859 |  | }
860 |  |
861 |  | /**
862 |  | * Expects an int that matches one of the given expectations.
863 |  | *
864 |  | * @param first
865 |  | * placeholder for the first expectation.
866 |  | * @param second
867 |  | * placeholder for the second expectation.
868 |  | * @return <code>0</code>.
869 |  | */
870 | 2 | public static int or(int first, int second) {
871 | 2 | LastControl.reportOr(2);
872 | 2 | return first;
873 |  | }
874 |  |
875 |  | /**
876 |  | * Expects a long that matches one of the given expectations.
877 |  | *
878 |  | * @param first
879 |  | * placeholder for the first expectation.
880 |  | * @param second
881 |  | * placeholder for the second expectation.
882 |  | * @return <code>0</code>.
883 |  | */
884 | 1 | public static long or(long first, long second) {
885 | 1 | LastControl.reportOr(2);
886 | 1 | return 0;
887 |  | }
888 |  |
889 |  | /**
890 |  | * Expects a short that matches one of the given expectations.
891 |  | *
892 |  | * @param first
893 |  | * placeholder for the first expectation.
894 |  | * @param second
895 |  | * placeholder for the second expectation.
896 |  | * @return <code>0</code>.
897 |  | */
898 | 1 | public static short or(short first, short second) {
899 | 1 | LastControl.reportOr(2);
900 | 1 | return 0;
901 |  | }
902 |  |
903 |  | /**
904 |  | * Expects an Object that matches one of the given expectations.
905 |  | *
906 |  | * @param <T>
907 |  | * the type of the object, it is passed through to prevent casts.
908 |  | * @param first
909 |  | * placeholder for the first expectation.
910 |  | * @param second
911 |  | * placeholder for the second expectation.
912 |  | * @return <code>null</code>.
913 |  | */
914 | 3 | public static <T> T or(T first, T second) {
915 | 3 | LastControl.reportOr(2);
916 | 2 | return null;
917 |  | }
918 |  |
919 |  | /**
920 |  | * Expects a boolean that does not match the given expectation.
921 |  | *
922 |  | * @param first
923 |  | * placeholder for the expectation.
924 |  | * @return <code>false</code>.
925 |  | */
926 | 1 | public static boolean not(boolean first) {
927 | 1 | LastControl.reportNot();
928 | 1 | return false;
929 |  | }
930 |  |
931 |  | /**
932 |  | * Expects a byte that does not match the given expectation.
933 |  | *
934 |  | * @param first
935 |  | * placeholder for the expectation.
936 |  | * @return <code>0</code>.
937 |  | */
938 | 1 | public static byte not(byte first) {
939 | 1 | LastControl.reportNot();
940 | 1 | return 0;
941 |  | }
942 |  |
943 |  | /**
944 |  | * Expects a char that does not match the given expectation.
945 |  | *
946 |  | * @param first
947 |  | * placeholder for the expectation.
948 |  | * @return <code>0</code>.
949 |  | */
950 | 1 | public static char not(char first) {
951 | 1 | LastControl.reportNot();
952 | 1 | return 0;
953 |  | }
954 |  |
955 |  | /**
956 |  | * Expects a double that does not match the given expectation.
957 |  | *
958 |  | * @param first
959 |  | * placeholder for the expectation.
960 |  | * @return <code>0</code>.
961 |  | */
962 | 1 | public static double not(double first) {
963 | 1 | LastControl.reportNot();
964 | 1 | return 0;
965 |  | }
966 |  |
967 |  | /**
968 |  | * Expects a float that does not match the given expectation.
969 |  | *
970 |  | * @param first
971 |  | * placeholder for the expectation.
972 |  | * @return <code>0</code>.
973 |  | */
974 | 1 | public static float not(float first) {
975 | 1 | LastControl.reportNot();
976 | 1 | return first;
977 |  | }
978 |  |
979 |  | /**
980 |  | * Expects an int that does not match the given expectation.
981 |  | *
982 |  | * @param first
983 |  | * placeholder for the expectation.
984 |  | * @return <code>0</code>.
985 |  | */
986 | 1 | public static int not(int first) {
987 | 1 | LastControl.reportNot();
988 | 1 | return 0;
989 |  | }
990 |  |
991 |  | /**
992 |  | * Expects a long that does not match the given expectation.
993 |  | *
994 |  | * @param first
995 |  | * placeholder for the expectation.
996 |  | * @return <code>0</code>.
997 |  | */
998 | 1 | public static long not(long first) {
999 | 1 | LastControl.reportNot();
1000 | 1 | return 0;
1001 |  | }
1002 |  |
1003 |  | /**
1004 |  | * Expects a short that does not match the given expectation.
1005 |  | *
1006 |  | * @param first
1007 |  | * placeholder for the expectation.
1008 |  | * @return <code>0</code>.
1009 |  | */
1010 | 1 | public static short not(short first) {
1011 | 1 | LastControl.reportNot();
1012 | 1 | return 0;
1013 |  | }
1014 |  |
1015 |  | /**
1016 |  | * Expects an Object that does not match the given expectation.
1017 |  | *
1018 |  | * @param <T>
1019 |  | * the type of the object, it is passed through to prevent casts.
1020 |  | * @param first
1021 |  | * placeholder for the expectation.
1022 |  | * @return <code>null</code>.
1023 |  | */
1024 | 6 | public static <T> T not(T first) {
1025 | 6 | LastControl.reportNot();
1026 | 5 | return null;
1027 |  | }
1028 |  |
1029 |  | /**
1030 |  | * Expects a boolean that is equal to the given value.
1031 |  | *
1032 |  | * @param value
1033 |  | * the given value.
1034 |  | * @return <code>0</code>.
1035 |  | */
1036 | 5 | public static boolean eq(boolean value) {
1037 | 5 | reportMatcher(new Equals(value));
1038 | 5 | return false;
1039 |  | }
1040 |  |
1041 |  | /**
1042 |  | * Expects a byte that is equal to the given value.
1043 |  | *
1044 |  | * @param value
1045 |  | * the given value.
1046 |  | * @return <code>0</code>.
1047 |  | */
1048 | 5 | public static byte eq(byte value) {
1049 | 5 | reportMatcher(new Equals(value));
1050 | 5 | return 0;
1051 |  | }
1052 |  |
1053 |  | /**
1054 |  | * Expects a char that is equal to the given value.
1055 |  | *
1056 |  | * @param value
1057 |  | * the given value.
1058 |  | * @return <code>0</code>.
1059 |  | */
1060 | 5 | public static char eq(char value) {
1061 | 5 | reportMatcher(new Equals(value));
1062 | 5 | return 0;
1063 |  | }
1064 |  |
1065 |  | /**
1066 |  | * Expects a double that is equal to the given value.
1067 |  | *
1068 |  | * @param value
1069 |  | * the given value.
1070 |  | * @return <code>0</code>.
1071 |  | */
1072 | 5 | public static double eq(double value) {
1073 | 5 | reportMatcher(new Equals(value));
1074 | 5 | return 0;
1075 |  | }
1076 |  |
1077 |  | /**
1078 |  | * Expects a float that is equal to the given value.
1079 |  | *
1080 |  | * @param value
1081 |  | * the given value.
1082 |  | * @return <code>0</code>.
1083 |  | */
1084 | 5 | public static float eq(float value) {
1085 | 5 | reportMatcher(new Equals(value));
1086 | 5 | return 0;
1087 |  | }
1088 |  |
1089 |  | /**
1090 |  | * Expects an int that is equal to the given value.
1091 |  | *
1092 |  | * @param value
1093 |  | * the given value.
1094 |  | * @return <code>0</code>.
1095 |  | */
1096 | 11 | public static int eq(int value) {
1097 | 11 | reportMatcher(new Equals(value));
1098 | 11 | return 0;
1099 |  | }
1100 |  |
1101 |  | /**
1102 |  | * Expects a long that is equal to the given value.
1103 |  | *
1104 |  | * @param value
1105 |  | * the given value.
1106 |  | * @return <code>0</code>.
1107 |  | */
1108 | 5 | public static long eq(long value) {
1109 | 5 | reportMatcher(new Equals(value));
1110 | 5 | return 0;
1111 |  | }
1112 |  |
1113 |  | /**
1114 |  | * Expects a short that is equal to the given value.
1115 |  | *
1116 |  | * @param value
1117 |  | * the given value.
1118 |  | * @return <code>0</code>.
1119 |  | */
1120 | 5 | public static short eq(short value) {
1121 | 5 | reportMatcher(new Equals(value));
1122 | 5 | return 0;
1123 |  | }
1124 |  |
1125 |  | /**
1126 |  | * Expects an Object that is equal to the given value.
1127 |  | *
1128 |  | * @param value
1129 |  | * the given value.
1130 |  | * @return <code>null</code>.
1131 |  | */
1132 | 12 | public static <T> T eq(T value) {
1133 | 12 | reportMatcher(new Equals(value));
1134 | 12 | return null;
1135 |  | }
1136 |  |
1137 |  | /**
1138 |  | * Expects a boolean array that is equal to the given array, i.e. it has to
1139 |  | * have the same length, and each element has to be equal.
1140 |  | *
1141 |  | * @param value
1142 |  | * the given arry.
1143 |  | * @return <code>null</code>.
1144 |  | */
1145 | 1 | public static boolean[] aryEq(boolean[] value) {
1146 | 1 | reportMatcher(new ArrayEquals(value));
1147 | 1 | return null;
1148 |  | }
1149 |  |
1150 |  | /**
1151 |  | * Expects a byte array that is equal to the given array, i.e. it has to
1152 |  | * have the same length, and each element has to be equal.
1153 |  | *
1154 |  | * @param value
1155 |  | * the given arry.
1156 |  | * @return <code>null</code>.
1157 |  | */
1158 | 1 | public static byte[] aryEq(byte[] value) {
1159 | 1 | reportMatcher(new ArrayEquals(value));
1160 | 1 | return null;
1161 |  | }
1162 |  |
1163 |  | /**
1164 |  | * Expects a char array that is equal to the given array, i.e. it has to
1165 |  | * have the same length, and each element has to be equal.
1166 |  | *
1167 |  | * @param value
1168 |  | * the given arry.
1169 |  | * @return <code>null</code>.
1170 |  | */
1171 | 1 | public static char[] aryEq(char[] value) {
1172 | 1 | reportMatcher(new ArrayEquals(value));
1173 | 1 | return null;
1174 |  | }
1175 |  |
1176 |  | /**
1177 |  | * Expects a double array that is equal to the given array, i.e. it has to
1178 |  | * have the same length, and each element has to be equal.
1179 |  | *
1180 |  | * @param value
1181 |  | * the given arry.
1182 |  | * @return <code>null</code>.
1183 |  | */
1184 | 1 | public static double[] aryEq(double[] value) {
1185 | 1 | reportMatcher(new ArrayEquals(value));
1186 | 1 | return null;
1187 |  | }
1188 |  |
1189 |  | /**
1190 |  | * Expects a float array that is equal to the given array, i.e. it has to
1191 |  | * have the same length, and each element has to be equal.
1192 |  | *
1193 |  | * @param value
1194 |  | * the given arry.
1195 |  | * @return <code>null</code>.
1196 |  | */
1197 | 1 | public static float[] aryEq(float[] value) {
1198 | 1 | reportMatcher(new ArrayEquals(value));
1199 | 1 | return null;
1200 |  | }
1201 |  |
1202 |  | /**
1203 |  | * Expects an int array that is equal to the given array, i.e. it has to
1204 |  | * have the same length, and each element has to be equal.
1205 |  | *
1206 |  | * @param value
1207 |  | * the given arry.
1208 |  | * @return <code>null</code>.
1209 |  | */
1210 | 1 | public static int[] aryEq(int[] value) {
1211 | 1 | reportMatcher(new ArrayEquals(value));
1212 | 1 | return null;
1213 |  | }
1214 |  |
1215 |  | /**
1216 |  | * Expects a long array that is equal to the given array, i.e. it has to
1217 |  | * have the same length, and each element has to be equal.
1218 |  | *
1219 |  | * @param value
1220 |  | * the given arry.
1221 |  | * @return <code>null</code>.
1222 |  | */
1223 | 1 | public static long[] aryEq(long[] value) {
1224 | 1 | reportMatcher(new ArrayEquals(value));
1225 | 1 | return null;
1226 |  | }
1227 |  |
1228 |  | /**
1229 |  | * Expects a short array that is equal to the given array, i.e. it has to
1230 |  | * have the same length, and each element has to be equal.
1231 |  | *
1232 |  | * @param value
1233 |  | * the given arry.
1234 |  | * @return <code>null</code>.
1235 |  | */
1236 | 1 | public static short[] aryEq(short[] value) {
1237 | 1 | reportMatcher(new ArrayEquals(value));
1238 | 1 | return null;
1239 |  | }
1240 |  |
1241 |  | /**
1242 |  | * Expects an Object array that is equal to the given array, i.e. it has to
1243 |  | * have the same type, length, and each element has to be equal.
1244 |  | *
1245 |  | * @param <T>
1246 |  | * the type of the array, it is passed through to prevent casts.
1247 |  | * @param value
1248 |  | * the given arry.
1249 |  | * @return <code>null</code>.
1250 |  | */
1251 | 2 | public static <T> T[] aryEq(T[] value) {
1252 | 2 | reportMatcher(new ArrayEquals(value));
1253 | 2 | return null;
1254 |  | }
1255 |  |
1256 |  | /**
1257 |  | * Expects null.
1258 |  | *
1259 |  | * @return <code>null</code>.
1260 |  | */
1261 | 3 | public static Object isNull() {
1262 | 3 | reportMatcher(Null.NULL);
1263 | 3 | return null;
1264 |  | }
1265 |  |
1266 |  | /**
1267 |  | * Expects not null.
1268 |  | *
1269 |  | * @return <code>null</code>.
1270 |  | */
1271 | 5 | public static Object notNull() {
1272 | 5 | reportMatcher(NotNull.NOT_NULL);
1273 | 5 | return null;
1274 |  | }
1275 |  |
1276 |  | /**
1277 |  | * Expects a string that contains a substring that matches the given regular
1278 |  | * expression. For details, see the EasyMock documentation.
1279 |  | *
1280 |  | * @param regex
1281 |  | * the regular expression.
1282 |  | * @return <code>null</code>.
1283 |  | */
1284 | 2 | public static String find(String regex) {
1285 | 2 | reportMatcher(new Find(regex));
1286 | 2 | return null;
1287 |  | }
1288 |  |
1289 |  | /**
1290 |  | * Expects a string that matches the given regular expression. For details,
1291 |  | * see the EasyMock documentation.
1292 |  | *
1293 |  | * @param regex
1294 |  | * the regular expression.
1295 |  | * @return <code>null</code>.
1296 |  | */
1297 | 2 | public static String matches(String regex) {
1298 | 2 | reportMatcher(new Matches(regex));
1299 | 2 | return null;
1300 |  | }
1301 |  |
1302 |  | /**
1303 |  | * Expects a string that starts with the given prefix. For details, see the
1304 |  | * EasyMock documentation.
1305 |  | *
1306 |  | * @param prefix
1307 |  | * the prefix.
1308 |  | * @return <code>null</code>.
1309 |  | */
1310 | 2 | public static String startsWith(String prefix) {
1311 | 2 | reportMatcher(new StartsWith(prefix));
1312 | 2 | return null;
1313 |  | }
1314 |  |
1315 |  | /**
1316 |  | * Expects a string that ends with the given suffix. For details, see the
1317 |  | * EasyMock documentation.
1318 |  | *
1319 |  | * @param suffix
1320 |  | * the suffix.
1321 |  | * @return <code>null</code>.
1322 |  | */
1323 | 2 | public static String endsWith(String suffix) {
1324 | 2 | reportMatcher(new EndsWith(suffix));
1325 | 2 | return null;
1326 |  | }
1327 |  |
1328 |  | /**
1329 |  | * Expects a double that has an absolute difference to the given value that
1330 |  | * is less than the given delta. For details, see the EasyMock
1331 |  | * documentation.
1332 |  | *
1333 |  | * @param value
1334 |  | * the given value.
1335 |  | * @param delta
1336 |  | * the given delta.
1337 |  | * @return <code>0</code>.
1338 |  | */
1339 | 2 | public static double eq(double value, double delta) {
1340 | 2 | reportMatcher(new EqualsWithDelta(value, delta));
1341 | 2 | return 0;
1342 |  | }
1343 |  |
1344 |  | /**
1345 |  | * Expects a float that has an absolute difference to the given value that
1346 |  | * is less than the given delta. For details, see the EasyMock
1347 |  | * documentation.
1348 |  | *
1349 |  | * @param value
1350 |  | * the given value.
1351 |  | * @param delta
1352 |  | * the given delta.
1353 |  | * @return <code>0</code>.
1354 |  | */
1355 | 3 | public static float eq(float value, float delta) {
1356 | 3 | reportMatcher(new EqualsWithDelta(value, delta));
1357 | 3 | return 0;
1358 |  | }
1359 |  |
1360 |  | /**
1361 |  | * Expects an Object that is the same as the given value. For details, see
1362 |  | * the EasyMock documentation.
1363 |  | *
1364 |  | * @param <T>
1365 |  | * the type of the object, it is passed through to prevent casts.
1366 |  | * @param value
1367 |  | * the given value.
1368 |  | * @return <code>null</code>.
1369 |  | */
1370 | 2 | public static <T> T same(T value) {
1371 | 2 | reportMatcher(new Same(value));
1372 | 2 | return null;
1373 |  | }
1374 |  |
1375 |  | /**
1376 |  | * Switches the given mock objects (more exactly: the controls of the mock
1377 |  | * objects) to replay mode. For details, see the EasyMock documentation.
1378 |  | *
1379 |  | * @param mocks
1380 |  | * the mock objects.
1381 |  | */
1382 | 63 | public static void replay(Object... mocks) {
1383 | 63 | for (Object mock : mocks) {
1384 | 63 | getControl(mock).replay();
1385 |  | }
1386 |  | }
1387 |  |
1388 |  | /**
1389 |  | * Resets the given mock objects (more exactly: the controls of the mock
1390 |  | * objects). For details, see the EasyMock documentation.
1391 |  | *
1392 |  | * @param mocks
1393 |  | * the mock objects.
1394 |  | */
1395 | 3 | public static void reset(Object... mocks) {
1396 | 3 | for (Object mock : mocks) {
1397 | 3 | getControl(mock).reset();
1398 |  | }
1399 |  | }
1400 |  |
1401 |  | /**
1402 |  | * Verifies the given mock objects (more exactly: the controls of the mock
1403 |  | * objects).
1404 |  | *
1405 |  | * @param mocks
1406 |  | * the mock objects.
1407 |  | */
1408 | 48 | public static void verify(Object... mocks) {
1409 | 48 | for (Object mock : mocks) {
1410 | 48 | getControl(mock).verify();
1411 |  | }
1412 |  | }
1413 |  |
1414 |  | /**
1415 |  | * Switches order checking of the given mock object (more exactly: the
1416 |  | * control of the mock object) the on and off. For details, see the EasyMock
1417 |  | * documentation.
1418 |  | *
1419 | &