KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > MockControl


1 /*
2  * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock;
6
7 import java.lang.reflect.InvocationHandler JavaDoc;
8 import java.lang.reflect.Method JavaDoc;
9
10 import junit.framework.AssertionFailedError;
11
12 import org.easymock.internal.AlwaysMatcher;
13 import org.easymock.internal.ArrayMatcher;
14 import org.easymock.internal.AssertionFailedErrorWrapper;
15 import org.easymock.internal.EqualsMatcher;
16 import org.easymock.internal.IBehavior;
17 import org.easymock.internal.IBehaviorFactory;
18 import org.easymock.internal.IMockControlState;
19 import org.easymock.internal.IProxyFactory;
20 import org.easymock.internal.JavaProxyFactory;
21 import org.easymock.internal.NiceBehavior;
22 import org.easymock.internal.ObjectMethodsFilter;
23 import org.easymock.internal.OrderedBehavior;
24 import org.easymock.internal.Range;
25 import org.easymock.internal.RecordState;
26 import org.easymock.internal.ReplayState;
27 import org.easymock.internal.RuntimeExceptionWrapper;
28 import org.easymock.internal.ThrowableWrapper;
29 import org.easymock.internal.UnorderedBehavior;
30
31 /**
32  * A <code>MockControl</code> object controls the behavior of its associated
33  * mock object. For more information, see the EasyMock documentation.
34  */

35 public class MockControl<T> {
36     private IMockControlState state;
37
38     private T mock;
39
40     private IBehavior behavior;
41
42     private IBehaviorFactory behaviorFactory;
43
44     /**
45      * internal constant with <code>protected</code> visibility to allow
46      * access for extensions.
47      */

48     protected static final IBehaviorFactory NICE_BEHAVIOR_FACTORY = new IBehaviorFactory() {
49         public IBehavior createBehavior() {
50             return new NiceBehavior();
51         }
52     };
53
54     /**
55      * internal constant with <code>protected</code> visibility to allow
56      * access for extensions.
57      */

58     protected static final IBehaviorFactory ORDERED_BEHAVIOR_FACTORY = new IBehaviorFactory() {
59         public IBehavior createBehavior() {
60             return new OrderedBehavior();
61         }
62     };
63
64     /**
65      * internal constant with <code>protected</code> visibility to allow
66      * access for extensions.
67      */

68     protected static final IBehaviorFactory UNORDERED_BEHAVIOR_FACTORY = new IBehaviorFactory() {
69         public IBehavior createBehavior() {
70             return new UnorderedBehavior();
71         }
72     };
73
74     /**
75      * Creates a mock control object for the specified interface. The
76      * <code>MockControl</code> and its associated mock object will not check
77      * the order of expected method calls. An unexpected method call on the mock
78      * object will lead to an <code>AssertionFailedError</code>.
79      *
80      * @param toMock
81      * the class of the interface to mock.
82      * @return the mock control.
83      */

84     public static <T> MockControl<T> createControl(Class JavaDoc<T> toMock) {
85         return new MockControl<T>(toMock, new JavaProxyFactory<T>(),
86                 UNORDERED_BEHAVIOR_FACTORY);
87     }
88
89     /**
90      * Creates a mock control object for the specified interface. The
91      * <code>MockControl</code> and its associated mock object will check the
92      * order of expected method calls. An unexpected method call on the mock
93      * object will lead to an <code>AssertionFailedError</code>.
94      *
95      * @param toMock
96      * the class of the interface to mock.
97      * @return the mock control.
98      */

99     public static <T> MockControl<T> createStrictControl(Class JavaDoc<T> toMock) {
100         return new MockControl<T>(toMock, new JavaProxyFactory<T>(),
101                 ORDERED_BEHAVIOR_FACTORY);
102     }
103
104     /**
105      * Creates a mock control object for the specified interface. The
106      * <code>MockControl</code> and its associated mock object will not check
107      * the order of expected method calls. An unexpected method call on the mock
108      * object will return an empty value (0, null, false).
109      *
110      * @param toMock
111      * the class of the interface to mock.
112      * @return the mock control.
113      */

114     public static <T> MockControl<T> createNiceControl(Class JavaDoc<T> toMock) {
115         return new MockControl<T>(toMock, new JavaProxyFactory<T>(),
116                 NICE_BEHAVIOR_FACTORY);
117     }
118
119     /**
120      * Creates a new mock control object using the provided proxy and behavior
121      * factory - this is an internal constructor with <code>protected</code>
122      * visibility to allow access for extensions.
123      *
124      * @param toMock
125      * the class of the interface to mock.
126      * @param proxyFactory
127      * the proxy factory.
128      * @param behaviorFactory
129      * the behavior factory.
130      */

131     protected MockControl(Class JavaDoc<T> toMock, IProxyFactory<T> proxyFactory,
132             IBehaviorFactory behaviorFactory) {
133         mock = proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
134                 createDelegator()));
135         this.behaviorFactory = behaviorFactory;
136         reset();
137     }
138
139     private InvocationHandler JavaDoc createDelegator() {
140         return new InvocationHandler JavaDoc() {
141             public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args)
142                     throws Throwable JavaDoc {
143                 try {
144                     return state.invoke(proxy, method, args);
145                 } catch (RuntimeExceptionWrapper e) {
146                     throw e.getRuntimeException().fillInStackTrace();
147                 } catch (AssertionFailedErrorWrapper e) {
148                     throw e.getAssertionFailedError().fillInStackTrace();
149                 } catch (ThrowableWrapper t) {
150                     throw t.getThrowable().fillInStackTrace();
151                 }
152             }
153         };
154     }
155
156     /**
157      * Returns the mock object.
158      *
159      * @return the mock object of this control
160      */

