1 30 31 package org.apache.commons.httpclient; 32 33 import junit.framework.*; 34 import java.lang.reflect.*; 35 36 43 public class TestHttpStatus extends TestCase { 44 45 public TestHttpStatus(String testName) { 47 super(testName); 48 } 49 50 public static void main(String args[]) { 52 String [] testCaseName = { TestHttpStatus.class.getName() }; 53 junit.textui.TestRunner.main(testCaseName); 54 } 55 56 58 public static Test suite() { 59 return new TestSuite(TestHttpStatus.class); 60 } 61 62 63 65 public void testStatusText() throws IllegalAccessException { 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 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 { 96 try { 97 HttpStatus.getStatusText(-1); 98 fail("IllegalArgumentException must have been thrown"); 99 } catch (IllegalArgumentException expected) { 100 } 101 } 102 103 public void testStatusTextAll() throws Exception { 104 for (int i = 0; i < 600; i++) { 105 HttpStatus.getStatusText(i); 106 } 107 } 108 } 109 | Popular Tags |