001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/impl/TestEnglishReasonPhraseCatalog.java $
003: * $Revision: 503381 $
004: * $Date: 2007-02-04 11:59:10 +0100 (Sun, 04 Feb 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.impl;
033:
034: import junit.framework.*;
035: import java.lang.reflect.*;
036:
037: import org.apache.http.HttpStatus;
038:
039: /**
040: *
041: * Unit tests for {@link EnglishReasonPhraseCatalog}
042: *
043: * @author Sean C. Sullivan
044: */
045: public class TestEnglishReasonPhraseCatalog extends TestCase {
046:
047: // ------------------------------------------------------------ Constructor
048: public TestEnglishReasonPhraseCatalog(String testName) {
049: super (testName);
050: }
051:
052: // ------------------------------------------------------------------- Main
053: public static void main(String args[]) {
054: String[] testCaseName = { TestEnglishReasonPhraseCatalog.class
055: .getName() };
056: junit.textui.TestRunner.main(testCaseName);
057: }
058:
059: // ------------------------------------------------------- TestCase Methods
060:
061: public static Test suite() {
062: return new TestSuite(TestEnglishReasonPhraseCatalog.class);
063: }
064:
065: // ----------------------------------------------------------- Test Methods
066:
067: public void testReasonPhrases() throws IllegalAccessException {
068: Field[] publicFields = HttpStatus.class.getFields();
069:
070: assertTrue(publicFields != null);
071:
072: assertTrue(publicFields.length > 0);
073:
074: for (int i = 0; i < publicFields.length; i++) {
075: final Field f = publicFields[i];
076:
077: final int modifiers = f.getModifiers();
078:
079: if ((f.getType() == int.class)
080: && Modifier.isPublic(modifiers)
081: && Modifier.isFinal(modifiers)
082: && Modifier.isStatic(modifiers)) {
083: final int iValue = f.getInt(null);
084: final String text = EnglishReasonPhraseCatalog.INSTANCE
085: .getReason(iValue, null);
086: assertTrue(
087: "text is null for HttpStatus." + f.getName(),
088: (text != null));
089: assertTrue(text.length() > 0);
090: }
091: }
092: }
093:
094: public void testStatusInvalid() throws Exception {
095: try {
096: EnglishReasonPhraseCatalog.INSTANCE.getReason(-1, null);
097: fail("IllegalArgumentException must have been thrown (-1)");
098: } catch (IllegalArgumentException expected) {
099: }
100: try {
101: EnglishReasonPhraseCatalog.INSTANCE.getReason(99, null);
102: fail("IllegalArgumentException must have been thrown (99)");
103: } catch (IllegalArgumentException expected) {
104: }
105: try {
106: EnglishReasonPhraseCatalog.INSTANCE.getReason(600, null);
107: fail("IllegalArgumentException must have been thrown (600)");
108: } catch (IllegalArgumentException expected) {
109: }
110: }
111:
112: public void testStatusAll() throws Exception {
113: for (int i = 100; i < 600; i++) {
114: EnglishReasonPhraseCatalog.INSTANCE.getReason(i, null);
115: }
116: }
117: }
|