161     public T getMock() {
162         return mock;
163     }
164
165     /**
166      * Resets the mock control and the mock object to the state directly after
167      * creation.
168      */

169     public final void reset() {
170         behavior = behaviorFactory.createBehavior();
171         state = new RecordState(behavior);
172     }
173
174     /**
175      * Switches the mock object from record state to replay state. For more
176      * information, see the EasyMock documentation.
177      *
178      * @throws IllegalStateException
179      * if the mock object already is in replay state.
180      */

181     public void replay() {
182         try {
183             state.replay();
184             state = new ReplayState(behavior);
185         } catch (RuntimeExceptionWrapper e) {
186             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
187         }
188     }
189
190     /**
191      * Verifies that all expectations have been met. For more information, see
192      * the EasyMock documentation.
193      *
194      * @throws IllegalStateException
195      * if the mock object is in record state.
196      * @throws AssertionFailedError
197      * if any expectation has not been met.
198      */

199     public void verify() {
200         try {
201             state.verify();
202         } catch (RuntimeExceptionWrapper e) {
203             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
204         } catch (AssertionFailedErrorWrapper e) {
205             throw (AssertionFailedError) e.getAssertionFailedError()
206                     .fillInStackTrace();
207         }
208     }
209
210     /**
211      * Records that the mock object will expect the last method call once, and
212      * will react by returning silently.
213      *
214      * @exception IllegalStateException
215      * if the mock object is in replay state, if no method was
216      * called on the mock object before, or if the last method
217      * called on the mock was no void method.
218      */

219     public void setVoidCallable() {
220         try {
221             state.setVoidCallable(MockControl.ONE);
222         } catch (RuntimeExceptionWrapper e) {
223             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
224         }
225     }
226
227     /**
228      * Records that the mock object will expect the last method call once, and
229      * will react by throwing the provided Throwable.
230      *
231      * @param throwable
232      * the Throwable to throw.
233      * @exception IllegalStateException
234      * if the mock object is in replay state or if no method was
235      * called on the mock object before.
236      * @exception IllegalArgumentException
237      * if the last method called on the mock cannot throw the
238      * provided Throwable.
239      * @exception NullPointerException
240      * if throwable is null.
241      */

