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 package org.apache.hc.core5.http.impl;
29
30 import java.lang.reflect.Field;
31 import java.lang.reflect.Modifier;
32
33 import org.apache.hc.core5.http.HttpStatus;
34 import org.junit.Assert;
35 import org.junit.Test;
36
37
38
39
40
41
42 public class TestEnglishReasonPhraseCatalog {
43
44 @Test
45 public void testReasonPhrases() throws IllegalAccessException {
46 final Field[] publicFields = HttpStatus.class.getFields();
47
48 Assert.assertNotNull( publicFields );
49
50 Assert.assertTrue( publicFields.length > 0 );
51
52 for (final Field f : publicFields) {
53 final int modifiers = f.getModifiers();
54
55 if ( (f.getType() == int.class)
56 && Modifier.isPublic(modifiers)
57 && Modifier.isFinal(modifiers)
58 && Modifier.isStatic(modifiers) )
59 {
60 final int iValue = f.getInt(null);
61 final String text = EnglishReasonPhraseCatalog.
62 INSTANCE.getReason(iValue, null);
63 Assert.assertNotNull("text is null for HttpStatus."+f.getName(), text);
64 Assert.assertTrue(text.length() > 0);
65 }
66 }
67 }
68
69
70 @Test
71 public void testStatusInvalid() throws Exception {
72 try {
73 EnglishReasonPhraseCatalog.INSTANCE.getReason(-1, null);
74 Assert.fail("IllegalArgumentException must have been thrown (-1)");
75 } catch (final IllegalArgumentException expected) {
76 }
77 try {
78 EnglishReasonPhraseCatalog.INSTANCE.getReason(99, null);
79 Assert.fail("IllegalArgumentException must have been thrown (99)");
80 } catch (final IllegalArgumentException expected) {
81 }
82 try {
83 EnglishReasonPhraseCatalog.INSTANCE.getReason(600, null);
84 Assert.fail("IllegalArgumentException must have been thrown (600)");
85 } catch (final IllegalArgumentException expected) {
86 }
87 }
88
89 @Test
90 public void testStatusAll() throws Exception {
91 for (int i = 100; i < 600; i++) {
92 EnglishReasonPhraseCatalog.INSTANCE.getReason(i, null);
93 }
94 }
95 }