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.protocol;
29
30 import java.util.LinkedList;
31 import java.util.List;
32
33 import org.apache.hc.core5.http.HttpRequestInterceptor;
34 import org.junit.Assert;
35 import org.junit.Test;
36
37 public class TestChainBuilder {
38
39 @Test
40 public void testBuildChain() throws Exception {
41 final ChainBuilder<HttpRequestInterceptor> cb = new ChainBuilder<>();
42 final HttpRequestInterceptor i1 = new RequestContent();
43 final HttpRequestInterceptor i2 = new RequestTargetHost();
44 final HttpRequestInterceptor i3 = new RequestConnControl();
45 final HttpRequestInterceptor i4 = new RequestUserAgent();
46 final HttpRequestInterceptor i5 = new RequestExpectContinue();
47 cb.addFirst(i1);
48 cb.addAllFirst(i2, i3);
49 cb.addFirst(null);
50 cb.addAllFirst((List<HttpRequestInterceptor>) null);
51 cb.addLast(i4);
52 cb.addLast(null);
53 cb.addAllLast(i5);
54 cb.addAllLast((List<HttpRequestInterceptor>) null);
55 cb.addFirst(i1);
56 cb.addAllLast(i3, i4, i5);
57 final LinkedList<HttpRequestInterceptor> list = cb.build();
58 Assert.assertNotNull(list);
59 Assert.assertEquals(5, list.size());
60 Assert.assertSame(i1, list.get(0));
61 Assert.assertSame(i2, list.get(1));
62 Assert.assertSame(i3, list.get(2));
63 Assert.assertSame(i4, list.get(3));
64 Assert.assertSame(i5, list.get(4));
65 }
66
67 }