    1   /*
    2    * $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 $
    3    * $Revision: 480424 $
    4    * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
    5    * ====================================================================
    6    *
    7    *  Licensed to the Apache Software Foundation (ASF) under one or more
    8    *  contributor license agreements.  See the NOTICE file distributed with
    9    *  this work for additional information regarding copyright ownership.
    10   *  The ASF licenses this file to You under the Apache License, Version 2.0
    11   *  (the "License"); you may not use this file except in compliance with
    12   *  the License.  You may obtain a copy of the License at
    13   *
    14   *      http://www.apache.org/licenses/LICENSE-2.0
    15   *
    16   *  Unless required by applicable law or agreed to in writing, software
    17   *  distributed under the License is distributed on an "AS IS" BASIS,
    18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    19   *  See the License for the specific language governing permissions and
    20   *  limitations under the License.
    21   * ====================================================================
    22   *
    23   * This software consists of voluntary contributions made by many
    24   * individuals on behalf of the Apache Software Foundation.  For more
    25   * information on the Apache Software Foundation, please see
    26   * <http://www.apache.org/>.
    27   *
    28   * [Additional notices, if required by prior licensing conditions]
    29   *
    30   */
    31
    32  package org.apache.commons.httpclient;
    33
    34  import junit.framework.*;
    35  import java.lang.reflect.*;
    36
    37  /**
    38   *
    39   * Unit tests for {@link HttpStatus}
    40   *
    41   * @author Sean C. Sullivan
    42   * @version $Id: TestHttpStatus.java 480424 2006-11-29 05:56:49Z bayard $
    43   */
    44  public class TestHttpStatus extends TestCase {
    45
    46      // ------------------------------------------------------------ Constructor
    47      public TestHttpStatus(String testName) {
    48          super(testName);
    49      }
    50
    51      // ------------------------------------------------------------------- Main
    52      public static void main(String args[]) {
    53          String[] testCaseName = { TestHttpStatus.class.getName() };
    54          junit.textui.TestRunner.main(testCaseName);
    55      }
    56
    57      // ------------------------------------------------------- TestCase Methods
    58
    59      public static Test suite() {
    60          return new TestSuite(TestHttpStatus.class);
    61      }
    62
    63
    64      // ----------------------------------------------------------- Test Methods
    65
    66      public void testStatusText() throws IllegalAccessException {
    67  	Field[] publicFields = HttpStatus.class.getFields();
    68
    69  	assertTrue( publicFields != null );
    70
    71  	assertTrue( publicFields.length > 0 );
    72
    73  	for (int i = 0; i < publicFields.length; i++)
    74  	{
    75  		final Field f = publicFields[i];
    76
    77  		final int modifiers = f.getModifiers();
    78
    79  		if ( (f.getType() == int.class)
    80  			&& Modifier.isPublic(modifiers)
    81  			&& Modifier.isFinal(modifiers)
    82  			&& Modifier.isStatic(modifiers) )
    83  		{
    84  			final int iValue = f.getInt(null);
    85  			final String text = HttpStatus.getStatusText(iValue);
    86
    87  			assertTrue( "text is null for HttpStatus." + f.getName(),
    88  				(text != null) );
    89
    90  			assertTrue( text.length() > 0 );
    91  		}
    92  	}
    93
    94      }
    95
    96      public void testStatusTextNegative() throws Exception {
    97          try {
    98              HttpStatus.getStatusText(-1);
    99              fail("IllegalArgumentException must have been thrown");
    100         } catch (IllegalArgumentException expected) {
    101         }
    102     }
    103
    104     public void testStatusTextAll() throws Exception {
    105         for (int i = 0; i < 600; i++) {
    106             HttpStatus.getStatusText(i);
    107         }
    108     }
    109 }