242     public void setThrowable(Throwable JavaDoc throwable) {
243         try {
244             state.setThrowable(throwable, MockControl.ONE);
245         } catch (RuntimeExceptionWrapper e) {
246             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
247         }
248     }
249
250     /**
251      * Records that the mock object will expect the last method call once, and
252      * will react by returning the provided return value.
253      *
254      * @param value
255      * the return value.
256      * @throws IllegalStateException
257      * if the mock object is in replay state, if no method was
258      * called on the mock object before. or if the last method
259      * called on the mock does not return <code>boolean</code>.
260      */

261     public void setReturnValue(boolean value) {
262         try {
263             state.setReturnValue(value, MockControl.ONE);
264         } catch (RuntimeExceptionWrapper e) {
265             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
266         }
267     }
268
269     /**
270      * Records that the mock object will expect the last method call once, and
271      * will react by returning the provided return value.
272      *
273      * @param value
274      * the return value.
275      * @throws IllegalStateException
276      * if the mock object is in replay state, if no method was
277      * called on the mock object before. or if the last method
278      * called on the mock does not return
279      * <code>byte, short, char, int, or long</code>.
280      */

281     public void setReturnValue(long value) {
282         try {
283             state.setReturnValue(value, MockControl.ONE);
284         } catch (RuntimeExceptionWrapper e) {
285             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
286         }
287     }
288
289     /**
290      * Records that the mock object will expect the last method call once, and
291      * will react by returning the provided return value.
292      *
293      * @param value
294      * the return value.
295      * @throws IllegalStateException
296      * if the mock object is in replay state, if no method was
297      * called on the mock object before. or if the last method
298      * called on the mock does not return <code>float</code>.
299      */

300     public void setReturnValue(float value) {
301         try {
302             state.setReturnValue(value, MockControl.ONE);
303         } catch (RuntimeExceptionWrapper e) {
304             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
305         }
306     }
307
308     /**
309      * Records that the mock object will expect the last method call once, and
310      * will react by returning the provided return value.
311      *
312      * @param value
313      * the return value.
314      * @throws IllegalStateException
315      * if the mock object is in replay state, if no method was
316      * called on the mock object before. or if the last method
317      * called on the mock does not return <code>double</code>.
318      */

319     public void setReturnValue(double value) {
320         try {
321             state.setReturnValue(value, MockControl.ONE);
322         } catch (RuntimeExceptionWrapper e) {
323             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
324         }
325     }
326
327     /**
328      * Records that the mock object will expect the last method call once, and
329      * will react by returning the provided return value.
330      *
331      * @param value
332      * the return value.
333      * @throws IllegalStateException
334      * if the mock object is in replay state, if no method was
335      * called on the mock object before. or if the last method
336      * called on the mock does not return an object.
337      * @throws IllegalArgumentException
338      * if the provided return value is not compatible to the return
339      * value of the last method called on the mock object.
340      */

341     public void setReturnValue(Object JavaDoc value) {
342         try {
343             state.setReturnValue(value, MockControl.ONE);
344         } catch (RuntimeExceptionWrapper e) {
345             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
346         }
347     }
348
349     /**
350      * Records that the mock object will expect the last method call a fixed
351      * number of times, and will react by returning silently.
352      *
353      * @param times
354      * the number of times that the call is expected.
355      * @exception IllegalStateException
356      * if the mock object is in replay state, if no method was
357      * called on the mock object before, or if the last method
358      * called on the mock was no void method.
359      */

360     public void setVoidCallable(int times) {
361         try {
362             state.setVoidCallable(new Range(times));
363         } catch (RuntimeExceptionWrapper e) {
364             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
365         }
366     }
367
368     /**
369      * Records that the mock object will expect the last method call a fixed
370      * number of times, and will react by throwing the provided Throwable.
371      *
372      * @param throwable
373      * the Throwable to throw.
374      * @param times
375      * the number of times that the call is expected.
376      * @exception IllegalStateException
377      * if the mock object is in replay state or if no method was
378      * called on the mock object before.
379      * @exception IllegalArgumentException
380      * if the last method called on the mock cannot throw the
381      * provided Throwable.
382      * @exception NullPointerException
383      * if throwable is null.
384      */

