Skip to content

Commit 284b11e

Browse files
committed
Fixed Label entity and added unit test for same.
1 parent cdf53b7 commit 284b11e

File tree

4 files changed

+78
-23
lines changed

4 files changed

+78
-23
lines changed

src/main/java/org/gitlab4j/api/LabelsApi.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@
88
import org.gitlab4j.api.models.Label;
99

1010
public class LabelsApi extends AbstractApi {
11+
1112
public LabelsApi(GitLabApi gitLabApi) {
1213
super(gitLabApi);
1314
}
1415

1516
public List<Label> getLabels(Integer projectId) throws GitLabApiException {
16-
17-
if (projectId == null) {
18-
throw new RuntimeException("projectId cannot be null");
19-
}
20-
21-
Response response = get(javax.ws.rs.core.Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "labels");
22-
return (response.readEntity(new GenericType<List<Label>>() {
23-
}));
17+
return (getLabels(projectId, 1, getDefaultPerPage()));
2418
}
2519

2620
public List<Label> getLabels(Integer projectId, int page, int perPage) throws GitLabApiException {
@@ -30,8 +24,7 @@ public List<Label> getLabels(Integer projectId, int page, int perPage) throws Gi
3024
}
3125

3226
Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "labels");
33-
return (response.readEntity(new GenericType<List<Label>>() {
34-
}));
27+
return (response.readEntity(new GenericType<List<Label>>() {}));
3528
}
3629

3730
public Label createLabel(Integer projectId, String name, String color, String description) throws GitLabApiException {

src/main/java/org/gitlab4j/api/models/Label.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@
77
@XmlRootElement
88
@XmlAccessorType(XmlAccessType.FIELD)
99
public class Label {
10-
private Integer id;
1110

11+
private Integer id;
1212
private String name;
13-
1413
private String color;
15-
1614
private String description;
17-
1815
private Integer openIssuesCount;
19-
2016
private Integer closedIssuesCount;
21-
22-
private Integer openMergeRequestCount;
23-
17+
private Integer openMergeRequestsCount;
2418
private boolean subscribed;
25-
2619
private Integer priority;
2720

2821
public Integer getId() {
@@ -73,12 +66,12 @@ public void setClosedIssuesCount(Integer closedIssuesCount) {
7366
this.closedIssuesCount = closedIssuesCount;
7467
}
7568

76-
public Integer getOpenMergeRequestCount() {
77-
return openMergeRequestCount;
69+
public Integer getOpenMergeRequestsCount() {
70+
return openMergeRequestsCount;
7871
}
7972

80-
public void setOpenMergeRequestCount(Integer openMergeRequestCount) {
81-
this.openMergeRequestCount = openMergeRequestCount;
73+
public void setOpenMergeRequestsCount(Integer openMergeRequestsCount) {
74+
this.openMergeRequestsCount = openMergeRequestsCount;
8275
}
8376

8477
public boolean isSubscribed() {

src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.gitlab4j.api.models.Issue;
4444
import org.gitlab4j.api.models.Job;
4545
import org.gitlab4j.api.models.Key;
46+
import org.gitlab4j.api.models.Label;
4647
import org.gitlab4j.api.models.Member;
4748
import org.gitlab4j.api.models.MergeRequest;
4849
import org.gitlab4j.api.models.Milestone;
@@ -417,6 +418,21 @@ public void testImpersonationToken() {
417418
}
418419
}
419420

421+
@Test
422+
public void testLabels() {
423+
424+
try {
425+
426+
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("labels.json"));
427+
ObjectMapper objectMapper = jacksonJson.getContext(null);
428+
List<Label> labels = objectMapper.readValue(reader, new TypeReference<List<Label>>() {});
429+
assertTrue(compareJson(labels, "labels"));
430+
431+
} catch (Exception e) {
432+
e.printStackTrace();
433+
}
434+
}
435+
420436
private <T> T makeFakeApiCall(Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
421437

422438
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(file + ".json"));
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[
2+
{
3+
"id" : 1,
4+
"name" : "bug",
5+
"color" : "#d9534f",
6+
"description": "Bug reported by user",
7+
"open_issues_count": 1,
8+
"closed_issues_count": 0,
9+
"open_merge_requests_count": 1,
10+
"subscribed": false,
11+
"priority": 10
12+
},
13+
{
14+
"id" : 4,
15+
"color" : "#d9534f",
16+
"name" : "confirmed",
17+
"description": "Confirmed issue",
18+
"open_issues_count": 2,
19+
"closed_issues_count": 5,
20+
"open_merge_requests_count": 0,
21+
"subscribed": false
22+
},
23+
{
24+
"id" : 7,
25+
"name" : "critical",
26+
"color" : "#d9534f",
27+
"description": "Critical issue. Need fix ASAP",
28+
"open_issues_count": 1,
29+
"closed_issues_count": 3,
30+
"open_merge_requests_count": 1,
31+
"subscribed": false
32+
},
33+
{
34+
"id" : 8,
35+
"name" : "documentation",
36+
"color" : "#f0ad4e",
37+
"description": "Issue about documentation",
38+
"open_issues_count": 1,
39+
"closed_issues_count": 0,
40+
"open_merge_requests_count": 2,
41+
"subscribed": false
42+
},
43+
{
44+
"id" : 9,
45+
"color" : "#5cb85c",
46+
"name" : "enhancement",
47+
"description": "Enhancement proposal",
48+
"open_issues_count": 1,
49+
"closed_issues_count": 0,
50+
"open_merge_requests_count": 1,
51+
"subscribed": true
52+
}
53+
]

0 commit comments

Comments
 (0)