2424import static com .spotify .github .v3 .clients .GitHubClient .LIST_PENDING_TEAM_INVITATIONS ;
2525import static com .spotify .github .v3 .clients .GitHubClient .LIST_TEAMS ;
2626import static com .spotify .github .v3 .clients .GitHubClient .LIST_TEAM_MEMBERS ;
27+ import static com .spotify .github .v3 .clients .MockHelper .createMockResponse ;
2728import static java .nio .charset .Charset .defaultCharset ;
2829import static java .util .concurrent .CompletableFuture .completedFuture ;
30+ import static java .util .stream .Collectors .toList ;
31+ import static java .util .stream .StreamSupport .stream ;
2932import static org .hamcrest .MatcherAssert .assertThat ;
3033import static org .hamcrest .core .Is .is ;
3134import static org .mockito .ArgumentMatchers .any ;
3235import static org .mockito .ArgumentMatchers .eq ;
3336import static org .mockito .Mockito .*;
3437
3538import com .google .common .io .Resources ;
39+ import com .spotify .github .async .AsyncPage ;
3640import com .spotify .github .jackson .Json ;
3741import com .spotify .github .v3 .Team ;
3842import com .spotify .github .v3 .User ;
43+ import com .spotify .github .v3 .comment .Comment ;
3944import com .spotify .github .v3 .orgs .Membership ;
4045import com .spotify .github .v3 .orgs .TeamInvitation ;
4146import com .spotify .github .v3 .orgs .requests .MembershipCreate ;
4247import com .spotify .github .v3 .orgs .requests .TeamCreate ;
4348import com .spotify .github .v3 .orgs .requests .TeamUpdate ;
4449import java .io .IOException ;
50+ import java .util .Iterator ;
4551import java .util .List ;
4652import java .util .concurrent .CompletableFuture ;
4753import okhttp3 .Response ;
@@ -67,6 +73,7 @@ public void setUp() {
6773 teamClient = new TeamClient (github , "github" );
6874 json = Json .create ();
6975 when (github .json ()).thenReturn (json );
76+ when (github .urlFor ("" )).thenReturn ("https://github.com/api/v3" );
7077 }
7178
7279 @ Test
@@ -156,6 +163,37 @@ public void listTeamMembers() throws Exception {
156163 assertThat (teamMembers .size (), is (2 ));
157164 }
158165
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+
159197 @ Test
160198 public void updateMembership () throws Exception {
161199 final MembershipCreate membershipCreateRequest =
0 commit comments