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 package org.apache.hc.core5.http;
28
29 import org.apache.hc.core5.util.LangUtils;
30 import org.hamcrest.BaseMatcher;
31 import org.hamcrest.Description;
32 import org.hamcrest.Factory;
33 import org.hamcrest.Matcher;
34
35 public class HeaderMatcher extends BaseMatcher<Header> {
36
37 private final String headerName;
38 private final Object headerValue;
39
40 public HeaderMatcher(final String headerName, final Object headerValue) {
41 this.headerName = headerName;
42 this.headerValue = headerValue;
43 }
44
45 @Override
46 public boolean matches(final Object item) {
47 if (item instanceof Header) {
48 final Header header = (Header) item;
49 if (headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue())) {
50 return true;
51 }
52 }
53 return false;
54 }
55
56 @Override
57 public void describeTo(final Description description) {
58 description.appendText("same header as ").appendValue(headerValue).appendText(": ").appendValue(headerValue);
59 }
60
61 @Factory
62 public static Matcher<Header> same(final String headerName, final Object headerValue) {
63 return new HeaderMatcher(headerName, headerValue);
64 }
65
66 }