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
29
30 package com.jcabi.github;
31
32 import com.jcabi.http.mock.MkAnswer;
33 import com.jcabi.http.mock.MkContainer;
34 import com.jcabi.http.mock.MkGrizzlyContainer;
35 import com.jcabi.http.request.JdkRequest;
36 import java.net.HttpURLConnection;
37 import javax.json.Json;
38 import javax.json.JsonValue;
39 import org.hamcrest.MatcherAssert;
40 import org.hamcrest.Matchers;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.mockito.Mockito;
44
45
46
47
48
49
50
51
52 public final class RtAssigneesTest {
53
54
55
56
57
58 @Rule
59 public final transient RandomPort resource = new RandomPort();
60
61
62
63
64
65 @Test
66 public void iteratesAssignees() throws Exception {
67 try (
68 final MkContainer container = new MkGrizzlyContainer().next(
69 new MkAnswer.Simple(
70 HttpURLConnection.HTTP_OK,
71 Json.createArrayBuilder()
72 .add(RtAssigneesTest.json("octocat"))
73 .add(RtAssigneesTest.json("dummy"))
74 .build().toString()
75 )
76 ).start(this.resource.port());
77 ) {
78 final Assignees users = new RtAssignees(
79 new JdkRequest(container.home()),
80 this.repo()
81 );
82 MatcherAssert.assertThat(
83 users.iterate(),
84 Matchers.<User>iterableWithSize(2)
85 );
86 }
87 }
88
89
90
91
92
93 @Test
94 public void checkUserIsAssigneeForRepo() throws Exception {
95 try (
96 final MkContainer container = new MkGrizzlyContainer().next(
97 new MkAnswer.Simple(
98 HttpURLConnection.HTTP_NO_CONTENT,
99 Json.createArrayBuilder()
100 .add(RtAssigneesTest.json("octocat2"))
101 .add(RtAssigneesTest.json("dummy"))
102 .build().toString()
103 )
104 ).start(this.resource.port())) {
105 final Assignees users = new RtAssignees(
106 new JdkRequest(container.home()),
107 this.repo()
108 );
109 MatcherAssert.assertThat(
110 users.check("octocat2"),
111 Matchers.equalTo(true)
112 );
113 }
114 }
115
116
117
118
119
120 @Test
121 public void checkUserIsNotAssigneeForRepo() throws Exception {
122 try (
123 final MkContainer container = new MkGrizzlyContainer().next(
124 new MkAnswer.Simple(
125 HttpURLConnection.HTTP_NOT_FOUND,
126 Json.createArrayBuilder()
127 .add(RtAssigneesTest.json("octocat3"))
128 .add(RtAssigneesTest.json("dummy"))
129 .build().toString()
130 )
131 ).start(this.resource.port());
132 ) {
133 final Assignees users = new RtAssignees(
134 new JdkRequest(container.home()),
135 this.repo()
136 );
137 MatcherAssert.assertThat(
138 users.check("octocat33"),
139 Matchers.equalTo(false)
140 );
141 }
142 }
143
144
145
146
147
148
149 private static JsonValue json(final String login) {
150 return Json.createObjectBuilder()
151 .add("login", login)
152 .build();
153 }
154
155
156
157
158
159 private Repo repo() {
160 final Repo repo = Mockito.mock(Repo.class);
161 Mockito.doReturn(new Coordinates.Simple("test", "assignee"))
162 .when(repo).coordinates();
163 Mockito.doReturn(Mockito.mock(Github.class)).when(repo).github();
164 return repo;
165 }
166 }