KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > VerifyingTestCase


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

3 package org.jmock.core;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8 import junit.framework.TestCase;
9 import org.jmock.util.Verifier;
10
11
12 /**
13  * A {@link junit.framework.TestCase} that verifies {@link org.jmock.core.Verifiable}
14  * fields and registered Verifiable objects after the test has run and before the fixture
15  * has been torn down.
16  */

17 public abstract class VerifyingTestCase extends TestCase
18 {
19     private List JavaDoc objectsThatRequireVerification = new ArrayList JavaDoc();
20
21     public VerifyingTestCase() {
22         super();
23     }
24
25     public VerifyingTestCase( String JavaDoc name ) {
26         super(name);
27     }
28
29     /* This is virtually a copy/paste of the same invokedMethod in the TestCase class to allow
30      * overriding of runTest in the normal manner.
31      *
32      * @see junit.framework.TestCase#runBare()
33      */

34     public void runBare() throws Throwable JavaDoc {
35         setUp();
36         try {
37             runTest();
38             verify();
39         }
40         finally {
41             tearDown();
42         }
43     }
44
45     public void registerToVerify( Verifiable verifiable ) {
46         objectsThatRequireVerification.add(verifiable);
47     }
48
49     public void unregisterToVerify( Verifiable verifiable ) {
50         objectsThatRequireVerification.remove(verifiable);
51     }
52
53     public void verify() {
54         for (Iterator JavaDoc iterator = objectsThatRequireVerification.iterator(); iterator.hasNext();) {
55             Verifiable verifiable = (Verifiable)iterator.next();
56             verifiable.verify();
57         }
58         Verifier.verifyObject(this);
59     }
60
61 }
62
63
Popular Tags