KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > TestNoNameTestCase


1 /*
2  * ========================================================================
3  *
4  * Copyright 2004 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;
21
22 import junit.framework.TestCase;
23 import org.apache.cactus.internal.AbstractCactusTestCase;
24 import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
25 import org.apache.cactus.internal.configuration.BaseConfiguration;
26 import org.apache.cactus.internal.configuration.DefaultServletConfiguration;
27 import org.apache.cactus.internal.util.TestCaseImplementError;
28 import org.apache.cactus.spi.client.connector.ProtocolHandler;
29
30 /**
31  * Unit tests of the <code>AbstractTestCase</code> class and its subclasses.
32  *
33  * @version $Id: TestNoNameTestCase.java,v 1.1 2004/05/22 11:34:46 vmassol Exp $
34  */

35 public class TestNoNameTestCase extends TestCase
36 {
37     /**
38      * Sample subclass of AbstractCactusTestCase of which the constructor
39      * and setName() don't set test name.
40      */

41     class NoNameTestCase extends AbstractCactusTestCase
42     {
43         /**
44          * default constructor
45          */

46         public NoNameTestCase()
47         {
48         }
49
50         /**
51          * Construct without super(theName)
52          * @param theName name of the test
53          */

54         public NoNameTestCase(String JavaDoc theName)
55         {
56         }
57
58         /**
59          * override junit.framework.TestCase#setName(String).
60          * @param theName name of the test
61          */

62         public void setName(String JavaDoc theName)
63         {
64         }
65
66         /**
67          * dummy implementation
68          * @return ProtocolHandler always return null
69          */

70         protected ProtocolHandler createProtocolHandler()
71         {
72             return new HttpProtocolHandler(new DefaultServletConfiguration());
73         }
74
75         /**
76          * dummy test entry
77          */

78         public void testNoName()
79         {
80         }
81     }
82
83     /**
84      * Sample subclass of ServletTestCase of which the constructor
85      * and setName() don't set test name.
86      */

87     class NoNameServletTestCase extends ServletTestCase
88     {
89         /**
90          * default constructor
91          */

92         public NoNameServletTestCase()
93         {
94         }
95
96         /**
97          * Construct without super(theName)
98          * @param theName name of the test
99          */

100         public NoNameServletTestCase(String JavaDoc theName)
101         {
102         }
103
104         /**
105          * override junit.framework.TestCase#setName(String).
106          * @param theName name of the test
107          */

108         public void setName(String JavaDoc theName)
109         {
110         }
111
112         /**
113          * dummy test entry
114          */

115         public void testNoName()
116         {
117         }
118     }
119
120     /**
121      * Sample subclass of JspTestCase of which the constructor
122      * and setName() don't set test name.
123      */

124     class NoNameJspTestCase extends JspTestCase
125     {
126         /**
127          * default constructor
128          */

129         public NoNameJspTestCase()
130         {
131         }
132
133         /**
134          * Construct without super(theName)
135          * @param theName name of the test
136          */

137         public NoNameJspTestCase(String JavaDoc theName)
138         {
139         }
140
141         /**
142          * override junit.framework.TestCase#setName(String).
143          * @param theName name of the test
144          */

145         public void setName(String JavaDoc theName)
146         {
147         }
148
149         /**
150          * dummy test entry
151          */

152         public void testNoName()
153         {
154         }
155     }
156
157     /**
158      * set cactus.contextURL as a system property.
159      */

160     public void setUp()
161     {
162         System.setProperty(BaseConfiguration.CACTUS_CONTEXT_URL_PROPERTY,
163             "http://localhost/dummy");
164     }
165
166     /**
167      * @param theName name of the test
168      */

169     public TestNoNameTestCase(String JavaDoc theName)
170     {
171         super(theName);
172     }
173
174     /**
175      * @param theTest the test to test
176      */

177     private void executeRunBare(TestCase theTest)
178     {
179         try
180         {
181             theTest.runBare();
182             fail("test should fail");
183         }
184         catch (Throwable JavaDoc t)
185         {
186             assertEquals(TestCaseImplementError.class.getName(),
187                 t.getClass().getName());
188             String JavaDoc message = t.getMessage();
189             assertNotNull("no message", message);
190             assertEquals("No test name found. "
191                 + "The test [" + theTest.getClass().getName()
192                 + "] is not properly implemented.", message);
193         }
194     }
195
196     /**
197      * Test subclass of AbstractCactusTestCase.
198      * Set the test name by constructor NoNameTestCase(String).
199      */

200     public void testNoNameTestCase()
201     {
202         TestCase test;
203         test = new NoNameTestCase("testNoName");
204         executeRunBare(test);
205     }
206
207     /**
208      * Test subclass of AbstractCactusTestCase.
209      * Set the test name by TestCase#setName(String).
210      */

211     public void testNoNameTestCaseWithSetName()
212     {
213         TestCase test;
214         test = new NoNameTestCase();
215         test.setName("testNoName");
216         executeRunBare(test);
217     }
218
219     /**
220      * Test subclass of ServletTestCase.
221      * Set the test name by constructor NoNameTestCase(String).
222      */

223     public void testNoNameServletTestCase()
224     {
225         TestCase test;
226         test = new NoNameServletTestCase("testNoName");
227         executeRunBare(test);
228     }
229
230     /**
231      * Test subclass of ServletTestCase.
232      * Set the test name by TestCase#setName(String).
233      */

234     public void testNoNameServletTestCaseWithSetName()
235     {
236         TestCase test;
237         test = new NoNameServletTestCase();
238         test.setName("testNoName");
239         executeRunBare(test);
240     }
241
242     /**
243      * Test subclass of JspTestCase.
244      * Set the test name by constructor NoNameTestCase(String).
245      */

246     public void testNoNameJspTestCase()
247     {
248         TestCase test;
249         test = new NoNameJspTestCase("testNoName");
250         executeRunBare(test);
251     }
252
253     /**
254      * Test subclass of JspTestCase.
255      * Set the test name by TestCase#setName(String).
256      */

257     public void testNoNameJspTestCaseWithSetName()
258     {
259         TestCase test;
260         test = new NoNameJspTestCase();
261         test.setName("testNoName");
262         executeRunBare(test);
263     }
264 }
265
Popular Tags