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
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 608014 2008-01-02 05:48:53Z rolandw $
43 */
44 public class TestHttpStatus extends TestCase {
45
46
47 public TestHttpStatus(String testName) {
48 super(testName);
49 }
50
51
52 public static void main(String args[]) {
53 String[] testCaseName = { TestHttpStatus.class.getName() };
54 junit.textui.TestRunner.main(testCaseName);
55 }
56
57
58
59 public static Test suite() {
60 return new TestSuite(TestHttpStatus.class);
61 }
62
63
64
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 }