385     public void setThrowable(Throwable JavaDoc throwable, int times) {
386         try {
387             state.setThrowable(throwable, new Range(times));
388         } catch (RuntimeExceptionWrapper e) {
389             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
390         }
391     }
392
393     /**
394      * Records that the mock object will expect the last method call a fixed
395      * number of times, and will react by returning the provided return value.
396      *
397      * @param value
398      * the return value.
399      * @param times
400      * the number of times that the call is expected.
401      * @throws IllegalStateException
402      * if the mock object is in replay state, if no method was
403      * called on the mock object before. or if the last method
404      * called on the mock does not return <code>boolean</code>.
405      */

406     public void setReturnValue(boolean value, int times) {
407         try {
408             state.setReturnValue(value, new Range(times));
409         } catch (RuntimeExceptionWrapper e) {
410             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
411         }
412     }
413
414     /**
415      * Records that the mock object will expect the last method call a fixed
416      * number of times, and will react by returning the provided return value.
417      *
418      * @param value
419      * the return value.
420      * @param times
421      * the number of times that the call is expected.
422      * @throws IllegalStateException
423      * if the mock object is in replay state, if no method was
424      * called on the mock object before. or if the last method
425      * called on the mock does not return <code>double</code>.
426      */

427     public void setReturnValue(double value, int times) {
428         try {
429             state.setReturnValue(value, new Range(times));
430         } catch (RuntimeExceptionWrapper e) {
431             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
432         }
433     }
434
435     /**
436      * Records that the mock object will expect the last method call a fixed
437      * number of times, and will react by returning the provided return value.
438      *
439      * @param value
440      * the return value.
441      * @param times
442      * the number of times that the call is expected.
443      * @throws IllegalStateException
444      * if the mock object is in replay state, if no method was
445      * called on the mock object before. or if the last method
446      * called on the mock does not return <code>float</code>.
447      */

448     public void setReturnValue(float value, int times) {
449         try {
450             state.setReturnValue(value, new Range(times));
451         } catch (RuntimeExceptionWrapper e) {
452             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
453         }
454     }
455
456     /**
457      * Records that the mock object will expect the last method call a fixed
458      * number of times, and will react by returning the provided return value.
459      *
460      * @param value
461      * the return value.
462      * @param times
463      * the number of times that the call is expected.
464      * @throws IllegalStateException
465      * if the mock object is in replay state, if no method was
466      * called on the mock object before. or if the last method
467      * called on the mock does not return
468      * <code>byte, short, char, int, or long</code>.
469      */

470     public void setReturnValue(long value, int times) {
471         try {
472             state.setReturnValue(value, new Range(times));
473         } catch (RuntimeExceptionWrapper e) {
474             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
475         }
476     }
477
478     /**
479      * Records that the mock object will expect the last method call a fixed
480      * number of times, and will react by returning the provided return value.
481      *
482      * @param value
483      * the return value.
484      * @param times
485      * the number of times that the call is expected.
486      * @throws IllegalStateException
487      * if the mock object is in replay state, if no method was
488      * called on the mock object before. or if the last method
489      * called on the mock does not return an object.
490      * @throws IllegalArgumentException
491      * if the provided return value is not compatible to the return
492      * value of the last method called on the mock object.
493      */

494     public void setReturnValue(Object JavaDoc value, int times) {
495         try {
496             state.setReturnValue(value, new Range(times));
497         } catch (RuntimeExceptionWrapper e) {
498             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
499         }
500     }
501
502     /**
503      * Records that the mock object will expect the last method call the number
504      * of times specified by the range argument, and will react by returning
505      * silently. Available range arguments are:
506      * <ul>
507      * <li>{@link MockControl#ZERO_OR_MORE}</li>
508      * <li>{@link MockControl#ONE}</li>
509      * <li>{@link MockControl#ONE_OR_MORE}</li>
510      * </ul>
511      *
512      * @param range
513      * the number of times that the call is expected.
514      * @exception IllegalStateException
515      * if the mock object is in replay state, if no method was
516      * called on the mock object before, or if the last method
517      * called on the mock was no void method.
518      */

