KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestTearDownException


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.sample.servlet.unit;
21
22 import org.apache.cactus.ServletTestCase;
23
24 import junit.framework.AssertionFailedError;
25
26 /**
27  * Test that <code>tearDown()</code> is called even when an exception
28  * occurs during the test.
29  *
30  * @version $Id: TestTearDownException.java,v 1.4 2004/02/29 16:36:44 vmassol Exp $
31  */

32 public class TestTearDownException extends ServletTestCase
33 {
34     /**
35      * Intercepts running test cases to check for normal exceptions.
36      */

37     public void runBare()
38     {
39         try
40         {
41             super.runBare();
42         }
43         catch (Throwable JavaDoc e)
44         {
45             assertEquals("testTearDown() worked", e.getMessage());
46         }
47     }
48
49     //-------------------------------------------------------------------------
50

51     /**
52      * Verify that the <code>tearDown()</code> is always called even when there
53      * is an exception raised during the test.
54      *
55      * @exception Exception on test failure
56      */

57     public void testTearDown() throws Exception JavaDoc
58     {
59         // Provoke an exception
60
fail("provoked error");
61     }
62
63     /**
64      * Verify that the <code>tearDown()</code> is always called even when there
65      * is an exception raised during the test.
66      */

67     public void tearDown()
68     {
69         throw new AssertionFailedError("testTearDown() worked");
70     }
71 }
72
Popular Tags