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.github.mock.MkGithub;
33 import java.io.IOException;
34 import javax.json.Json;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39
40
41
42
43
44
45
46 public final class PullTest {
47
48
49
50
51
52
53 @Test
54 public void canFetchCommentsCount() throws Exception {
55 final int number = 1;
56 final Pull pull = Mockito.mock(Pull.class);
57 Mockito.doReturn(
58 Json.createObjectBuilder()
59 .add("comments", number)
60 .build()
61 ).when(pull).json();
62 MatcherAssert.assertThat(
63 new Pull.Smart(pull).commentsCount(),
64 Matchers.is(number)
65 );
66 }
67
68
69
70
71 @Test
72 public void getsIssue() {
73 final int number = 2;
74 final Issue issue = Mockito.mock(Issue.class);
75 Mockito.when(issue.number()).thenReturn(number);
76 final Issues issues = Mockito.mock(Issues.class);
77 Mockito.when(issues.get(2)).thenReturn(issue);
78 final Repo repo = Mockito.mock(Repo.class);
79 Mockito.when(repo.issues()).thenReturn(issues);
80 final Pull pull = Mockito.mock(Pull.class);
81 Mockito.when(pull.number()).thenReturn(number);
82 Mockito.when(pull.repo()).thenReturn(repo);
83 MatcherAssert.assertThat(
84 new Pull.Smart(pull).issue().number(),
85 Matchers.equalTo(number)
86 );
87 }
88
89
90
91
92
93 @Test
94 public void getsPullComments() throws IOException {
95 final PullComments pullComments = Mockito.mock(PullComments.class);
96 final Pull pull = Mockito.mock(Pull.class);
97 Mockito.when(pull.comments()).thenReturn(pullComments);
98 MatcherAssert.assertThat(
99 new Pull.Smart(pull).comments(),
100 Matchers.equalTo(pullComments)
101 );
102 }
103
104
105
106
107
108 @Test
109 public void getsAuthor() throws IOException {
110 final String login = "rose";
111 final Repo repo = Mockito.mock(Repo.class);
112 Mockito.when(repo.github()).thenReturn(new MkGithub());
113 final Pull pull = Mockito.mock(Pull.class);
114 Mockito.when(pull.json()).thenReturn(
115 Json.createObjectBuilder()
116 .add(
117 "user",
118 Json.createObjectBuilder()
119 .add("login", login)
120 .build()
121 )
122 .build()
123 );
124 Mockito.when(pull.repo()).thenReturn(repo);
125 MatcherAssert.assertThat(
126 new Pull.Smart(pull).author().login(),
127 Matchers.equalTo(login)
128 );
129 }
130 }