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;
29
30 import org.junit.Assert;
31 import org.junit.Test;
32
33
34
35
36 public class TestHttpExceptions {
37
38 private static final String CLEAN_MESSAGE = "[0x00]Hello[0x06][0x07][0x08][0x09][0x0a][0x0b][0x0c][0x0d][0x0e][0x0f]World";
39 private static final String nonPrintableMessage = String.valueOf(
40 new char[] { 1, 'H', 'e', 'l', 'l', 'o', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 'W', 'o', 'r', 'l', 'd' });
41
42 @Test
43 public void testConstructor() {
44 final Throwable cause = new Exception();
45 new HttpException();
46 new HttpException("Oppsie");
47 new HttpException("Oppsie", cause);
48 new ProtocolException();
49 new ProtocolException("Oppsie");
50 new ProtocolException("Oppsie", cause);
51 new NoHttpResponseException("Oppsie");
52 new ConnectionClosedException("Oppsie");
53 new MethodNotSupportedException("Oppsie");
54 new MethodNotSupportedException("Oppsie", cause);
55 new UnsupportedHttpVersionException();
56 new UnsupportedHttpVersionException("Oppsie");
57 }
58
59 @Test
60 public void testNonPrintableCharactersInConnectionClosedException() {
61 Assert.assertEquals(CLEAN_MESSAGE, new ConnectionClosedException(nonPrintableMessage).getMessage());
62 }
63
64 @Test
65 public void testNonPrintableCharactersInHttpException() {
66 Assert.assertEquals(CLEAN_MESSAGE, new HttpException(nonPrintableMessage).getMessage());
67 }
68
69 @Test
70 public void testNonPrintableCharactersInMethodNotSupportedException() {
71 Assert.assertEquals(CLEAN_MESSAGE, new MethodNotSupportedException(nonPrintableMessage).getMessage());
72 }
73
74 @Test
75 public void testNonPrintableCharactersInNoHttpResponseException() {
76 Assert.assertEquals(CLEAN_MESSAGE, new NoHttpResponseException(nonPrintableMessage).getMessage());
77 }
78
79 @Test
80 public void testNonPrintableCharactersInProtocolException() {
81 Assert.assertEquals(CLEAN_MESSAGE, new ProtocolException(nonPrintableMessage).getMessage());
82 }
83
84 @Test
85 public void testNonPrintableCharactersInUnsupportedHttpVersionException() {
86 Assert.assertEquals(CLEAN_MESSAGE, new UnsupportedHttpVersionException(nonPrintableMessage).getMessage());
87 }
88
89 }