18
18
* -/-/-
19
19
*/
20
20
21
-
22
21
package com .spotify .github .v3 .clients ;
23
22
24
23
import static com .google .common .io .Resources .getResource ;
31
30
import static org .hamcrest .core .Is .is ;
32
31
import static org .mockito .ArgumentMatchers .any ;
33
32
import static org .mockito .ArgumentMatchers .eq ;
34
- import static org .mockito .Mockito .mock ;
35
- import static org .mockito .Mockito .when ;
33
+ import static org .mockito .Mockito .*;
36
34
37
35
import com .google .common .io .Resources ;
38
36
import com .spotify .github .jackson .Json ;
57
55
import org .powermock .modules .junit4 .PowerMockRunner ;
58
56
59
57
@ RunWith (PowerMockRunner .class )
60
- @ PrepareForTest ({ Headers .class , ResponseBody .class , Response .class })
58
+ @ PrepareForTest ({Headers .class , ResponseBody .class , Response .class })
61
59
public class TeamClientTest {
62
60
63
61
private GitHubClient github ;
@@ -113,42 +111,43 @@ public void deleteTeam() throws Exception {
113
111
@ Test
114
112
public void createTeam () throws Exception {
115
113
final TeamCreate teamCreateRequest =
116
- json .fromJson (
117
- getFixture ("teams_request.json" ),
118
- TeamCreate .class );
114
+ json .fromJson (getFixture ("teams_request.json" ), TeamCreate .class );
119
115
120
- final CompletableFuture <Team > fixtureResponse = completedFuture (json .fromJson (
121
- getFixture ("team_get.json" ),
122
- Team .class ));
116
+ final CompletableFuture <Team > fixtureResponse =
117
+ completedFuture (json .fromJson (getFixture ("team_get.json" ), Team .class ));
123
118
when (github .post (any (), any (), eq (Team .class ))).thenReturn (fixtureResponse );
124
119
final CompletableFuture <Team > actualResponse = teamClient .createTeam (teamCreateRequest );
125
120
126
121
assertThat (actualResponse .get ().name (), is ("Justice League" ));
122
+ verify (github , times (1 ))
123
+ .post (eq ("/orgs/github/teams" ), eq ("{\" name\" :\" Justice League\" }" ), eq (Team .class ));
127
124
}
128
125
129
126
@ Test
130
127
public void updateTeam () throws Exception {
131
128
final TeamUpdate teamUpdateRequest =
132
- json .fromJson (
133
- getFixture ("teams_patch.json" ),
134
- TeamUpdate .class );
129
+ json .fromJson (getFixture ("teams_patch.json" ), TeamUpdate .class );
135
130
136
- final CompletableFuture <Team > fixtureResponse = completedFuture (json .fromJson (
137
- getFixture ("teams_patch_response.json" ),
138
- Team .class ));
131
+ final CompletableFuture <Team > fixtureResponse =
132
+ completedFuture (json .fromJson (getFixture ("teams_patch_response.json" ), Team .class ));
139
133
when (github .patch (any (), any (), eq (Team .class ))).thenReturn (fixtureResponse );
140
- final CompletableFuture <Team > actualResponse = teamClient .updateTeam (teamUpdateRequest , "justice-league" );
134
+ final CompletableFuture <Team > actualResponse =
135
+ teamClient .updateTeam (teamUpdateRequest , "justice-league" );
141
136
142
137
assertThat (actualResponse .get ().name (), is ("Justice League2" ));
138
+ verify (github , times (1 ))
139
+ .patch (eq ("/orgs/github/teams/justice-league" ), eq ("{\" name\" :\" Justice League2\" }" ), eq (Team .class ));
143
140
}
144
141
145
142
@ Test
146
143
public void getMembership () throws Exception {
147
144
final CompletableFuture <Membership > fixture =
148
145
completedFuture (json .fromJson (getFixture ("membership.json" ), Membership .class ));
149
- when (github .request ("/orgs/github/teams/1/memberships/octocat" , Membership .class )).thenReturn (fixture );
146
+ when (github .request ("/orgs/github/teams/1/memberships/octocat" , Membership .class ))
147
+ .thenReturn (fixture );
150
148
final Membership membership = teamClient .getMembership ("1" , "octocat" ).get ();
151
- assertThat (membership .url ().toString (), is ("https://api.github.com/teams/1/memberships/octocat" ));
149
+ assertThat (
150
+ membership .url ().toString (), is ("https://api.github.com/teams/1/memberships/octocat" ));
152
151
assertThat (membership .role (), is ("maintainer" ));
153
152
assertThat (membership .state (), is ("active" ));
154
153
}
@@ -167,15 +166,14 @@ public void listTeamMembers() throws Exception {
167
166
@ Test
168
167
public void updateMembership () throws Exception {
169
168
final MembershipCreate membershipCreateRequest =
170
- json .fromJson (
171
- getFixture ("membership_update.json" ),
172
- MembershipCreate .class );
169
+ json .fromJson (getFixture ("membership_update.json" ), MembershipCreate .class );
173
170
174
- final CompletableFuture <Membership > fixtureResponse = completedFuture ( json . fromJson (
175
- getFixture ( "membership_update_response.json" ),
176
- Membership .class ));
171
+ final CompletableFuture <Membership > fixtureResponse =
172
+ completedFuture (
173
+ json . fromJson ( getFixture ( "membership_update_response.json" ), Membership .class ));
177
174
when (github .put (any (), any (), eq (Membership .class ))).thenReturn (fixtureResponse );
178
- final CompletableFuture <Membership > actualResponse = teamClient .updateMembership (membershipCreateRequest , "1" , "octocat" );
175
+ final CompletableFuture <Membership > actualResponse =
176
+ teamClient .updateMembership (membershipCreateRequest , "1" , "octocat" );
179
177
180
178
assertThat (actualResponse .get ().role (), is ("member" ));
181
179
}
@@ -194,9 +192,12 @@ public void deleteMembership() throws Exception {
194
192
@ Test
195
193
public void listPendingTeamInvitations () throws Exception {
196
194
final CompletableFuture <List <TeamInvitation >> fixture =
197
- completedFuture (json .fromJson (getFixture ("list_team_invitations.json" ), LIST_PENDING_TEAM_INVITATIONS ));
198
- when (github .request ("/orgs/github/teams/1/invitations" , LIST_PENDING_TEAM_INVITATIONS )).thenReturn (fixture );
199
- final List <TeamInvitation > pendingInvitations = teamClient .listPendingTeamInvitations ("1" ).get ();
195
+ completedFuture (
196
+ json .fromJson (getFixture ("list_team_invitations.json" ), LIST_PENDING_TEAM_INVITATIONS ));
197
+ when (github .request ("/orgs/github/teams/1/invitations" , LIST_PENDING_TEAM_INVITATIONS ))
198
+ .thenReturn (fixture );
199
+ final List <TeamInvitation > pendingInvitations =
200
+ teamClient .listPendingTeamInvitations ("1" ).get ();
200
201
assertThat (pendingInvitations .get (0 ).login (), is ("octocat" ));
201
202
assertThat (pendingInvitations .get (1 ).id (), is (2 ));
202
203
assertThat (pendingInvitations .size (), is (2 ));
0 commit comments