1818 * -/-/-
1919 */
2020
21-
2221package com .spotify .github .v3 .clients ;
2322
2423import static com .google .common .io .Resources .getResource ;
3130import static org .hamcrest .core .Is .is ;
3231import static org .mockito .ArgumentMatchers .any ;
3332import 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 .*;
3634
3735import com .google .common .io .Resources ;
3836import com .spotify .github .jackson .Json ;
5755import org .powermock .modules .junit4 .PowerMockRunner ;
5856
5957@ RunWith (PowerMockRunner .class )
60- @ PrepareForTest ({ Headers .class , ResponseBody .class , Response .class })
58+ @ PrepareForTest ({Headers .class , ResponseBody .class , Response .class })
6159public class TeamClientTest {
6260
6361 private GitHubClient github ;
@@ -113,42 +111,43 @@ public void deleteTeam() throws Exception {
113111 @ Test
114112 public void createTeam () throws Exception {
115113 final TeamCreate teamCreateRequest =
116- json .fromJson (
117- getFixture ("teams_request.json" ),
118- TeamCreate .class );
114+ json .fromJson (getFixture ("teams_request.json" ), TeamCreate .class );
119115
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 ));
123118 when (github .post (any (), any (), eq (Team .class ))).thenReturn (fixtureResponse );
124119 final CompletableFuture <Team > actualResponse = teamClient .createTeam (teamCreateRequest );
125120
126121 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 ));
127124 }
128125
129126 @ Test
130127 public void updateTeam () throws Exception {
131128 final TeamUpdate teamUpdateRequest =
132- json .fromJson (
133- getFixture ("teams_patch.json" ),
134- TeamUpdate .class );
129+ json .fromJson (getFixture ("teams_patch.json" ), TeamUpdate .class );
135130
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 ));
139133 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" );
141136
142137 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 ));
143140 }
144141
145142 @ Test
146143 public void getMembership () throws Exception {
147144 final CompletableFuture <Membership > fixture =
148145 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 );
150148 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" ));
152151 assertThat (membership .role (), is ("maintainer" ));
153152 assertThat (membership .state (), is ("active" ));
154153 }
@@ -167,15 +166,14 @@ public void listTeamMembers() throws Exception {
167166 @ Test
168167 public void updateMembership () throws Exception {
169168 final MembershipCreate membershipCreateRequest =
170- json .fromJson (
171- getFixture ("membership_update.json" ),
172- MembershipCreate .class );
169+ json .fromJson (getFixture ("membership_update.json" ), MembershipCreate .class );
173170
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 ));
177174 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" );
179177
180178 assertThat (actualResponse .get ().role (), is ("member" ));
181179 }
@@ -194,9 +192,12 @@ public void deleteMembership() throws Exception {
194192 @ Test
195193 public void listPendingTeamInvitations () throws Exception {
196194 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 ();
200201 assertThat (pendingInvitations .get (0 ).login (), is ("octocat" ));
201202 assertThat (pendingInvitations .get (1 ).id (), is (2 ));
202203 assertThat (pendingInvitations .size (), is (2 ));
0 commit comments