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.message;
29
30 import java.util.Locale;
31
32 import org.apache.hc.core5.http.HttpResponse;
33 import org.apache.hc.core5.http.HttpStatus;
34 import org.junit.jupiter.api.Assertions;
35 import org.junit.jupiter.api.Test;
36
37 public class HttpResponseWrapperTest {
38
39 @Test
40 void testDefaultResponseConstructors() {
41 final HttpResponse response1 = new BasicHttpResponse(HttpStatus.SC_BAD_REQUEST, "Bad Request");
42 final HttpResponseWrapper httpResponseWrapper1 = new HttpResponseWrapper(response1);
43
44 Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, httpResponseWrapper1.getCode());
45
46 final HttpResponse response2 = new BasicHttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "whatever");
47 final HttpResponseWrapper httpResponseWrapper2 = new HttpResponseWrapper(response2);
48 Assertions.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, httpResponseWrapper2.getCode());
49 Assertions.assertEquals("whatever", httpResponseWrapper2.getReasonPhrase());
50
51 httpResponseWrapper2.setReasonPhrase("another-whatever");
52 Assertions.assertEquals("another-whatever", httpResponseWrapper2.getReasonPhrase());
53 }
54
55 @Test
56 void testSetResponseStatus() {
57 final HttpResponse response1 = new BasicHttpResponse(200, "OK");
58 final HttpResponseWrapper httpResponseWrapper1 = new HttpResponseWrapper(response1);
59
60 Assertions.assertNotNull(httpResponseWrapper1.getCode());
61 Assertions.assertEquals(200, httpResponseWrapper1.getCode());
62
63 final HttpResponse response2 = new BasicHttpResponse(HttpStatus.SC_BAD_REQUEST, "Bad Request");
64 final HttpResponseWrapper httpResponseWrapper2 = new HttpResponseWrapper(response2);
65 Assertions.assertEquals(HttpStatus.SC_BAD_REQUEST, httpResponseWrapper2.getCode());
66
67 final HttpResponse response3 = new BasicHttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "whatever");
68 final HttpResponseWrapper httpResponseWrapper3 = new HttpResponseWrapper(response3);
69 Assertions.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, httpResponseWrapper3.getCode());
70 Assertions.assertEquals("whatever", httpResponseWrapper3.getReasonPhrase());
71
72 final HttpResponse response4 = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
73 final HttpResponseWrapper httpResponseWrapper4 = new HttpResponseWrapper(response4);
74 Assertions.assertThrows(IllegalArgumentException.class, () -> httpResponseWrapper4.setCode(-23));
75 }
76
77 @Test
78 void testLocale() {
79 final HttpResponse response = new BasicHttpResponse(200, "OK");
80 final HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper(response);
81 httpResponseWrapper.setLocale(Locale.US);
82 Assertions.assertEquals("US", httpResponseWrapper.getLocale().getCountry());
83 }
84
85 }