View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import com.jcabi.github.mock.MkGitHub;
8   import jakarta.json.Json;
9   import java.io.IOException;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.Test;
13  import org.mockito.Mockito;
14  
15  /**
16   * Tests for {@link Pull}.
17   * @since 0.7
18   * @checkstyle MultipleStringLiterals (500 lines)
19   */
20  final class PullTest {
21  
22      @Test
23      void canFetchCommentsCount() throws IOException {
24          final int number = 1;
25          final Pull pull = Mockito.mock(Pull.class);
26          Mockito.doReturn(
27              Json.createObjectBuilder()
28                  .add("comments", number)
29                  .build()
30          ).when(pull).json();
31          MatcherAssert.assertThat(
32              "Values are not equal",
33              new Pull.Smart(pull).commentsCount(),
34              Matchers.is(number)
35          );
36      }
37  
38      @Test
39      void getsIssue() {
40          final int number = 2;
41          final Issue issue = Mockito.mock(Issue.class);
42          Mockito.when(issue.number()).thenReturn(number);
43          final Issues issues = Mockito.mock(Issues.class);
44          Mockito.when(issues.get(2)).thenReturn(issue);
45          final Repo repo = Mockito.mock(Repo.class);
46          Mockito.when(repo.issues()).thenReturn(issues);
47          final Pull pull = Mockito.mock(Pull.class);
48          Mockito.when(pull.number()).thenReturn(number);
49          Mockito.when(pull.repo()).thenReturn(repo);
50          MatcherAssert.assertThat(
51              "Values are not equal",
52              new Pull.Smart(pull).issue().number(),
53              Matchers.equalTo(number)
54          );
55      }
56  
57      /**
58       * Pull.Smart can get pull comments.
59       * @throws IOException If some problem inside
60       */
61      @Test
62      void getsPullComments() throws IOException {
63          final PullComments comments = Mockito.mock(PullComments.class);
64          final Pull pull = Mockito.mock(Pull.class);
65          Mockito.when(pull.comments()).thenReturn(comments);
66          MatcherAssert.assertThat(
67              "Values are not equal",
68              new Pull.Smart(pull).comments(),
69              Matchers.equalTo(comments)
70          );
71      }
72  
73      /**
74       * Pull.Smart can get the author.
75       * @throws IOException If some problem inside
76       */
77      @Test
78      void getsAuthor() throws IOException {
79          final Repo repo = Mockito.mock(Repo.class);
80          Mockito.when(repo.github()).thenReturn(new MkGitHub());
81          final Pull pull = Mockito.mock(Pull.class);
82          final String login = "rose";
83          Mockito.when(pull.json()).thenReturn(
84              Json.createObjectBuilder()
85                  .add(
86                      "user",
87                      Json.createObjectBuilder()
88                          .add("login", login)
89                          .build()
90                  )
91                  .build()
92          );
93          Mockito.when(pull.repo()).thenReturn(repo);
94          MatcherAssert.assertThat(
95              "Values are not equal",
96              new Pull.Smart(pull).author().login(),
97              Matchers.equalTo(login)
98          );
99      }
100 }