Skip to content

Commit

Permalink
Additional test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 11, 2021
1 parent cfcf81a commit 796214c
Show file tree
Hide file tree
Showing 61 changed files with 1,845 additions and 824 deletions.
2 changes: 0 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ private static class GHAppInstallationRepositoryResult extends SearchResult<GHRe

@Override
GHRepository[] getItems(GitHub root) {
for (GHRepository item : repositories) {
}
return repositories;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/kohsuke/github/GHArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private String getApiRoute() {
}

GHArtifact wrapUp(GHRepository owner) {
this.owner = owner;
this.owner = owner;
return this;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/kohsuke/github/GHContentSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ private static class ContentSearchResult extends SearchResult<GHContent> {

@Override
GHContent[] getItems(GitHub root) {
for (GHContent item : items) {
}
return items;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ private Context(GitHub root) {
*/
public List<GHHook> getHooks() throws IOException {

GHHook[] hookArray = root().createRequest().withUrlPath(collection()).fetch(collectionClass()); // jdk/eclipse
// bug
// jdk/eclipse bug
GHHook[] hookArray = root().createRequest().withUrlPath(collection()).fetch(collectionClass());
// requires this
// to be on separate line
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(hookArray));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void lock() throws IOException {
* the io exception
*/
public void unlock() throws IOException {
root().createRequest().method("PUT").withUrlPath(getApiRoute() + "/lock").send();
root().createRequest().method("DELETE").withUrlPath(getApiRoute() + "/lock").send();
}

/**
Expand Down
43 changes: 40 additions & 3 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -138,9 +139,13 @@ public void testIssueWithNoComment() throws IOException {
List<GHIssueComment> v = i.getComments();
// System.out.println(v);
assertThat(v, is(empty()));
}

i = repository.getIssue(3);
v = i.getComments();
@Test
public void testIssueWithComment() throws IOException {
GHRepository repository = gitHub.getRepository("kohsuke/test");
GHIssue i = repository.getIssue(3);
List<GHIssueComment> v = i.getComments();
// System.out.println(v);
assertThat(v.size(), equalTo(3));
assertThat(v.get(0).getHtmlUrl().toString(),
Expand All @@ -160,10 +165,30 @@ public void testIssueWithNoComment() throws IOException {
assertThat(v.get(1).getUser().getLogin(), equalTo("kohsuke"));
List<GHReaction> reactions = v.get(1).listReactions().toList();
assertThat(reactions.size(), equalTo(3));
assertThat(reactions.stream().map(item -> item.getContent()).collect(Collectors.toList()),
containsInAnyOrder(ReactionContent.EYES, ReactionContent.HOORAY, ReactionContent.ROCKET));

// TODO: Add comment CRUD test
// TODO: Add reactions CRUD test

GHReaction reaction = null;
try {
reaction = v.get(1).createReaction(ReactionContent.CONFUSED);
v = i.getComments();
reactions = v.get(1).listReactions().toList();
assertThat(reactions.stream().map(item -> item.getContent()).collect(Collectors.toList()),
containsInAnyOrder(ReactionContent.CONFUSED, ReactionContent.EYES, ReactionContent.HOORAY, ReactionContent.ROCKET));

reaction.delete();
reaction = null;
v = i.getComments();
reactions = v.get(1).listReactions().toList();
assertThat(reactions.stream().map(item -> item.getContent()).collect(Collectors.toList()),
containsInAnyOrder(ReactionContent.EYES, ReactionContent.HOORAY, ReactionContent.ROCKET));
} finally {
if (reaction != null) {
reaction.delete();
}
}
}

@Test
Expand All @@ -179,6 +204,17 @@ public void testCreateIssue() throws IOException {
.milestone(milestone)
.create();
assertThat(o, notNullValue());
assertThat(o.getBody(), equalTo("this is body"));

// test locking
assertThat(o.isLocked(), is(false));
o.lock();
o = repository.getIssue(o.getNumber());
assertThat(o.isLocked(), is(true));
o.unlock();
o = repository.getIssue(o.getNumber());
assertThat(o.isLocked(), is(false));

o.close();
}

Expand Down Expand Up @@ -771,6 +807,7 @@ public void testCommitStatus() throws Exception {
// System.out.println(state);
assertThat(state.getDescription(), equalTo("testing!"));
assertThat(state.getTargetUrl(), equalTo("http://kohsuke.org/"));
assertThat(state.getCreator().getLogin(), equalTo("kohsuke"));
}

@Test
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ public void listCommitCommentsSomeComments() throws IOException {
assertThat("Comment text found",
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
containsInAnyOrder("comment 1", "comment 2"));

}

@Test // Issue #261
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": 212423833,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTI0MjM4MzM=",
"id": 405314245,
"node_id": "MDEwOlJlcG9zaXRvcnk0MDUzMTQyNDU=",
"name": "github-api-test",
"full_name": "hub4j-test-org/github-api-test",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
Expand All @@ -25,7 +25,7 @@
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/github-api-test",
"description": "A test repository for testing the github-api project",
"description": "A test repository for testing the github-api project: github-api-test",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/forks",
Expand Down Expand Up @@ -64,9 +64,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments",
"created_at": "2019-10-02T19:25:19Z",
"updated_at": "2019-10-02T19:25:34Z",
"pushed_at": "2019-10-02T19:25:20Z",
"created_at": "2021-09-11T07:32:33Z",
"updated_at": "2021-09-11T07:32:36Z",
"pushed_at": "2021-09-11T07:32:34Z",
"git_url": "git://github.com/hub4j-test-org/github-api-test.git",
"ssh_url": "[email protected]:hub4j-test-org/github-api-test.git",
"clone_url": "https://github.com/hub4j-test-org/github-api-test.git",
Expand All @@ -93,17 +93,22 @@
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
Expand All @@ -120,5 +125,5 @@
"site_admin": false
},
"network_count": 0,
"subscribers_count": 2
"subscribers_count": 14
}

This file was deleted.

Loading

0 comments on commit 796214c

Please sign in to comment.