Skip to content

Commit 5a6a29c

Browse files
committed
Add array and iterator tests
1 parent e7e3be6 commit 5a6a29c

101 files changed

Lines changed: 34811 additions & 31 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -155,40 +155,19 @@ private GHRepository getTestRepository() throws IOException {
155155
return getTempRepository(GITHUB_API_TEST_REPO);
156156
}
157157

158-
@Ignore("Needs to be rewritten to not create new issues just to check that they can be found.")
159158
@Test
160159
public void testListIssues() throws IOException {
161-
GHUser u = getUser();
162-
GHRepository repository = getTestRepository();
160+
Iterable<GHIssue> closedIssues = gitHub.getOrganization("github-api")
161+
.getRepository("github-api")
162+
.listIssues(GHIssueState.CLOSED);
163163

164-
GHMilestone milestone = repository.createMilestone(System.currentTimeMillis() + "", "Test Milestone");
165-
milestone.close();
166-
GHIssue unhomed = null;
167-
GHIssue homed = null;
168-
try {
169-
unhomed = repository.createIssue("testing")
170-
.body("this is body")
171-
.assignee(u)
172-
.label("bug")
173-
.label("question")
174-
.create();
175-
assertEquals(unhomed.getNumber(), repository.getIssues(GHIssueState.OPEN, null).get(0).getNumber());
176-
homed = repository.createIssue("testing")
177-
.body("this is body")
178-
.assignee(u)
179-
.label("bug")
180-
.label("question")
181-
.milestone(milestone)
182-
.create();
183-
assertEquals(homed.getNumber(), repository.getIssues(GHIssueState.OPEN, milestone).get(0).getNumber());
184-
} finally {
185-
if (unhomed != null) {
186-
unhomed.close();
187-
}
188-
if (homed != null) {
189-
homed.close();
190-
}
164+
int x = 0;
165+
for (GHIssue issue : closedIssues) {
166+
assertNotNull(issue);
167+
x++;
191168
}
169+
170+
assertTrue(x > 150);
192171
}
193172

194173
@Test

src/test/java/org/kohsuke/github/GHRepositoryTest.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import static org.hamcrest.Matchers.*;
1414
import static org.hamcrest.core.IsInstanceOf.instanceOf;
15-
import static org.junit.Assert.*;
1615

1716
/**
1817
* @author Liam Newman
@@ -344,4 +343,84 @@ public void getPostCommitHooks() throws Exception {
344343
assertThat(postcommitHooks.size(), equalTo(0));
345344
}
346345

346+
public void getRefs() throws Exception {
347+
GHRepository repo = getTempRepository();
348+
GHRef[] refs = repo.getRefs();
349+
assertThat(refs, notNullValue());
350+
assertThat(refs.length, equalTo(1));
351+
assertThat(refs[0].getRef(), equalTo("refs/heads/master"));
352+
}
353+
354+
@Test
355+
public void getRefsHeads() throws Exception {
356+
GHRepository repo = getTempRepository();
357+
GHRef[] refs = repo.getRefs("heads");
358+
assertThat(refs, notNullValue());
359+
assertThat(refs.length, equalTo(1));
360+
assertThat(refs[0].getRef(), equalTo("refs/heads/master"));
361+
}
362+
363+
@Test
364+
public void getRefsEmptyTags() throws Exception {
365+
GHRepository repo = getTempRepository();
366+
try {
367+
repo.getRefs("tags");
368+
fail();
369+
} catch (Exception e) {
370+
assertThat(e, instanceOf(GHFileNotFoundException.class));
371+
assertThat(e.getMessage(),
372+
containsString(
373+
"{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/git/refs/#get-a-reference\"}"));
374+
assertThat(e.getCause(), instanceOf(FileNotFoundException.class));
375+
}
376+
}
377+
378+
@Test
379+
public void listRefs() throws Exception {
380+
GHRepository repo = getTempRepository();
381+
List<GHRef> refs = repo.listRefs().asList();
382+
assertThat(refs, notNullValue());
383+
assertThat(refs.size(), equalTo(1));
384+
assertThat(refs.get(0).getRef(), equalTo("refs/heads/master"));
385+
}
386+
387+
@Test
388+
public void listRefsHeads() throws Exception {
389+
GHRepository repo = getTempRepository();
390+
List<GHRef> refs = repo.listRefs("heads").asList();
391+
assertThat(refs, notNullValue());
392+
assertThat(refs.size(), equalTo(1));
393+
assertThat(refs.get(0).getRef(), equalTo("refs/heads/master"));
394+
}
395+
396+
@Test
397+
public void listRefsEmptyTags() throws Exception {
398+
try {
399+
GHRepository repo = getTempRepository();
400+
repo.listRefs("tags").asList();
401+
fail();
402+
} catch (Exception e) {
403+
assertThat(e, instanceOf(GHException.class));
404+
assertThat(e.getMessage(), containsString("Failed to retrieve "));
405+
assertThat(e.getMessage(),
406+
containsString("/repos/github-api-test-org/temp-listRefsEmptyTags/git/refs/tags"));
407+
assertThat(e.getCause(), instanceOf(GHFileNotFoundException.class));
408+
}
409+
}
410+
411+
@Test
412+
public void listTagsEmpty() throws Exception {
413+
GHRepository repo = getTempRepository();
414+
List<GHTag> refs = repo.listTags().asList();
415+
assertThat(refs, notNullValue());
416+
assertThat(refs.size(), equalTo(0));
417+
}
418+
419+
@Test
420+
public void listTags() throws Exception {
421+
GHRepository repo = getRepository();
422+
List<GHTag> refs = repo.listTags().withPageSize(33).asList();
423+
assertThat(refs, notNullValue());
424+
assertThat(refs.size(), greaterThan(90));
425+
}
347426
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "github-api",
3+
"id": 54909825,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
5+
"url": "https://api.github.com/orgs/github-api",
6+
"repos_url": "https://api.github.com/orgs/github-api/repos",
7+
"events_url": "https://api.github.com/orgs/github-api/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api/issues",
10+
"members_url": "https://api.github.com/orgs/github-api/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 1,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api",
22+
"created_at": "2019-09-04T18:12:34Z",
23+
"updated_at": "2019-09-04T18:12:34Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 17575,
29+
"collaborators": 0,
30+
"billing_email": "bitwiseman@gmail.com",
31+
"default_repository_permission": "read",
32+
"members_can_create_repositories": true,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 2,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"id": 617210,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=",
4+
"name": "github-api",
5+
"full_name": "github-api/github-api",
6+
"private": false,
7+
"owner": {
8+
"login": "github-api",
9+
"id": 54909825,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
11+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/github-api",
14+
"html_url": "https://github.com/github-api",
15+
"followers_url": "https://api.github.com/users/github-api/followers",
16+
"following_url": "https://api.github.com/users/github-api/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/github-api/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/github-api/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/github-api/subscriptions",
20+
"organizations_url": "https://api.github.com/users/github-api/orgs",
21+
"repos_url": "https://api.github.com/users/github-api/repos",
22+
"events_url": "https://api.github.com/users/github-api/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/github-api/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/github-api/github-api",
28+
"description": "Java API for GitHub",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/github-api/github-api",
31+
"forks_url": "https://api.github.com/repos/github-api/github-api/forks",
32+
"keys_url": "https://api.github.com/repos/github-api/github-api/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/github-api/github-api/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/github-api/github-api/teams",
35+
"hooks_url": "https://api.github.com/repos/github-api/github-api/hooks",
36+
"issue_events_url": "https://api.github.com/repos/github-api/github-api/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/github-api/github-api/events",
38+
"assignees_url": "https://api.github.com/repos/github-api/github-api/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/github-api/github-api/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/github-api/github-api/tags",
41+
"blobs_url": "https://api.github.com/repos/github-api/github-api/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/github-api/github-api/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/github-api/github-api/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/github-api/github-api/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/github-api/github-api/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/github-api/github-api/languages",
47+
"stargazers_url": "https://api.github.com/repos/github-api/github-api/stargazers",
48+
"contributors_url": "https://api.github.com/repos/github-api/github-api/contributors",
49+
"subscribers_url": "https://api.github.com/repos/github-api/github-api/subscribers",
50+
"subscription_url": "https://api.github.com/repos/github-api/github-api/subscription",
51+
"commits_url": "https://api.github.com/repos/github-api/github-api/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/github-api/github-api/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/github-api/github-api/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/github-api/github-api/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/github-api/github-api/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/github-api/github-api/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/github-api/github-api/merges",
58+
"archive_url": "https://api.github.com/repos/github-api/github-api/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/github-api/github-api/downloads",
60+
"issues_url": "https://api.github.com/repos/github-api/github-api/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/github-api/github-api/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/github-api/github-api/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/github-api/github-api/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/github-api/github-api/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/github-api/github-api/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/github-api/github-api/deployments",
67+
"created_at": "2010-04-19T04:13:03Z",
68+
"updated_at": "2020-01-10T19:14:02Z",
69+
"pushed_at": "2020-01-10T19:14:21Z",
70+
"git_url": "git://github.com/github-api/github-api.git",
71+
"ssh_url": "git@github.com:github-api/github-api.git",
72+
"clone_url": "https://github.com/github-api/github-api.git",
73+
"svn_url": "https://github.com/github-api/github-api",
74+
"homepage": "http://github-api.kohsuke.org/",
75+
"size": 17575,
76+
"stargazers_count": 602,
77+
"watchers_count": 602,
78+
"language": "Java",
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": true,
84+
"forks_count": 444,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 55,
89+
"license": {
90+
"key": "mit",
91+
"name": "MIT License",
92+
"spdx_id": "MIT",
93+
"url": "https://api.github.com/licenses/mit",
94+
"node_id": "MDc6TGljZW5zZTEz"
95+
},
96+
"forks": 444,
97+
"open_issues": 55,
98+
"watchers": 602,
99+
"default_branch": "master",
100+
"permissions": {
101+
"admin": true,
102+
"push": true,
103+
"pull": true
104+
},
105+
"temp_clone_token": "",
106+
"allow_squash_merge": true,
107+
"allow_merge_commit": true,
108+
"allow_rebase_merge": true,
109+
"delete_branch_on_merge": false,
110+
"organization": {
111+
"login": "github-api",
112+
"id": 54909825,
113+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
114+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
115+
"gravatar_id": "",
116+
"url": "https://api.github.com/users/github-api",
117+
"html_url": "https://github.com/github-api",
118+
"followers_url": "https://api.github.com/users/github-api/followers",
119+
"following_url": "https://api.github.com/users/github-api/following{/other_user}",
120+
"gists_url": "https://api.github.com/users/github-api/gists{/gist_id}",
121+
"starred_url": "https://api.github.com/users/github-api/starred{/owner}{/repo}",
122+
"subscriptions_url": "https://api.github.com/users/github-api/subscriptions",
123+
"organizations_url": "https://api.github.com/users/github-api/orgs",
124+
"repos_url": "https://api.github.com/users/github-api/repos",
125+
"events_url": "https://api.github.com/users/github-api/events{/privacy}",
126+
"received_events_url": "https://api.github.com/users/github-api/received_events",
127+
"type": "Organization",
128+
"site_admin": false
129+
},
130+
"network_count": 444,
131+
"subscribers_count": 49
132+
}

0 commit comments

Comments
 (0)