1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 155418 2005-02-26 13:01:52Z dirkv $
42 */
43 public class TestHttpStatus extends TestCase {
44
45
46 public TestHttpStatus(String testName) {
47 super(testName);
48 }
49
50
51 public static void main(String args[]) {
52 String[] testCaseName = { TestHttpStatus.class.getName() };
53 junit.textui.TestRunner.main(testCaseName);
54 }
55
56
57
58 public static Test suite() {
59 return new TestSuite(TestHttpStatus.class);
60 }
61
62
63
64
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 }