From 804fa60317798d3f4d15848c3a3264dd220dfa78 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Mon, 24 Feb 2020 10:38:45 -0800 Subject: [PATCH] Deprecate asList and asSet --- .../java/org/kohsuke/github/GHContent.java | 16 ----- src/main/java/org/kohsuke/github/GHIssue.java | 8 +-- .../java/org/kohsuke/github/GHMembership.java | 5 -- .../java/org/kohsuke/github/GHMyself.java | 14 ++-- .../org/kohsuke/github/GHOrganization.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 7 -- .../java/org/kohsuke/github/GHRelease.java | 6 +- .../java/org/kohsuke/github/GHRepository.java | 67 ++++++++----------- src/main/java/org/kohsuke/github/GHTeam.java | 10 +-- src/main/java/org/kohsuke/github/GHUser.java | 7 +- src/main/java/org/kohsuke/github/GitHub.java | 40 +++++------ .../org/kohsuke/github/PagedIterable.java | 33 ++++++++- src/test/java/org/kohsuke/github/AppTest.java | 16 ++--- .../java/org/kohsuke/github/GHAppTest.java | 2 +- .../org/kohsuke/github/GHIssueEventTest.java | 4 +- .../kohsuke/github/GHMarketplacePlanTest.java | 14 ++-- .../org/kohsuke/github/GHPullRequestTest.java | 18 ++--- .../github/GHRepositoryStatisticsTest.java | 4 +- .../org/kohsuke/github/GHRepositoryTest.java | 23 +++++-- .../java/org/kohsuke/github/GitHubTest.java | 2 +- 20 files changed, 138 insertions(+), 160 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index b8599d9a9..ac9144055 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -387,22 +387,6 @@ public class GHContent implements Refreshable { return this; } - /** - * Wrap gh content [ ]. - * - * @param contents - * the contents - * @param repository - * the repository - * @return the gh content [ ] - */ - public static GHContent[] wrap(GHContent[] contents, GHRepository repository) { - for (GHContent unwrappedContent : contents) { - unwrappedContent.wrap(repository); - } - return contents; - } - /** * Fully populate the data by retrieving missing data. * diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index ab476fe47..051e36732 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -100,12 +100,6 @@ public class GHIssue extends GHObject implements Reactable { return this; } - static GHIssue[] wrap(GHIssue[] issues, GHRepository owner) { - for (GHIssue i : issues) - i.wrap(owner); - return issues; - } - /** * Repository to which the issue belongs. * @@ -434,7 +428,7 @@ public class GHIssue extends GHObject implements Reactable { * @see #listComments() #listComments() */ public List getComments() throws IOException { - return listComments().asList(); + return listComments().toList(); } /** diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index 154660854..38da47a91 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -83,11 +83,6 @@ public class GHMembership /* extends GHObject --- but it doesn't have id, create return this; } - static void wrap(GHMembership[] page, GitHub root) { - for (GHMembership m : page) - m.wrap(root); - } - /** * Role of a user in an organization. */ diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 5d559cbac..f394bec52 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -2,7 +2,6 @@ package org.kohsuke.github; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -69,11 +68,7 @@ public class GHMyself extends GHUser { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.createRequest() - .withUrlPath("/user/emails") - .toIterable(GHEmail[].class, null) - .toArray(); - return Collections.unmodifiableList(Arrays.asList(addresses)); + return root.createRequest().withUrlPath("/user/emails").toIterable(GHEmail[].class, null).toList(); } /** @@ -87,8 +82,7 @@ public class GHMyself extends GHUser { * the io exception */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList(Arrays - .asList(root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toArray())); + return root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toList(); } /** @@ -102,10 +96,10 @@ public class GHMyself extends GHUser { * the io exception */ public List getPublicVerifiedKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.createRequest() + return root.createRequest() .withUrlPath("/users/" + getLogin() + "/keys") .toIterable(GHVerifiedKey[].class, null) - .toArray())); + .toList(); } /** diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 061b77d56..2bf341d61 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -253,7 +253,7 @@ public class GHOrganization extends GHPerson { * @deprecated use {@link #listMembers()} */ public List getMembers() throws IOException { - return listMembers().asList(); + return listMembers().toList(); } /** diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index e41094a85..bfa718f61 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -88,13 +88,6 @@ public class GHRef { return this; } - static GHRef[] wrap(GHRef[] in, GitHub root) { - for (GHRef r : in) { - r.wrap(root); - } - return in; - } - /** * The type GHObject. */ diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 2ebde9d28..2371bb292 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLEncoder; -import java.util.Arrays; import java.util.Date; import java.util.List; @@ -258,8 +257,9 @@ public class GHRelease extends GHObject { public List getAssets() throws IOException { Requester builder = owner.root.createRequest(); - GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toIterable(GHAsset[].class, null).toArray(); - return Arrays.asList(GHAsset.wrap(assets, this)); + return builder.withUrlPath(getApiTailUrl("assets")) + .toIterable(GHAsset[].class, item -> item.wrap(this)) + .toList(); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 9ee25206a..ee8d152c7 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -39,7 +39,6 @@ import java.io.Reader; import java.net.URL; import java.util.AbstractSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -358,7 +357,7 @@ public class GHRepository extends GHObject { * the io exception */ public List getIssues(GHIssueState state) throws IOException { - return listIssues(state).asList(); + return listIssues(state).toList(); } /** @@ -376,9 +375,9 @@ public class GHRepository extends GHObject { Requester requester = root.createRequest() .with("state", state) .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()); - return Arrays.asList( - GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).toIterable(GHIssue[].class, null).toArray(), - this)); + return requester.withUrlPath(getApiTailUrl("issues")) + .toIterable(GHIssue[].class, item -> item.wrap(this)) + .toList(); } /** @@ -437,7 +436,7 @@ public class GHRepository extends GHObject { * @deprecated use {@link #listReleases()} */ public List getReleases() throws IOException { - return listReleases().asList(); + return listReleases().toList(); } /** @@ -735,7 +734,7 @@ public class GHRepository extends GHObject { */ @WithBridgeMethods(Set.class) public GHPersonSet getCollaborators() throws IOException { - return new GHPersonSet(listCollaborators().asList()); + return new GHPersonSet(listCollaborators().toList()); } /** @@ -785,12 +784,14 @@ public class GHRepository extends GHObject { * the io exception */ public Set getCollaboratorNames() throws IOException { - Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.createRequest() + Set r = new HashSet<>(); + // no initializer - we just want to the logins + PagedIterable users = root.createRequest() .withUrlPath(getApiTailUrl("collaborators")) - .toIterable(GHUser[].class, null) - .toArray(), root)) + .toIterable(GHUser[].class, null); + for (GHUser u : users.toArray()) { r.add(u.login); + } return r; } @@ -832,9 +833,11 @@ public class GHRepository extends GHObject { * the io exception */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp( - root.createRequest().withUrlPath(getApiTailUrl("teams")).toIterable(GHTeam[].class, null).toArray(), - root.getOrganization(getOwnerName()))))); + GHOrganization org = root.getOrganization(getOwnerName()); + return root.createRequest() + .withUrlPath(getApiTailUrl("teams")) + .toIterable(GHTeam[].class, item -> item.wrapUp(org)) + .toSet(); } /** @@ -1240,7 +1243,7 @@ public class GHRepository extends GHObject { * @see #listPullRequests(GHIssueState) #listPullRequests(GHIssueState) */ public List getPullRequests(GHIssueState state) throws IOException { - return queryPullRequests().state(state).list().asList(); + return queryPullRequests().state(state).list().toList(); } /** @@ -1451,10 +1454,7 @@ public class GHRepository extends GHObject { * on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { - return GHRef.wrap(root.createRequest() - .withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name)) - .toIterable(GHRef[].class, null) - .toArray(), root); + return listRefs().toArray(); } /** @@ -1479,10 +1479,7 @@ public class GHRepository extends GHObject { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { - return GHRef.wrap(root.createRequest() - .withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType)) - .toIterable(GHRef[].class, null) - .toArray(), root); + return listRefs(refType).toArray(); } /** @@ -1740,7 +1737,7 @@ public class GHRepository extends GHObject { * the io exception */ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException { - List v = listCommitStatuses(sha1).asList(); + List v = listCommitStatuses(sha1).toList(); return v.isEmpty() ? null : v.get(0); } @@ -2077,9 +2074,8 @@ public class GHRepository extends GHObject { Map r = new TreeMap(); for (GHBranch p : root.createRequest() .withUrlPath(getApiTailUrl("branches")) - .toIterable(GHBranch[].class, null) + .toIterable(GHBranch[].class, item -> item.wrap(this)) .toArray()) { - p.wrap(this); r.put(p.getName(), p); } return r; @@ -2210,14 +2206,10 @@ public class GHRepository extends GHObject { } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref) + return requester.with("ref", ref) .withUrlPath(target) - .toIterable(GHContent[].class, null) - .toArray(); - - GHContent.wrap(files, this); - - return Arrays.asList(files); + .toIterable(GHContent[].class, item -> item.wrap(this)) + .toList(); } /** @@ -2371,13 +2363,10 @@ public class GHRepository extends GHObject { * the io exception */ public List getDeployKeys() throws IOException { - List list = new ArrayList(Arrays.asList(root.createRequest() + return root.createRequest() .withUrlPath(getApiTailUrl("keys")) - .toIterable(GHDeployKey[].class, null) - .toArray())); - for (GHDeployKey h : list) - h.wrap(this); - return list; + .toIterable(GHDeployKey[].class, item -> item.wrap(this)) + .toList(); } /** diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index bf67761db..85eefdb85 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -1,7 +1,6 @@ package org.kohsuke.github; import java.io.IOException; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -52,13 +51,6 @@ public class GHTeam implements Refreshable { return wrapUp(organization); } - static GHTeam[] wrapUp(GHTeam[] teams, GHOrganization owner) { - for (GHTeam t : teams) { - t.wrapUp(owner); - } - return teams; - } - static GHTeam[] wrapUp(GHTeam[] teams, GHPullRequest owner) { for (GHTeam t : teams) { t.root = owner.root; @@ -163,7 +155,7 @@ public class GHTeam implements Refreshable { * the io exception */ public Set getMembers() throws IOException { - return Collections.unmodifiableSet(listMembers().asSet()); + return listMembers().toSet(); } /** diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index c5217ad77..89542f1ce 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -41,8 +41,7 @@ public class GHUser extends GHPerson { * the io exception */ public List getKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList( - root.createRequest().withUrlPath(getApiTailUrl("keys")).toIterable(GHKey[].class, null).toArray())); + return root.createRequest().withUrlPath(getApiTailUrl("keys")).toIterable(GHKey[].class, null).toList(); } /** @@ -74,7 +73,7 @@ public class GHUser extends GHPerson { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollows() throws IOException { - return new GHPersonSet(listFollows().asList()); + return new GHPersonSet(listFollows().toList()); } /** @@ -95,7 +94,7 @@ public class GHUser extends GHPerson { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollowers() throws IOException { - return new GHPersonSet(listFollowers().asList()); + return new GHPersonSet(listFollowers().toList()); } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 2f1ce3d4c..73353691d 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -599,13 +599,9 @@ public class GitHub { * the io exception */ public List getMyInvitations() throws IOException { - GHInvitation[] invitations = createRequest().withUrlPath("/user/repository_invitations") - .toIterable(GHInvitation[].class, null) - .toArray(); - for (GHInvitation i : invitations) { - i.wrapUp(this); - } - return Arrays.asList(invitations); + return createRequest().withUrlPath("/user/repository_invitations") + .toIterable(GHInvitation[].class, item -> item.wrapUp(this)) + .toList(); } /** @@ -620,12 +616,12 @@ public class GitHub { */ public Map getMyOrganizations() throws IOException { GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs") - .toIterable(GHOrganization[].class, null) + .toIterable(GHOrganization[].class, item -> item.wrapUp(this)) .toArray(); - Map r = new HashMap(); + Map r = new HashMap<>(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow - r.put(o.getLogin(), o.wrapUp(this)); + r.put(o.getLogin(), o); } return r; } @@ -675,12 +671,12 @@ public class GitHub { */ public Map getUserPublicOrganizations(String login) throws IOException { GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs") - .toIterable(GHOrganization[].class, null) + .toIterable(GHOrganization[].class, item -> item.wrapUp(this)) .toArray(); - Map r = new HashMap(); + Map r = new HashMap<>(); for (GHOrganization o : orgs) { - // don't put 'o' into orgs because they are shallow - r.put(o.getLogin(), o.wrapUp(this)); + // don't put 'o' into orgs cache because they are shallow records + r.put(o.getLogin(), o); } return r; } @@ -696,13 +692,14 @@ public class GitHub { * the io exception */ public Map> getMyTeams() throws IOException { - Map> allMyTeams = new HashMap>(); - for (GHTeam team : createRequest().withUrlPath("/user/teams").toIterable(GHTeam[].class, null).toArray()) { - team.wrapUp(this); + Map> allMyTeams = new HashMap<>(); + for (GHTeam team : createRequest().withUrlPath("/user/teams") + .toIterable(GHTeam[].class, item -> item.wrapUp(this)) + .toArray()) { String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); if (teamsPerOrg == null) { - teamsPerOrg = new HashSet(); + teamsPerOrg = new HashSet<>(); } teamsPerOrg.add(team); allMyTeams.put(orgLogin, teamsPerOrg); @@ -731,10 +728,9 @@ public class GitHub { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = createRequest().withUrlPath("/events").toIterable(GHEventInfo[].class, null).toArray(); - for (GHEventInfo e : events) - e.wrapUp(this); - return Arrays.asList(events); + return createRequest().withUrlPath("/events") + .toIterable(GHEventInfo[].class, item -> item.wrapUp(this)) + .toList(); } /** diff --git a/src/main/java/org/kohsuke/github/PagedIterable.java b/src/main/java/org/kohsuke/github/PagedIterable.java index 6fac1c2ea..c11049a0c 100644 --- a/src/main/java/org/kohsuke/github/PagedIterable.java +++ b/src/main/java/org/kohsuke/github/PagedIterable.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -111,9 +112,31 @@ public abstract class PagedIterable implements Iterable { * @return the list */ @Nonnull + public List toList() throws IOException { + return Collections.unmodifiableList(Arrays.asList(this.toArray())); + } + + /** + * Eagerly walk {@link Iterable} and return the result in a set. + * + * @return the set + */ + @Nonnull + public Set toSet() throws IOException { + return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(this.toArray()))); + } + + /** + * Eagerly walk {@link Iterable} and return the result in a list. + * + * @return the list + * @deprecated Use {@link #toList()} instead. + */ + @Nonnull + @Deprecated public List asList() { try { - return Arrays.asList(this.toArray()); + return this.toList(); } catch (IOException e) { throw new GHException("Failed to retrieve list: " + e.getMessage(), e); } @@ -123,10 +146,16 @@ public abstract class PagedIterable implements Iterable { * Eagerly walk {@link Iterable} and return the result in a set. * * @return the set + * @deprecated Use {@link #toSet()} instead. */ @Nonnull + @Deprecated public Set asSet() { - return new LinkedHashSet<>(this.asList()); + try { + return this.toSet(); + } catch (IOException e) { + throw new GHException("Failed to retrieve list: " + e.getMessage(), e); + } } /** diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 662b134c8..6bbb2880a 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -117,7 +117,7 @@ public class AppTest extends AbstractGitHubWireMockTest { .create(); assertNotNull(deployment.getCreator()); assertNotNull(deployment.getId()); - List deployments = repository.listDeployments(null, "master", null, "unittest").asList(); + List deployments = repository.listDeployments(null, "master", null, "unittest").toList(); assertNotNull(deployments); assertFalse(Iterables.isEmpty(deployments)); GHDeployment unitTestDeployment = deployments.get(0); @@ -260,7 +260,7 @@ public class AppTest extends AbstractGitHubWireMockTest { GHRepository r = gitHub.getRepository("github-api/github-api"); assertEquals("master", r.getMasterBranch()); PagedIterable i = r.listPullRequests(GHIssueState.CLOSED); - List prs = i.asList(); + List prs = i.toList(); assertNotNull(prs); assertTrue(prs.size() > 0); } @@ -570,7 +570,7 @@ public class AppTest extends AbstractGitHubWireMockTest { // state = r.createCommitStatus("ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396", GHCommitState.FAILURE, // "http://kohsuke.org/", "testing!"); - List lst = r.listCommitStatuses("ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396").asList(); + List lst = r.listCommitStatuses("ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396").toList(); state = lst.get(0); // System.out.println(state); assertEquals("testing!", state.getDescription()); @@ -778,7 +778,7 @@ public class AppTest extends AbstractGitHubWireMockTest { cleanupLabel("test2"); GHRepository r = gitHub.getRepository("github-api-test-org/test-labels"); - List lst = r.listLabels().asList(); + List lst = r.listLabels().toList(); for (GHLabel l : lst) { // System.out.println(l.getName()); } @@ -887,7 +887,7 @@ public class AppTest extends AbstractGitHubWireMockTest { List l; // retrieval - l = i.listReactions().asList(); + l = i.listReactions().toList(); assertThat(l.size(), equalTo(1)); assertThat(l.get(0).getUser().getLogin(), is("kohsuke")); @@ -900,7 +900,7 @@ public class AppTest extends AbstractGitHubWireMockTest { assertThat(a.getContent(), is(ReactionContent.HOORAY)); a.delete(); - l = i.listReactions().asList(); + l = i.listReactions().toList(); assertThat(l.size(), equalTo(1)); a = i.createReaction(ReactionContent.PLUS_ONE); @@ -919,7 +919,7 @@ public class AppTest extends AbstractGitHubWireMockTest { assertThat(a.getUser().getLogin(), is(gitHub.getMyself().getLogin())); assertThat(a.getContent(), is(ReactionContent.ROCKET)); - l = i.listReactions().asList(); + l = i.listReactions().toList(); assertThat(l.size(), equalTo(5)); assertThat(l.get(0).getUser().getLogin(), is("kohsuke")); assertThat(l.get(0).getContent(), is(ReactionContent.HEART)); @@ -937,7 +937,7 @@ public class AppTest extends AbstractGitHubWireMockTest { l.get(3).delete(); l.get(4).delete(); - l = i.listReactions().asList(); + l = i.listReactions().toList(); assertThat(l.size(), equalTo(1)); } diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index f0f76c06b..0361f01df 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -43,7 +43,7 @@ public class GHAppTest extends AbstractGitHubWireMockTest { @Test public void listInstallations() throws IOException { GHApp app = gitHub.getApp(); - List installations = app.listInstallations().asList(); + List installations = app.listInstallations().toList(); assertThat(installations.size(), is(1)); GHAppInstallation appInstallation = installations.get(0); diff --git a/src/test/java/org/kohsuke/github/GHIssueEventTest.java b/src/test/java/org/kohsuke/github/GHIssueEventTest.java index b8135ec15..c3d097634 100644 --- a/src/test/java/org/kohsuke/github/GHIssueEventTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueEventTest.java @@ -20,7 +20,7 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest { issue.addLabels("test-label"); // Test that the events are present. - List list = issue.listEvents().asList(); + List list = issue.listEvents().toList(); assertEquals(1, list.size()); GHIssueEvent event = list.get(0); @@ -39,7 +39,7 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest { @Test public void testRepositoryEvents() throws Exception { GHRepository repo = getRepository(); - List list = repo.listIssueEvents().asList(); + List list = repo.listIssueEvents().toList(); assertTrue(list.size() > 0); int i = 0; diff --git a/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java b/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java index a6dbfe749..b1693e5c7 100644 --- a/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java +++ b/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java @@ -28,30 +28,30 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest { @Test public void listMarketplacePlans() throws IOException { - List plans = gitHub.listMarketplacePlans().asList(); + List plans = gitHub.listMarketplacePlans().toList(); assertEquals(3, plans.size()); plans.forEach(this::testMarketplacePlan); } @Test public void listAccounts() throws IOException { - List plans = gitHub.listMarketplacePlans().asList(); + List plans = gitHub.listMarketplacePlans().toList(); assertEquals(3, plans.size()); - List marketplaceUsers = plans.get(0).listAccounts().createRequest().asList(); + List marketplaceUsers = plans.get(0).listAccounts().createRequest().toList(); assertEquals(2, marketplaceUsers.size()); marketplaceUsers.forEach(this::testMarketplaceAccount); } @Test public void listAccountsWithDirection() throws IOException { - List plans = gitHub.listMarketplacePlans().asList(); + List plans = gitHub.listMarketplacePlans().toList(); assertEquals(3, plans.size()); for (GHMarketplacePlan plan : plans) { List marketplaceUsers = plan.listAccounts() .direction(DESC) .createRequest() - .asList(); + .toList(); assertEquals(2, marketplaceUsers.size()); marketplaceUsers.forEach(this::testMarketplaceAccount); } @@ -60,7 +60,7 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest { @Test public void listAccountsWithSortAndDirection() throws IOException { - List plans = gitHub.listMarketplacePlans().asList(); + List plans = gitHub.listMarketplacePlans().toList(); assertEquals(3, plans.size()); for (GHMarketplacePlan plan : plans) { @@ -68,7 +68,7 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest { .sort(UPDATED) .direction(DESC) .createRequest() - .asList(); + .toList(); assertEquals(2, marketplaceUsers.size()); marketplaceUsers.forEach(this::testMarketplaceAccount); } diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index 51d95a775..72079ee7d 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -56,7 +56,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { assertThat(p2.getNumber(), is(p.getNumber())); assertThat(p2.isDraft(), is(true)); - p = repo.queryPullRequests().state(GHIssueState.OPEN).head("test/stable").list().asList().get(0); + p = repo.queryPullRequests().state(GHIssueState.OPEN).head("test/stable").list().toList().get(0); assertThat(p2.getNumber(), is(p.getNumber())); assertThat(p.isDraft(), is(true)); @@ -91,14 +91,14 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING)); assertThat(draftReview.getBody(), is("Some draft review")); assertThat(draftReview.getCommitId(), notNullValue()); - List reviews = p.listReviews().asList(); + List reviews = p.listReviews().toList(); assertThat(reviews.size(), is(1)); GHPullRequestReview review = reviews.get(0); assertThat(review.getState(), is(GHPullRequestReviewState.PENDING)); assertThat(review.getBody(), is("Some draft review")); assertThat(review.getCommitId(), notNullValue()); draftReview.submit("Some review comment", GHPullRequestReviewEvent.COMMENT); - List comments = review.listReviewComments().asList(); + List comments = review.listReviewComments().toList(); assertEquals(1, comments.size()); GHPullRequestReviewComment comment = comments.get(0); assertEquals("Some niggle", comment.getBody()); @@ -111,21 +111,21 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { String name = "pullRequestReviewComments"; GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test"); // System.out.println(p.getUrl()); - assertTrue(p.listReviewComments().asList().isEmpty()); + assertTrue(p.listReviewComments().toList().isEmpty()); p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1); - List comments = p.listReviewComments().asList(); + List comments = p.listReviewComments().toList(); assertEquals(1, comments.size()); GHPullRequestReviewComment comment = comments.get(0); assertEquals("Sample review comment", comment.getBody()); comment.update("Updated review comment"); - comments = p.listReviewComments().asList(); + comments = p.listReviewComments().toList(); assertEquals(1, comments.size()); comment = comments.get(0); assertEquals("Updated review comment", comment.getBody()); comment.delete(); - comments = p.listReviewComments().asList(); + comments = p.listReviewComments().toList(); assertTrue(comments.isEmpty()); } @@ -254,7 +254,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { .head("github-api-test-org:test/stable") .base("master") .list() - .asList(); + .toList(); assertNotNull(prs); assertEquals(1, prs.size()); assertEquals("test/stable", prs.get(0).getHead().getRef()); @@ -273,7 +273,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { .head("test/stable") .base("master") .list() - .asList(); + .toList(); assertNotNull(prs); assertEquals(1, prs.size()); assertEquals("test/stable", prs.get(0).getHead().getRef()); diff --git a/src/test/java/org/kohsuke/github/GHRepositoryStatisticsTest.java b/src/test/java/org/kohsuke/github/GHRepositoryStatisticsTest.java index 057a09ee3..cae623b13 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryStatisticsTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryStatisticsTest.java @@ -24,7 +24,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest { } // check the statistics are accurate - List list = stats.asList(); + List list = stats.toList(); assertEquals(99, list.size()); // find a particular developer @@ -79,7 +79,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest { } // check the statistics are accurate - List list = stats.asList(); + List list = stats.toList(); // TODO: Return this as a map with the timestamp as the key. // Either that or wrap in an object an accessor method. diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 0356ead76..c2ca9f46d 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -394,7 +394,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listRefs() throws Exception { GHRepository repo = getTempRepository(); - List refs = repo.listRefs().asList(); + List refs = repo.listRefs().toList(); assertThat(refs, notNullValue()); assertThat(refs.size(), equalTo(1)); assertThat(refs.get(0).getRef(), equalTo("refs/heads/master")); @@ -403,7 +403,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listRefsHeads() throws Exception { GHRepository repo = getTempRepository(); - List refs = repo.listRefs("heads").asList(); + List refs = repo.listRefs("heads").toList(); assertThat(refs, notNullValue()); assertThat(refs.size(), equalTo(1)); assertThat(refs.get(0).getRef(), equalTo("refs/heads/master")); @@ -411,6 +411,19 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listRefsEmptyTags() throws Exception { + try { + GHRepository repo = getTempRepository(); + repo.listRefs("tags").toList(); + fail(); + } catch (Exception e) { + assertThat(e, instanceOf(GHFileNotFoundException.class)); + assertThat(e.getMessage(), + containsString("/repos/github-api-test-org/temp-listRefsEmptyTags/git/refs/tags")); + } + } + + @Test + public void listRefsEmptyTagsAsList() throws Exception { try { GHRepository repo = getTempRepository(); repo.listRefs("tags").asList(); @@ -427,7 +440,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listTagsEmpty() throws Exception { GHRepository repo = getTempRepository(); - List refs = repo.listTags().asList(); + List refs = repo.listTags().toList(); assertThat(refs, notNullValue()); assertThat(refs.size(), equalTo(0)); } @@ -435,7 +448,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listTags() throws Exception { GHRepository repo = getRepository(); - List refs = repo.listTags().withPageSize(33).asList(); + List refs = repo.listTags().withPageSize(33).toList(); assertThat(refs, notNullValue()); assertThat(refs.size(), greaterThan(90)); } @@ -459,7 +472,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void listCollaborators() throws Exception { GHRepository repo = getRepository(); - List collaborators = repo.listCollaborators().asList(); + List collaborators = repo.listCollaborators().toList(); assertThat(collaborators.size(), greaterThan(10)); } } diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 0d4887a7a..5208feb3b 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -112,7 +112,7 @@ public class GitHubTest extends AbstractGitHubWireMockTest { @Test public void getMyMarketplacePurchases() throws IOException { - List userPurchases = gitHub.getMyMarketplacePurchases().asList(); + List userPurchases = gitHub.getMyMarketplacePurchases().toList(); assertEquals(2, userPurchases.size()); for (GHMarketplaceUserPurchase userPurchase : userPurchases) {