Skip to content

Commit b5e8e83

Browse files
authored
Merge pull request #673 from gitlab4j/pr-662-add-tests
test: Add tests for EmailOnPushService
2 parents d155674 + 2b8bdcf commit b5e8e83

File tree

3 files changed

+418
-302
lines changed

3 files changed

+418
-302
lines changed

src/main/java/org/gitlab4j/api/services/EmailOnPushService.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public EmailOnPushService withTagPushEvents(Boolean pushEvents) {
3232

3333
@JsonIgnore
3434
public String getRecipients() {
35-
return ((String)getProperty(RECIPIENT_PROP));
35+
return (getProperty(RECIPIENT_PROP));
3636
}
3737
public void setRecipients(String recipients) {
3838
setProperty(RECIPIENT_PROP, recipients);
@@ -45,7 +45,7 @@ public EmailOnPushService withRecipients(String recipients) {
4545

4646
@JsonIgnore
4747
public Boolean getDisableDiffs() {
48-
return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP,"false"));
48+
return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP, false));
4949
}
5050
public void setDisableDiffs(Boolean disableDiffs) {
5151
setProperty(DISABLE_DIFFS_PROP, disableDiffs);
@@ -54,10 +54,10 @@ public EmailOnPushService withDisableDiffs(Boolean disableDiffs) {
5454
setDisableDiffs(disableDiffs);
5555
return this;
5656
}
57-
57+
5858
@JsonIgnore
5959
public Boolean getSendFromCommitterEmail() {
60-
return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL_PROP,"false"));
60+
return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL_PROP, false));
6161
}
6262
public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
6363
setProperty(SEND_FROM_COMMITTER_EMAIL_PROP, sendFromCommitterEmail);
@@ -68,16 +68,20 @@ public EmailOnPushService withSendFromCommitterEmail(Boolean sendFromCommitterEm
6868
}
6969

7070
@JsonIgnore
71-
public String getBranchesToBeNotified() {
72-
return ((String)getProperty(BRANCHES_TO_BE_NOTIFIED_PROP));
71+
public BranchesToBeNotified getBranchesToBeNotified() {
72+
String branchesToBeNotified = getProperty(BRANCHES_TO_BE_NOTIFIED_PROP);
73+
74+
if (branchesToBeNotified == null || branchesToBeNotified.isEmpty()) {
75+
return null;
76+
}
77+
78+
return (BranchesToBeNotified.valueOf(branchesToBeNotified.toUpperCase()));
7379
}
74-
public void setBranchesToBeNotified(String branchesToBeNotified) {
75-
setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified);
80+
public void setBranchesToBeNotified(BranchesToBeNotified branchesToBeNotified) {
81+
setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified.toString());
7682
}
77-
public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) {
83+
public EmailOnPushService withBranchesToBeNotified(BranchesToBeNotified branchesToBeNotified) {
7884
setBranchesToBeNotified(branchesToBeNotified);
7985
return this;
8086
}
81-
82-
8387
}

src/main/java/org/gitlab4j/api/services/NotificationService.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ public abstract class NotificationService {
3434

3535
private Integer id;
3636
private String title;
37+
private String slug;
3738
private Date createdAt;
3839
private Date updatedAt;
3940
private Boolean active;
4041

42+
private Boolean commitEvents;
4143
private Boolean pushEvents;
4244
private Boolean issuesEvents;
4345
private Boolean confidentialIssuesEvents;
@@ -61,6 +63,14 @@ public void setId(Integer id) {
6163
this.id = id;
6264
}
6365

66+
public String getSlug() {
67+
return slug;
68+
}
69+
70+
public void setSlug(String slug) {
71+
this.slug = slug;
72+
}
73+
6474
public String getTitle() {
6575
return title;
6676
}
@@ -97,6 +107,19 @@ public void setActive(Boolean active) {
97107
// The following methods can be used to configure the notification service
98108
// *******************************************************************************
99109

110+
public Boolean getCommitEvents() {
111+
return commitEvents;
112+
}
113+
114+
public void setCommitEvents(Boolean commitEvents) {
115+
this.commitEvents = commitEvents;
116+
}
117+
118+
protected <T> T withCommitEvents(Boolean commitEvents, T derivedInstance) {
119+
this.commitEvents = commitEvents;
120+
return (derivedInstance);
121+
}
122+
100123
public Boolean getPushEvents() {
101124
return pushEvents;
102125
}
@@ -237,7 +260,7 @@ public void setProperties(Map<String, Object> properties) {
237260

238261
@JsonIgnore
239262
protected String getProperty(String prop) {
240-
return ((String) getProperty(prop, ""));
263+
return (getProperty(prop, ""));
241264
}
242265

243266
@JsonIgnore
@@ -270,4 +293,13 @@ protected void setProperty(String prop, Object value) {
270293
public String toString() {
271294
return (JacksonJson.toJsonString(this));
272295
}
296+
297+
public enum BranchesToBeNotified {
298+
ALL, DEFAULT, PROTECTED, DEFAULT_AND_PROTECTED;
299+
@Override
300+
public String toString() {
301+
return (name().toLowerCase());
302+
}
303+
}
304+
273305
}

0 commit comments

Comments
 (0)