519     public void setVoidCallable(Range range) {
520         try {
521             state.setVoidCallable(range);
522         } catch (RuntimeExceptionWrapper e) {
523             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
524         }
525     }
526
527     /**
528      * Records that the mock object will expect the last method call the number
529      * of times specified by the range argument, and will react by throwing the
530      * provided Throwable. Available range arguments are:
531      * <ul>
532      * <li>{@link MockControl#ZERO_OR_MORE}</li>
533      * <li>{@link MockControl#ONE}</li>
534      * <li>{@link MockControl#ONE_OR_MORE}</li>
535      * </ul>
536      *
537      * @param throwable
538      * the Throwable to throw.
539      * @param range
540      * the number of times that the call is expected.
541      * @exception IllegalStateException
542      * if the mock object is in replay state or if no method was
543      * called on the mock object before.
544      * @exception IllegalArgumentException
545      * if the last method called on the mock cannot throw the
546      * provided Throwable.
547      * @exception NullPointerException
548      * if throwable is null.
549      */

550     public void setThrowable(Throwable JavaDoc throwable, Range range) {
551         try {
552             state.setThrowable(throwable, range);
553         } catch (RuntimeExceptionWrapper e) {
554             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
555         }
556     }
557
558     /**
559      * Records that the mock object will expect the last method call the number
560      * of times specified by the range argument, and will react by returning the
561      * provided return value. Available range arguments are:
562      * <ul>
563      * <li>{@link MockControl#ZERO_OR_MORE}</li>
564      * <li>{@link MockControl#ONE}</li>
565      * <li>{@link MockControl#ONE_OR_MORE}</li>
566      * </ul>
567      *
568      * @param value
569      * the return value.
570      * @param range
571      * the number of times that the call is expected.
572      * @throws IllegalStateException
573      * if the mock object is in replay state, if no method was
574      * called on the mock object before. or if the last method
575      * called on the mock does not return <code>boolean</code>.
576      */

577     public void setReturnValue(boolean value, Range range) {
578         try {
579             state.setReturnValue(value, range);
580         } catch (RuntimeExceptionWrapper e) {
581             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
582         }
583     }
584
585     /**
586      * Records that the mock object will expect the last method call the number
587      * of times specified by the range argument, and will react by returning the
588      * provided return value. Available range arguments are:
589      * <ul>
590      * <li>{@link MockControl#ZERO_OR_MORE}</li>
591      * <li>{@link MockControl#ONE}</li>
592      * <li>{@link MockControl#ONE_OR_MORE}</li>
593      * </ul>
594      *
595      * @param value
596      * the return value.
597      * @param range
598      * the number of times that the call is expected.
599      * @throws IllegalStateException
600      * if the mock object is in replay state, if no method was
601      * called on the mock object before. or if the last method
602      * called on the mock does not return <code>double</code>.
603      */

604     public void setReturnValue(double value, Range range) {
605         try {
606             state.setReturnValue(value, range);
607         } catch (RuntimeExceptionWrapper e) {
608             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
609         }
610     }
611
612     /**
613      * Records that the mock object will expect the last method call the number
614      * of times specified by the range argument, and will react by returning the
615      * provided return value. Available range arguments are:
616      * <ul>
617      * <li>{@link MockControl#ZERO_OR_MORE}</li>
618      * <li>{@link MockControl#ONE}</li>
619      * <li>{@link MockControl#ONE_OR_MORE}</li>
620      * </ul>
621      *
622      * @param value
623      * the return value.
624      * @param range
625      * the number of times that the call is expected.
626      * @throws IllegalStateException
627      * if the mock object is in replay state, if no method was
628      * called on the mock object before. or if the last method
629      * called on the mock does not return <code>float</code>.
630      */

631     public void setReturnValue(float value, Range range) {
632         try {
633             state.setReturnValue(value, range);
634         } catch (RuntimeExceptionWrapper e) {
635             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
636         }
637     }
638
639     /**
640      * Records that the mock object will expect the last method call the number
641      * of times specified by the range argument, and will react by returning the
642      * provided return value. Available range arguments are:
643      * <ul>
644      * <li>{@link MockControl#ZERO_OR_MORE}</li>
645      * <li>{@link MockControl#ONE}</li>
646      * <li>{@link MockControl#ONE_OR_MORE}</li>
647      * </ul>
648      *
649      * @param value
650      * the return value.
651      * @param range
652      * the number of times that the call is expected.
653      * @throws IllegalStateException
654      * if the mock object is in replay state, if no method was
655      * called on the mock object before. or if the last method
656      * called on the mock does not return
657      * <code>byte, short, char, int, or long</code>.
658      */

