1
2
3
4
5 package com.jcabi.http.mock;
6
7 import java.net.URI;
8 import java.util.Collections;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Test;
12 import org.mockito.Mockito;
13
14
15
16
17
18
19 final class MkQueryMatchersTest {
20
21
22
23
24 @Test
25 void canMatchBody() {
26 final String body = "Hello \u20ac!";
27 final MkQuery query = Mockito.mock(MkQuery.class);
28 Mockito.doReturn(body).when(query).body();
29 MatcherAssert.assertThat(
30 "should match the query body",
31 query,
32 MkQueryMatchers.hasBody(
33 Matchers.is(body)
34 )
35 );
36 }
37
38
39
40
41 @Test
42 void canMatchHeader() {
43 final String header = "Content-Type";
44 final String value = "application/json";
45 final MkQuery query = Mockito.mock(MkQuery.class);
46 Mockito.doReturn(
47 Collections.singletonMap(header, Collections.singletonList(value))
48 ).when(query).headers();
49 MatcherAssert.assertThat(
50 "should match the query header",
51 query,
52 MkQueryMatchers.hasHeader(
53 header,
54 Matchers.contains(value)
55 )
56 );
57 }
58
59
60
61
62 @Test
63 void canMatchPath() {
64 final URI body = URI.create("http://example.com/index.html?y=x");
65 final MkQuery query = Mockito.mock(MkQuery.class);
66 Mockito.doReturn(body).when(query).uri();
67 MatcherAssert.assertThat(
68 "should match the raw path",
69 query,
70 MkQueryMatchers.hasPath(
71 Matchers.is("/index.html")
72 )
73 );
74 }
75
76
77
78
79 @Test
80 void canMatchQuery() {
81 final URI body = URI.create("http://example.com/?x=10");
82 final MkQuery query = Mockito.mock(MkQuery.class);
83 Mockito.doReturn(body).when(query).uri();
84 MatcherAssert.assertThat(
85 "should match the raw query",
86 query,
87 MkQueryMatchers.hasQuery(
88 Matchers.is("x=10")
89 )
90 );
91 }
92
93 }