24
24
import static com .spotify .github .v3 .clients .GitHubClient .LIST_PENDING_TEAM_INVITATIONS ;
25
25
import static com .spotify .github .v3 .clients .GitHubClient .LIST_TEAMS ;
26
26
import static com .spotify .github .v3 .clients .GitHubClient .LIST_TEAM_MEMBERS ;
27
+ import static com .spotify .github .v3 .clients .MockHelper .createMockResponse ;
27
28
import static java .nio .charset .Charset .defaultCharset ;
28
29
import static java .util .concurrent .CompletableFuture .completedFuture ;
30
+ import static java .util .stream .Collectors .toList ;
31
+ import static java .util .stream .StreamSupport .stream ;
29
32
import static org .hamcrest .MatcherAssert .assertThat ;
30
33
import static org .hamcrest .core .Is .is ;
31
34
import static org .mockito .ArgumentMatchers .any ;
32
35
import static org .mockito .ArgumentMatchers .eq ;
33
36
import static org .mockito .Mockito .*;
34
37
35
38
import com .google .common .io .Resources ;
39
+ import com .spotify .github .async .AsyncPage ;
36
40
import com .spotify .github .jackson .Json ;
37
41
import com .spotify .github .v3 .Team ;
38
42
import com .spotify .github .v3 .User ;
43
+ import com .spotify .github .v3 .comment .Comment ;
39
44
import com .spotify .github .v3 .orgs .Membership ;
40
45
import com .spotify .github .v3 .orgs .TeamInvitation ;
41
46
import com .spotify .github .v3 .orgs .requests .MembershipCreate ;
42
47
import com .spotify .github .v3 .orgs .requests .TeamCreate ;
43
48
import com .spotify .github .v3 .orgs .requests .TeamUpdate ;
44
49
import java .io .IOException ;
50
+ import java .util .Iterator ;
45
51
import java .util .List ;
46
52
import java .util .concurrent .CompletableFuture ;
47
53
import okhttp3 .Response ;
@@ -67,6 +73,7 @@ public void setUp() {
67
73
teamClient = new TeamClient (github , "github" );
68
74
json = Json .create ();
69
75
when (github .json ()).thenReturn (json );
76
+ when (github .urlFor ("" )).thenReturn ("https://github.com/api/v3" );
70
77
}
71
78
72
79
@ Test
@@ -156,6 +163,37 @@ public void listTeamMembers() throws Exception {
156
163
assertThat (teamMembers .size (), is (2 ));
157
164
}
158
165
166
+ @ Test
167
+ public void listTeamMembersPaged () throws Exception {
168
+ final String firstPageLink =
169
+ "<https://github.com/api/v3/orgs/github/teams/1/members?page=2>; rel=\" next\" , <https://github.com/api/v3/orgs/github/teams/1/members?page=2>; rel=\" last\" " ;
170
+ final String firstPageBody =
171
+ Resources .toString (getResource (this .getClass (), "list_members_page1.json" ), defaultCharset ());
172
+ final Response firstPageResponse = createMockResponse (firstPageLink , firstPageBody );
173
+
174
+ final String lastPageLink =
175
+ "<https://github.com/api/v3/orgs/github/teams/1/members>; rel=\" first\" , <https://github.com/api/v3/orgs/github/teams/1/members>; rel=\" prev\" " ;
176
+ final String lastPageBody =
177
+ Resources .toString (getResource (this .getClass (), "list_members_page2.json" ), defaultCharset ());
178
+
179
+ final Response lastPageResponse = createMockResponse (lastPageLink , lastPageBody );
180
+
181
+ when (github .request (endsWith ("/orgs/github/teams/1/members?per_page=1" )))
182
+ .thenReturn (completedFuture (firstPageResponse ));
183
+ when (github .request (endsWith ("/orgs/github/teams/1/members?page=2" )))
184
+ .thenReturn (completedFuture (lastPageResponse ));
185
+
186
+ final Iterable <AsyncPage <User >> pageIterator = () -> teamClient .listTeamMembers ("1" , 1 );
187
+ final List <User > users =
188
+ stream (pageIterator .spliterator (), false )
189
+ .flatMap (page -> stream (page .spliterator (), false ))
190
+ .collect (toList ());
191
+
192
+ assertThat (users .size (), is (2 ));
193
+ assertThat (users .get (0 ).login (), is ("octocat" ));
194
+ assertThat (users .get (1 ).id (), is (2 ));
195
+ }
196
+
159
197
@ Test
160
198
public void updateMembership () throws Exception {
161
199
final MembershipCreate membershipCreateRequest =
0 commit comments