Skip to content

Commit 49947db

Browse files
authored
fix: Fix nil values and int warning for parent team (#146)
* fix: Fix nil values and int warning for parent team * fix: Ignore null values --------- Co-authored-by: Abhishek Jain <[email protected]>
1 parent 6f0e90a commit 49947db

File tree

4 files changed

+65
-60
lines changed

4 files changed

+65
-60
lines changed

.sdkmanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Enable auto-env through the sdkman_auto_env config
2+
# Add key=value pairs of SDKs to use below
3+
java=11.0.20-amzn
4+
maven=3.8.6

src/main/java/com/spotify/github/v3/orgs/requests/TeamCreate.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,61 @@
1919
*/
2020
package com.spotify.github.v3.orgs.requests;
2121

22+
import com.fasterxml.jackson.annotation.JsonInclude;
23+
import com.fasterxml.jackson.annotation.JsonProperty;
2224
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2325
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2426
import com.spotify.github.GithubStyle;
2527
import java.util.List;
2628
import java.util.Optional;
27-
import javax.annotation.Nullable;
2829
import org.immutables.value.Value;
2930

3031
/** Request to create a team within a given organisation */
3132
@Value.Immutable
3233
@GithubStyle
3334
@JsonSerialize(as = ImmutableTeamCreate.class)
3435
@JsonDeserialize(as = ImmutableTeamCreate.class)
36+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3537
public interface TeamCreate {
3638

3739
/** The name of the team. */
38-
@Nullable
3940
String name();
4041

4142
/** The description of the team. */
4243
Optional<String> description();
4344

4445
/**
45-
* The level of privacy this team should have.
46-
* For a non-nested team:
47-
* secret - only visible to organization owners and members of this team.
48-
* closed - visible to all members of this organization.
49-
* Default: secret
50-
* For a parent or child team:
51-
* closed - visible to all members of this organization.
52-
* Default for child team: closed
53-
* Can be one of: secret, closed
46+
* The level of privacy this team should have. For a non-nested team: secret - only visible to
47+
* organization owners and members of this team. closed - visible to all members of this
48+
* organization. Default: secret For a parent or child team: closed - visible to all members of
49+
* this organization. Default for child team: closed Can be one of: secret, closed
5450
*/
5551
Optional<String> privacy();
5652

5753
/**
5854
* The notification setting the team has chosen. The options are:
59-
* notifications_enabled - team members receive notifications when the team is @mentioned.
60-
* notifications_disabled - no one receives notifications.
61-
* Default: notifications_enabled
62-
* Can be one of: notifications_enabled, notifications_disabled
55+
*
56+
* <p>notifications_enabled - team members receive notifications when the team is @mentioned.
57+
*
58+
* <p>notifications_disabled - no one receives notifications.
59+
*
60+
* <p>Default: notifications_enabled
61+
*
62+
* <p>Can be one of: notifications_enabled, notifications_disabled
6363
*/
64-
@SuppressWarnings("checkstyle:methodname")
65-
Optional<String> notification_setting();
64+
@JsonProperty("notification_setting")
65+
Optional<String> notificationSetting();
6666

67-
/**
68-
* List GitHub IDs for organization members who will
69-
* become team maintainers.
70-
*/
67+
/** List GitHub IDs for organization members who will become team maintainers. */
7168
Optional<List<String>> maintainers();
7269

73-
/** The full name (e.g., "organization-name/repository-name")
74-
* of repositories to add the team to.
70+
/**
71+
* The full name (e.g., "organization-name/repository-name") of repositories to add the team to.
7572
*/
76-
@SuppressWarnings("checkstyle:methodname")
77-
Optional<List<String>> repo_names();
73+
@JsonProperty("repo_names")
74+
Optional<List<String>> repoNames();
7875

7976
/** The ID of a team to set as the parent team. */
80-
@SuppressWarnings("checkstyle:methodname")
81-
Optional<String> parent_team_id();
77+
@JsonProperty("parent_team_id")
78+
Optional<Integer> parentTeamId();
8279
}

src/main/java/com/spotify/github/v3/orgs/requests/TeamUpdate.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package com.spotify.github.v3.orgs.requests;
2121

22+
import com.fasterxml.jackson.annotation.JsonInclude;
23+
import com.fasterxml.jackson.annotation.JsonProperty;
2224
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2325
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2426
import com.spotify.github.GithubStyle;
@@ -31,6 +33,7 @@
3133
@GithubStyle
3234
@JsonSerialize(as = ImmutableTeamUpdate.class)
3335
@JsonDeserialize(as = ImmutableTeamUpdate.class)
36+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3437
public interface TeamUpdate {
3538

3639
/** The name of the team. */
@@ -60,11 +63,11 @@ public interface TeamUpdate {
6063
* Default: notifications_enabled
6164
* Can be one of: notifications_enabled, notifications_disabled
6265
*/
63-
@SuppressWarnings("checkstyle:methodname")
64-
Optional<String> notification_setting();
66+
@JsonProperty("notification_setting")
67+
Optional<String> notificationSetting();
6568

6669

6770
/** The ID of a team to set as the parent team. */
68-
@SuppressWarnings("checkstyle:methodname")
69-
Optional<String> parent_team_id();
71+
@JsonProperty("parent_team_id")
72+
Optional<Integer> parentTeamId();
7073
}

src/test/java/com/spotify/github/v3/clients/TeamClientTest.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* -/-/-
1919
*/
2020

21-
2221
package com.spotify.github.v3.clients;
2322

2423
import static com.google.common.io.Resources.getResource;
@@ -31,8 +30,7 @@
3130
import static org.hamcrest.core.Is.is;
3231
import static org.mockito.ArgumentMatchers.any;
3332
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.*;
3634

3735
import com.google.common.io.Resources;
3836
import com.spotify.github.jackson.Json;
@@ -57,7 +55,7 @@
5755
import 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})
6159
public 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

Comments
 (0)