659     public void setReturnValue(long value, Range range) {
660         try {
661             state.setReturnValue(value, range);
662         } catch (RuntimeExceptionWrapper e) {
663             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
664         }
665     }
666
667     /**
668      * Records that the mock object will expect the last method call the number
669      * of times specified by the range argument, and will react by returning the
670      * provided return value. Available range arguments are:
671      * <ul>
672      * <li>{@link MockControl#ZERO_OR_MORE}</li>
673      * <li>{@link MockControl#ONE}</li>
674      * <li>{@link MockControl#ONE_OR_MORE}</li>
675      * </ul>
676      *
677      * @param value
678      * the return value.
679      * @param range
680      * the number of times that the call is expected.
681      * @throws IllegalStateException
682      * if the mock object is in replay state, if no method was
683      * called on the mock object before. or if the last method
684      * called on the mock does not return an object.
685      * @throws IllegalArgumentException
686      * if the provided return value is not compatible to the return
687      * value of the last method called on the mock object.
688      */

689     public void setReturnValue(Object JavaDoc value, Range range) {
690         try {
691             state.setReturnValue(value, range);
692         } catch (RuntimeExceptionWrapper e) {
693             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
694         }
695     }
696
697     /**
698      * Records that the mock object will by default allow the last method
699      * specified by a method call.
700      *
701      * @exception IllegalStateException
702      * if the mock object is in replay state, if no method was
703      * called on the mock object before, or if the last method
704      * called on the mock was no void method.
705      */

706     public void setDefaultVoidCallable() {
707         try {
708             state.setDefaultVoidCallable();
709         } catch (RuntimeExceptionWrapper e) {
710             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
711         }
712     }
713
714     /**
715      * Records that the mock object will by default allow the last method
716      * specified by a method call, and will react by throwing the provided
717      * Throwable.
718      *
719      * @param throwable
720      * throwable the throwable to be thrown
721      * @exception IllegalArgumentException
722      * if the last method called on the mock cannot throw the
723      * provided Throwable.
724      * @exception NullPointerException
725      * if throwable is null.
726      * @exception IllegalStateException
727      * if the mock object is in replay state, or if no method was
728      * called on the mock object before.
729      */

730     public void setDefaultThrowable(Throwable JavaDoc throwable) {
731         try {
732             state.setDefaultThrowable(throwable);
733         } catch (RuntimeExceptionWrapper e) {
734             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
735         }
736     }
737
738     /**
739      * Records that the mock object will by default allow the last method
740      * specified by a method call, and will react by returning the provided
741      * return value.
742      *
743      * @param value
744      * the return value.
745      * @throws IllegalStateException
746      * if the mock object is in replay state, if no method was
747      * called on the mock object before. or if the last method
748      * called on the mock does not return <code>boolean</code>.
749      */

750     public void setDefaultReturnValue(boolean value) {
751         try {
752             state.setDefaultReturnValue(value);
753         } catch (RuntimeExceptionWrapper e) {
754             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
755         }
756     }
757
758     /**
759      * Records that the mock object will by default allow the last method
760      * specified by a method call, and will react by returning the provided
761      * return value.
762      *
763      * @param value
764      * the return value.
765      * @throws IllegalStateException
766      * if the mock object is in replay state, if no method was
767      * called on the mock object before. or if the last method
768      * called on the mock does not return
769      * <code>byte, short, char, int, or long</code>.
770      */

771     public void setDefaultReturnValue(long value) {
772         try {
773             state.setDefaultReturnValue(value);
774         } catch (RuntimeExceptionWrapper e) {
775             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
776         }
777     }
778
779     /**
780      * Records that the mock object will by default allow the last method
781      * specified by a method call, and will react by returning the provided
782      * return value.
783      *
784      * @param value
785      * the return value.
786      * @throws IllegalStateException
787      * if the mock object is in replay state, if no method was
788      * called on the mock object before. or if the last method
789      * called on the mock does not return <code>float</code>.
790      */

