KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > matcher > InvokedRecorderTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.core.matcher;
4
5 import junit.framework.TestCase;
6 import org.jmock.core.Invocation;
7 import org.jmock.core.matcher.InvokedRecorder;
8 import org.jmock.expectation.AssertMo;
9 import test.jmock.core.testsupport.MethodFactory;
10
11
12 public class InvokedRecorderTest extends TestCase
13 {
14     private Invocation emptyInvocation;
15     InvokedRecorder recorder;
16
17     public void setUp() {
18         MethodFactory methodFactory = new MethodFactory();
19
20         emptyInvocation = new Invocation("INVOKED-OBJECT",
21                                          methodFactory.newMethod("example", MethodFactory.NO_ARGUMENTS, Void JavaDoc.class, MethodFactory.NO_EXCEPTIONS),
22                                          new Object JavaDoc[0]);
23
24         recorder = new InvokedRecorder();
25     }
26
27     public void testAlwaysMatches() {
28         assertTrue("should match before invocation",
29                    recorder.matches(emptyInvocation));
30
31         recorder.invoked(emptyInvocation);
32
33         assertTrue("should still match after invocation",
34                    recorder.matches(emptyInvocation));
35     }
36
37     public void testAlwaysVerifies() {
38         recorder.verify();
39         recorder.invoked(emptyInvocation);
40         recorder.verify();
41     }
42
43     public void testReportsIfHasBeenInvoked() {
44         assertFalse("should not have been invoked", recorder.hasBeenInvoked());
45         recorder.invoked(emptyInvocation);
46         assertTrue("should have been invoked", recorder.hasBeenInvoked());
47     }
48
49     public void testCanExplicitlyVerifyThatItHasBeenInvoked() {
50         AssertMo.assertFails("verifyHasBeenInvoked should fail", new Runnable JavaDoc()
51         {
52             public void run() {
53                 recorder.verifyHasBeenInvoked();
54             }
55         });
56         recorder.invoked(emptyInvocation);
57         recorder.verifyHasBeenInvoked();
58     }
59
60     public void testDoesNotWriteDescription() {
61         assertEquals("should not be any description",
62                      "", (recorder.describeTo(new StringBuffer JavaDoc())).toString());
63     }
64 }
65
Popular Tags