KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestHttpStatus


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java,v 1.2.2.2 2004/05/02 11:19:58 olegk Exp $
3  * $Revision: 1.2.2.2 $
4  * $Date: 2004/05/02 11:19:58 $
5  * ====================================================================
6  *
7  * Copyright 1999-2004 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ====================================================================
21  *
22  * This software consists of voluntary contributions made by many
23  * individuals on behalf of the Apache Software Foundation. For more
24  * information on the Apache Software Foundation, please see
25  * <http://www.apache.org/>.
26  *
27  * [Additional notices, if required by prior licensing conditions]
28  *
29  */

30
31 package org.apache.commons.httpclient;
32
33 import junit.framework.*;
34 import java.lang.reflect.*;
35
36 /**
37  *
38  * Unit tests for {@link HttpStatus}
39  *
40  * @author Sean C. Sullivan
41  * @version $Id: TestHttpStatus.java,v 1.2.2.2 2004/05/02 11:19:58 olegk Exp $
42  */

43 public class TestHttpStatus extends TestCase {
44
45     // ------------------------------------------------------------ Constructor
46
public TestHttpStatus(String JavaDoc testName) {
47         super(testName);
48     }
49
50     // ------------------------------------------------------------------- Main
51
public static void main(String JavaDoc args[]) {
52         String JavaDoc[] testCaseName = { TestHttpStatus.class.getName() };
53         junit.textui.TestRunner.main(testCaseName);
54     }
55
56     // ------------------------------------------------------- TestCase Methods
57

58     public static Test suite() {
59         return new TestSuite(TestHttpStatus.class);
60     }
61
62
63     // ----------------------------------------------------------- Test Methods
64

65     public void testStatusText() throws IllegalAccessException JavaDoc {
66     Field[] publicFields = HttpStatus.class.getFields();
67
68     assertTrue( publicFields != null );
69
70     assertTrue( publicFields.length > 0 );
71
72     for (int i = 0; i < publicFields.length; i++)
73     {
74         final Field f = publicFields[i];
75
76         final int modifiers = f.getModifiers();
77
78         if ( (f.getType() == int.class)
79             && Modifier.isPublic(modifiers)
80             && Modifier.isFinal(modifiers)
81             && Modifier.isStatic(modifiers) )
82         {
83             final int iValue = f.getInt(null);
84             final String JavaDoc text = HttpStatus.getStatusText(iValue);
85
86             assertTrue( "text is null for HttpStatus." + f.getName(),
87                 (text != null) );
88
89             assertTrue( text.length() > 0 );
90         }
91     }
92
93     }
94
95     public void testStatusTextNegative() throws Exception JavaDoc {
96         try {
97             HttpStatus.getStatusText(-1);
98             fail("IllegalArgumentException must have been thrown");
99         } catch (IllegalArgumentException JavaDoc expected) {
100         }
101     }
102
103     public void testStatusTextAll() throws Exception JavaDoc {
104         for (int i = 0; i < 600; i++) {
105             HttpStatus.getStatusText(i);
106         }
107     }
108 }
109
Popular Tags