791     public void setDefaultReturnValue(float value) {
792         try {
793             state.setDefaultReturnValue(value);
794         } catch (RuntimeExceptionWrapper e) {
795             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
796         }
797     }
798
799     /**
800      * Records that the mock object will by default allow the last method
801      * specified by a method call, and will react by returning the provided
802      * return value.
803      *
804      * @param value
805      * the return value.
806      * @throws IllegalStateException
807      * if the mock object is in replay state, if no method was
808      * called on the mock object before. or if the last method
809      * called on the mock does not return <code>double</code>.
810      */

811     public void setDefaultReturnValue(double value) {
812         try {
813             state.setDefaultReturnValue(value);
814         } catch (RuntimeExceptionWrapper e) {
815             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
816         }
817     }
818
819     /**
820      * Records that the mock object will by default allow the last method
821      * specified by a method call, and will react by returning the provided
822      * return value.
823      *
824      * @param value
825      * the return value.
826      * @throws IllegalStateException
827      * if the mock object is in replay state, if no method was
828      * called on the mock object before. or if the last method
829      * called on the mock does not return an object.
830      * @throws IllegalArgumentException
831      * if the provided return value is not compatible to the return
832      * value of the last method called on the mock object.
833      */

834     public void setDefaultReturnValue(Object JavaDoc value) {
835         try {
836             state.setDefaultReturnValue(value);
837         } catch (RuntimeExceptionWrapper e) {
838             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
839         }
840     }
841
842     /**
843      * Sets the ArgumentsMatcher for the last method called on the mock object.
844      * The matcher must be set before any behavior for the method is defined.
845      *
846      * @throws IllegalStateException
847      * if called in replay state, or if no method was called on the
848      * mock object before.
849      */

850     public void setMatcher(ArgumentsMatcher matcher) {
851         try {
852             state.setMatcher(matcher);
853         } catch (RuntimeExceptionWrapper e) {
854             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
855         }
856     }
857
858     /**
859      * Records that the mock object will expect the last method call between
860      * <code>minCount</code> and <code>maxCount</code> times, and will react
861      * by returning silently.
862      *
863      * @param minCount
864      * the minimum number of times that the call is expected.
865      * @param maxCount
866      * the maximum number of times that the call is expected.
867      * @exception IllegalStateException
868      * if the mock object is in replay state, if no method was
869      * called on the mock object before, or if the last method
870      * called on the mock was no void method.
871      */

872     public void setVoidCallable(int minCount, int maxCount) {
873         try {
874             state.setVoidCallable(new Range(minCount, maxCount));
875         } catch (RuntimeExceptionWrapper e) {
876             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
877         }
878     }
879
880     /**
881      * Records that the mock object will expect the last method call between
882      * <code>minCount</code> and <code>maxCount</code> times, and will react
883      * by throwing the provided Throwable.
884      *
885      * @param throwable
886      * the Throwable to throw.
887      * @param minCount
888      * the minimum number of times that the call is expected.
889      * @param maxCount
890      * the maximum number of times that the call is expected.
891      * @exception IllegalStateException
892      * if the mock object is in replay state or if no method was
893      * called on the mock object before.
894      * @exception IllegalArgumentException
895      * if the last method called on the mock cannot throw the
896      * provided Throwable.
897      * @exception NullPointerException
898      * if throwable is null.
899      */

900     public void setThrowable(Throwable JavaDoc throwable, int minCount, int maxCount) {
901         try {
902             state.setThrowable(throwable, new Range(minCount, maxCount));
903         } catch (RuntimeExceptionWrapper e) {
904             throw (RuntimeException JavaDoc) e.getRuntimeException().fillInStackTrace();
905         }
906     }
907
908     /**
909      * Records that the mock object will expect the last method call between
910      * <code>minCount</code> and <code>maxCount</code> times, and will react
911     &nbs