74
74
75
75
public class PullRequestClientTest {
76
76
private static final String MOCK_GITHUB_HOST = "bogus.host" ;
77
- private static final URI MOCK_GITHUB_URI = URI .create (String .format ("http://%s/api/v3" , MOCK_GITHUB_HOST ));
77
+ private static final URI MOCK_GITHUB_URI =
78
+ URI .create (String .format ("http://%s/api/v3" , MOCK_GITHUB_HOST ));
78
79
private static final URI MOCK_GITHUB_URI_GQL = MOCK_GITHUB_URI .resolve ("/graphql" );
79
80
80
81
private static final String PR_CHANGED_FILES_TEMPLATE = "/repos/%s/%s/pulls/%s/files" ;
@@ -89,9 +90,7 @@ private static String getFixture(String resource) throws IOException {
89
90
@ BeforeEach
90
91
public void setUp () {
91
92
client = mock (OkHttpClient .class );
92
- github =
93
- GitHubClient .create (
94
- client ,MOCK_GITHUB_URI , MOCK_GITHUB_URI_GQL , "token" );
93
+ github = GitHubClient .create (client , MOCK_GITHUB_URI , MOCK_GITHUB_URI_GQL , "token" );
95
94
mockGithub = mock (GitHubClient .class );
96
95
}
97
96
@@ -429,7 +428,8 @@ void testChangedFiles() throws IOException {
429
428
430
429
final HttpResponse firstPageResponse = createMockResponse (pageLink , expectedBody );
431
430
432
- when (mockGithub .request (format (PR_CHANGED_FILES_TEMPLATE + "?per_page=30" , "owner" , "repo" , "1" )))
431
+ when (mockGithub .request (
432
+ format (PR_CHANGED_FILES_TEMPLATE + "?per_page=30" , "owner" , "repo" , "1" )))
433
433
.thenReturn (completedFuture (firstPageResponse ));
434
434
435
435
when (mockGithub .json ()).thenReturn (github .json ());
@@ -449,7 +449,8 @@ public void testListComments() throws Throwable {
449
449
final String expectedBody = "[" + getFixture ("pull_request_review_comment_reply.json" ) + "]" ;
450
450
451
451
final String pageLink =
452
- "<https://github.com/api/v3/repos/owner/repo/pulls/1/comments?page=1&per_page=30>; rel=\" first\" " ;
452
+ "<https://github.com/api/v3/repos/owner/repo/pulls/1/comments?page=1&per_page=30>;"
453
+ + " rel=\" first\" " ;
453
454
454
455
final HttpResponse firstPageResponse = createMockResponse (pageLink , expectedBody );
455
456
@@ -470,60 +471,98 @@ public void testListComments() throws Throwable {
470
471
assertThat (comments .get (0 ).user ().login (), is ("octocat" ));
471
472
}
472
473
474
+ @ Test
475
+ public void testListReviewComments () throws Throwable {
476
+ final String expectedBody = "[" + getFixture ("pull_request_review_comment_reply.json" ) + "]" ;
477
+
478
+ final String pageLink =
479
+ "<https://github.com/api/v3/repos/owner/repo/pulls/1/reviews/123/comments?page=1&per_page=30>;"
480
+ + " rel=\" first\" " ;
481
+
482
+ final HttpResponse firstPageResponse = createMockResponse (pageLink , expectedBody );
483
+
484
+ when (mockGithub .request ("/repos/owner/repo/pulls/1/reviews/123/comments?per_page=30" ))
485
+ .thenReturn (completedFuture (firstPageResponse ));
486
+
487
+ when (mockGithub .json ()).thenReturn (github .json ());
488
+
489
+ final PullRequestClient pullRequestClient =
490
+ PullRequestClient .create (mockGithub , "owner" , "repo" );
491
+
492
+ final Iterable <AsyncPage <Comment >> pageIterator =
493
+ () -> pullRequestClient .listReviewComments (1L , 123L );
494
+ List <Comment > comments = Async .streamFromPaginatingIterable (pageIterator ).collect (toList ());
495
+
496
+ assertEquals (1 , comments .size ());
497
+ assertThat (comments .get (0 ).body (), is ("Great stuff!" ));
498
+ assertThat (comments .get (0 ).id (), is (10L ));
499
+ assertThat (comments .get (0 ).user ().login (), is ("octocat" ));
500
+ }
501
+
473
502
@ Test
474
503
public void listCommitsWithoutSpecifyingPages () throws Exception {
475
504
// Given
476
505
final int COMMIT_PER_PAGE = 30 ;
477
506
478
507
final String firstPageLink =
479
- "<https://api.github.com/repos/owner/repo/pulls/1/commits?page=2>; rel=\" next\" , <https://api.github.com/repos/owner/repo/pulls/1/commits?page=4>; rel=\" last\" " ;
508
+ "<https://api.github.com/repos/owner/repo/pulls/1/commits?page=2>; rel=\" next\" ,"
509
+ + " <https://api.github.com/repos/owner/repo/pulls/1/commits?page=4>; rel=\" last\" " ;
480
510
final String firstPageBody =
481
- Resources .toString (getResource (this .getClass (), "pull_request_commits_page1.json" ), defaultCharset ());
511
+ Resources .toString (
512
+ getResource (this .getClass (), "pull_request_commits_page1.json" ), defaultCharset ());
482
513
final HttpResponse firstPageResponse = createMockResponse (firstPageLink , firstPageBody );
483
514
484
515
when (mockGithub .request ("/repos/owner/repo/pulls/1/commits" ))
485
516
.thenReturn (completedFuture (firstPageResponse ));
486
517
487
- final PullRequestClient pullRequestClient = PullRequestClient .create (mockGithub , "owner" , "repo" );
518
+ final PullRequestClient pullRequestClient =
519
+ PullRequestClient .create (mockGithub , "owner" , "repo" );
488
520
489
521
// When
490
522
final List <CommitItem > commits = pullRequestClient .listCommits (1L ).get ();
491
523
492
524
// Then
493
525
assertThat (commits .size (), is (COMMIT_PER_PAGE ));
494
526
assertThat (
495
- commits .get (COMMIT_PER_PAGE - 1 ).commit ().tree ().sha (), is ("219cb4c1ffada21259876d390df1a85767481617" ));
527
+ commits .get (COMMIT_PER_PAGE - 1 ).commit ().tree ().sha (),
528
+ is ("219cb4c1ffada21259876d390df1a85767481617" ));
496
529
}
497
530
498
531
@ Test
499
532
public void listCommitsSpecifyingPages () throws Exception {
500
533
// Given
501
534
final int COMMIT_PER_PAGE = 30 ;
502
535
503
- final String firstPageLink = String .format (
504
- "<%s/repos/owner/repo/pulls/1/commits?page=2&per_page=30>; rel=\" next\" , <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" last\" " ,
505
- MOCK_GITHUB_URI ,
506
- MOCK_GITHUB_URI );
536
+ final String firstPageLink =
537
+ String .format (
538
+ "<%s/repos/owner/repo/pulls/1/commits?page=2&per_page=30>; rel=\" next\" ,"
539
+ + " <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" last\" " ,
540
+ MOCK_GITHUB_URI , MOCK_GITHUB_URI );
507
541
final String firstPageBody =
508
- Resources .toString (getResource (this .getClass (), "pull_request_commits_page1.json" ), defaultCharset ());
542
+ Resources .toString (
543
+ getResource (this .getClass (), "pull_request_commits_page1.json" ), defaultCharset ());
509
544
final HttpResponse firstPageResponse = createMockResponse (firstPageLink , firstPageBody );
510
545
511
- final String secondPageLink = String .format (
512
- "<%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" prev\" , <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" next\" , <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" last\" , <%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" first\" " ,
513
- MOCK_GITHUB_URI ,
514
- MOCK_GITHUB_URI ,
515
- MOCK_GITHUB_URI ,
516
- MOCK_GITHUB_URI );
546
+ final String secondPageLink =
547
+ String .format (
548
+ "<%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" prev\" ,"
549
+ + " <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" next\" ,"
550
+ + " <%s/repos/owner/repo/pulls/1/commits?page=3&per_page=30>; rel=\" last\" ,"
551
+ + " <%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" first\" " ,
552
+ MOCK_GITHUB_URI , MOCK_GITHUB_URI , MOCK_GITHUB_URI , MOCK_GITHUB_URI );
517
553
final String secondPageBody =
518
- Resources .toString (getResource (this .getClass (), "pull_request_commits_page2.json" ), defaultCharset ());
554
+ Resources .toString (
555
+ getResource (this .getClass (), "pull_request_commits_page2.json" ), defaultCharset ());
519
556
final HttpResponse secondPageResponse = createMockResponse (secondPageLink , secondPageBody );
520
557
521
558
final String thirdPageLink =
522
- String .format ("<%s/repos/owner/repo/pulls/1/commits?page=2&per_page=30>; rel=\" prev\" , <%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" first\" " ,
523
- MOCK_GITHUB_URI ,
524
- MOCK_GITHUB_URI );
559
+ String .format (
560
+ "<%s/repos/owner/repo/pulls/1/commits?page=2&per_page=30>; rel=\" prev\" ,"
561
+ + " <%s/repos/owner/repo/pulls/1/commits?page=1&per_page=30>; rel=\" first\" " ,
562
+ MOCK_GITHUB_URI , MOCK_GITHUB_URI );
525
563
final String thirdPageBody =
526
- Resources .toString (getResource (this .getClass (), "pull_request_commits_page3.json" ), defaultCharset ());
564
+ Resources .toString (
565
+ getResource (this .getClass (), "pull_request_commits_page3.json" ), defaultCharset ());
527
566
final HttpResponse thirdPageResponse = createMockResponse (thirdPageLink , thirdPageBody );
528
567
529
568
when (mockGithub .urlFor ("" )).thenReturn (MOCK_GITHUB_URI .toString ());
@@ -537,15 +576,19 @@ public void listCommitsSpecifyingPages() throws Exception {
537
576
when (mockGithub .request ("/repos/owner/repo/pulls/1/commits?page=3&per_page=30" ))
538
577
.thenReturn (completedFuture (thirdPageResponse ));
539
578
540
- final PullRequestClient pullRequestClient = PullRequestClient .create (mockGithub , "owner" , "repo" );
579
+ final PullRequestClient pullRequestClient =
580
+ PullRequestClient .create (mockGithub , "owner" , "repo" );
541
581
542
582
// When
543
- final Iterable <AsyncPage <CommitItem >> pageIterator = () -> pullRequestClient .listCommits (1L , 30 );
544
- final List <CommitItem > commits = Async .streamFromPaginatingIterable (pageIterator ).collect (toList ());
583
+ final Iterable <AsyncPage <CommitItem >> pageIterator =
584
+ () -> pullRequestClient .listCommits (1L , 30 );
585
+ final List <CommitItem > commits =
586
+ Async .streamFromPaginatingIterable (pageIterator ).collect (toList ());
545
587
546
588
// Then
547
589
assertThat (commits .size (), is (COMMIT_PER_PAGE * 3 ));
548
590
assertThat (
549
- commits .get (COMMIT_PER_PAGE - 1 ).commit ().tree ().sha (), is ("219cb4c1ffada21259876d390df1a85767481617" ));
591
+ commits .get (COMMIT_PER_PAGE - 1 ).commit ().tree ().sha (),
592
+ is ("219cb4c1ffada21259876d390df1a85767481617" ));
550
593
}
551
594
}
0 commit comments