001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java,v 1.4 2004/05/02 11:21:13 olegk Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import junit.framework.*;
035: import java.lang.reflect.*;
036:
037: /**
038: *
039: * Unit tests for {@link HttpStatus}
040: *
041: * @author Sean C. Sullivan
042: * @version $Id: TestHttpStatus.java 480424 2006-11-29 05:56:49Z bayard $
043: */
044: public class TestHttpStatus extends TestCase {
045:
046: // ------------------------------------------------------------ Constructor
047: public TestHttpStatus(String testName) {
048: super (testName);
049: }
050:
051: // ------------------------------------------------------------------- Main
052: public static void main(String args[]) {
053: String[] testCaseName = { TestHttpStatus.class.getName() };
054: junit.textui.TestRunner.main(testCaseName);
055: }
056:
057: // ------------------------------------------------------- TestCase Methods
058:
059: public static Test suite() {
060: return new TestSuite(TestHttpStatus.class);
061: }
062:
063: // ----------------------------------------------------------- Test Methods
064:
065: public void testStatusText() throws IllegalAccessException {
066: Field[] publicFields = HttpStatus.class.getFields();
067:
068: assertTrue(publicFields != null);
069:
070: assertTrue(publicFields.length > 0);
071:
072: for (int i = 0; i < publicFields.length; i++) {
073: final Field f = publicFields[i];
074:
075: final int modifiers = f.getModifiers();
076:
077: if ((f.getType() == int.class)
078: && Modifier.isPublic(modifiers)
079: && Modifier.isFinal(modifiers)
080: && Modifier.isStatic(modifiers)) {
081: final int iValue = f.getInt(null);
082: final String text = HttpStatus.getStatusText(iValue);
083:
084: assertTrue(
085: "text is null for HttpStatus." + f.getName(),
086: (text != null));
087:
088: assertTrue(text.length() > 0);
089: }
090: }
091:
092: }
093:
094: public void testStatusTextNegative() throws Exception {
095: try {
096: HttpStatus.getStatusText(-1);
097: fail("IllegalArgumentException must have been thrown");
098: } catch (IllegalArgumentException expected) {
099: }
100: }
101:
102: public void testStatusTextAll() throws Exception {
103: for (int i = 0; i < 600; i++) {
104: HttpStatus.getStatusText(i);
105: }
106: }
107: }
|