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