From 2af4f6188268e8216fd2d7e10a95eb6dda4c9062 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Mon, 18 Nov 2019 11:35:45 -0800 Subject: [PATCH] Cleanup imports --- pom.xml | 87 +++++++++++-------- .../java/org/kohsuke/github/DeleteToken.java | 3 +- .../github/GHAppCreateTokenBuilder.java | 4 +- .../kohsuke/github/GHBranchProtection.java | 4 +- src/main/java/org/kohsuke/github/GHEvent.java | 50 +++++++++-- .../github/GHFileNotFoundException.java | 3 +- .../org/kohsuke/github/GHIOException.java | 3 +- src/main/java/org/kohsuke/github/GHIssue.java | 51 ++++++----- .../java/org/kohsuke/github/GHObject.java | 3 +- .../org/kohsuke/github/GHOrganization.java | 1 + .../org/kohsuke/github/GHPullRequest.java | 47 ++++++---- .../kohsuke/github/GHPullRequestReview.java | 5 +- .../github/GHPullRequestReviewComment.java | 1 + .../java/org/kohsuke/github/GHRateLimit.java | 3 +- .../java/org/kohsuke/github/GHRepository.java | 4 - .../github/GHRepositoryStatistics.java | 1 + src/main/java/org/kohsuke/github/GitHub.java | 5 +- .../org/kohsuke/github/HttpException.java | 3 +- .../java/org/kohsuke/github/Refreshable.java | 3 - .../java/org/kohsuke/github/Requester.java | 19 ++-- .../example/dataobject/ReadOnlyObjects.java | 11 ++- .../github/extras/OkHttpConnector.java | 4 - .../extras/okhttp3/ObsoleteUrlFactory.java | 44 +++++----- .../extras/okhttp3/OkHttpConnector.java | 4 +- src/test/java/org/kohsuke/HookApp.java | 4 +- .../github/AbstractGitHubApiTestBase.java | 9 -- src/test/java/org/kohsuke/github/AppTest.java | 2 - .../java/org/kohsuke/github/GHAppTest.java | 6 +- .../github/GHBranchProtectionTest.java | 11 ++- .../github/GHContentIntegrationTest.java | 4 +- .../org/kohsuke/github/GHDeploymentTest.java | 1 + .../kohsuke/github/GHEventPayloadTest.java | 44 +++++----- .../org/kohsuke/github/GHGistUpdaterTest.java | 11 ++- .../java/org/kohsuke/github/GHHookTest.java | 5 +- .../org/kohsuke/github/GHIssueEventTest.java | 3 +- .../kohsuke/github/GHOrganizationTest.java | 11 ++- .../org/kohsuke/github/GHPullRequestTest.java | 43 ++++++--- .../org/kohsuke/github/GHRateLimitTest.java | 6 -- .../org/kohsuke/github/GHRepositoryTest.java | 19 ++-- .../java/org/kohsuke/github/GHTeamTest.java | 1 - .../java/org/kohsuke/github/GistTest.java | 2 - .../org/kohsuke/github/GitHubStaticTest.java | 2 - .../java/org/kohsuke/github/GitHubTest.java | 6 +- .../org/kohsuke/github/Github2faTest.java | 4 +- .../org/kohsuke/github/LifecycleTest.java | 29 +++++-- .../java/org/kohsuke/github/PayloadRule.java | 13 +-- .../kohsuke/github/RepositoryMockTest.java | 2 +- .../kohsuke/github/RepositoryTrafficTest.java | 6 +- .../github/WireMockStatusReporterTest.java | 14 +-- .../github/extras/OkHttpConnectorTest.java | 3 +- .../extras/okhttp3/OkHttpConnectorTest.java | 15 ++-- .../github/junit/GitHubWireMockRule.java | 28 +++--- .../github/junit/WireMockMultiServerRule.java | 3 +- .../kohsuke/github/junit/WireMockRule.java | 20 +---- 54 files changed, 404 insertions(+), 286 deletions(-) diff --git a/pom.xml b/pom.xml index 7b3feb66a..34b8eb50f 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,7 @@ 4.2.2 2.4.1 format + sort .80 0.20 0.50 @@ -181,6 +182,23 @@ + + net.revelc.code + impsort-maven-plugin + 1.3.2 + + *,java.,javax. + true + true + + + + + ${impsort-maven-plugin.goal} + + + + com.github.spotbugs spotbugs-maven-plugin @@ -359,6 +377,7 @@ ci validate + check @@ -406,44 +425,44 @@ - - - - + + + + METHOD COVEREDRATIO ${jacoco.coverage.target.method} - - - - - + + + + + org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory.** @@ -461,7 +480,7 @@ - release + release diff --git a/src/main/java/org/kohsuke/github/DeleteToken.java b/src/main/java/org/kohsuke/github/DeleteToken.java index ebef1967f..30079d0a2 100644 --- a/src/main/java/org/kohsuke/github/DeleteToken.java +++ b/src/main/java/org/kohsuke/github/DeleteToken.java @@ -28,7 +28,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** * @author Kohsuke Kawaguchi */ -@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", justification = "Being constructed by JSON deserialization") +@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", + justification = "Being constructed by JSON deserialization") class DeleteToken { public String delete_token; } diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 43291820b..29830425b 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -55,7 +55,9 @@ public class GHAppCreateTokenBuilder { @Preview @Deprecated public GHAppInstallationToken create() throws IOException { - return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class) + return builder.method("POST") + .withPreview(MACHINE_MAN) + .to(apiUrlTail, GHAppInstallationToken.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 80a5e7bb4..d434c4039 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -3,11 +3,11 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import static org.kohsuke.github.Previews.ZZZAX; - import java.io.IOException; import java.util.Collection; +import static org.kohsuke.github.Previews.ZZZAX; + /** * The type GHBranchProtection. */ diff --git a/src/main/java/org/kohsuke/github/GHEvent.java b/src/main/java/org/kohsuke/github/GHEvent.java index 7d9254344..c82584096 100644 --- a/src/main/java/org/kohsuke/github/GHEvent.java +++ b/src/main/java/org/kohsuke/github/GHEvent.java @@ -10,12 +10,50 @@ import java.util.Locale; * @see Event type reference */ public enum GHEvent { - COMMIT_COMMENT, CREATE, DELETE, DEPLOYMENT, DEPLOYMENT_STATUS, DOWNLOAD, FOLLOW, FORK, FORK_APPLY, GIST, GOLLUM, INSTALLATION, INSTALLATION_REPOSITORIES, INTEGRATION_INSTALLATION_REPOSITORIES, CHECK_SUITE, ISSUE_COMMENT, ISSUES, LABEL, MARKETPLACE_PURCHASE, MEMBER, MEMBERSHIP, MILESTONE, ORGANIZATION, ORG_BLOCK, PAGE_BUILD, PROJECT_CARD, PROJECT_COLUMN, PROJECT, PUBLIC, PULL_REQUEST, PULL_REQUEST_REVIEW, PULL_REQUEST_REVIEW_COMMENT, PUSH, RELEASE, REPOSITORY, // only - // valid - // for - // org - // hooks - STATUS, TEAM, TEAM_ADD, WATCH, PING, + COMMIT_COMMENT, + CREATE, + DELETE, + DEPLOYMENT, + DEPLOYMENT_STATUS, + DOWNLOAD, + FOLLOW, + FORK, + FORK_APPLY, + GIST, + GOLLUM, + INSTALLATION, + INSTALLATION_REPOSITORIES, + INTEGRATION_INSTALLATION_REPOSITORIES, + CHECK_SUITE, + ISSUE_COMMENT, + ISSUES, + LABEL, + MARKETPLACE_PURCHASE, + MEMBER, + MEMBERSHIP, + MILESTONE, + ORGANIZATION, + ORG_BLOCK, + PAGE_BUILD, + PROJECT_CARD, + PROJECT_COLUMN, + PROJECT, + PUBLIC, + PULL_REQUEST, + PULL_REQUEST_REVIEW, + PULL_REQUEST_REVIEW_COMMENT, + PUSH, + RELEASE, + REPOSITORY, // only + // valid + // for + // org + // hooks + STATUS, + TEAM, + TEAM_ADD, + WATCH, + PING, /** * Special event type that means "every possible event" */ diff --git a/src/main/java/org/kohsuke/github/GHFileNotFoundException.java b/src/main/java/org/kohsuke/github/GHFileNotFoundException.java index 4db5b5b05..647551592 100644 --- a/src/main/java/org/kohsuke/github/GHFileNotFoundException.java +++ b/src/main/java/org/kohsuke/github/GHFileNotFoundException.java @@ -1,11 +1,12 @@ package org.kohsuke.github; -import javax.annotation.CheckForNull; import java.io.FileNotFoundException; import java.net.HttpURLConnection; import java.util.List; import java.util.Map; +import javax.annotation.CheckForNull; + /** * Request/responce contains useful metadata. Custom exception allows store info for next diagnostics. * diff --git a/src/main/java/org/kohsuke/github/GHIOException.java b/src/main/java/org/kohsuke/github/GHIOException.java index bb792ec1a..b38596867 100644 --- a/src/main/java/org/kohsuke/github/GHIOException.java +++ b/src/main/java/org/kohsuke/github/GHIOException.java @@ -1,11 +1,12 @@ package org.kohsuke.github; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.HttpURLConnection; import java.util.List; import java.util.Map; +import javax.annotation.CheckForNull; + /** * Request/responce contains useful metadata. Custom exception allows store info for next diagnostics. * diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 71a95639e..ec0620d08 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -24,10 +24,9 @@ package org.kohsuke.github; -import static org.kohsuke.github.Previews.SQUIRREL_GIRL; - import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.io.IOException; import java.net.URL; import java.util.ArrayList; @@ -35,10 +34,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Set; + +import static org.kohsuke.github.Previews.SQUIRREL_GIRL; /** * Represents an issue on GitHub. @@ -179,7 +178,7 @@ public class GHIssue extends GHObject implements Reactable { if (labels == null) { return Collections.emptyList(); } - return Collections. unmodifiableList(labels); + return Collections.unmodifiableList(labels); } /** @@ -231,8 +230,8 @@ public class GHIssue extends GHObject implements Reactable { */ @WithBridgeMethods(void.class) public GHIssueComment comment(String message) throws IOException { - GHIssueComment r = new Requester(root).with("body", message).to(getIssuesApiRoute() + "/comments", - GHIssueComment.class); + GHIssueComment r = new Requester(root).with("body", message) + .to(getIssuesApiRoute() + "/comments", GHIssueComment.class); return r.wrapUp(this); } @@ -443,22 +442,27 @@ public class GHIssue extends GHObject implements Reactable { * the io exception */ public PagedIterable listComments() throws IOException { - return root.retrieve().asPagedIterable(getIssuesApiRoute() + "/comments", GHIssueComment[].class, - item -> item.wrapUp(GHIssue.this)); + return root.retrieve() + .asPagedIterable(getIssuesApiRoute() + "/comments", + GHIssueComment[].class, + item -> item.wrapUp(GHIssue.this)); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL).with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class).wrap(root); + return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + .with("content", content.getContent()) + .to(getApiRoute() + "/reactions", GHReaction.class) + .wrap(root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve().withPreview(SQUIRREL_GIRL).asPagedIterable(getApiRoute() + "/reactions", - GHReaction[].class, item -> item.wrap(owner.root)); + return owner.root.retrieve() + .withPreview(SQUIRREL_GIRL) + .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } /** @@ -482,8 +486,10 @@ public class GHIssue extends GHObject implements Reactable { * the io exception */ public void addAssignees(Collection assignees) throws IOException { - root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).to(getIssuesApiRoute() + "/assignees", - this); + root.retrieve() + .method("POST") + .with(ASSIGNEES, getLogins(assignees)) + .to(getIssuesApiRoute() + "/assignees", this); } /** @@ -531,7 +537,10 @@ public class GHIssue extends GHObject implements Reactable { * the io exception */ public void removeAssignees(Collection assignees) throws IOException { - root.retrieve().method("DELETE").with(ASSIGNEES, getLogins(assignees)).inBody() + root.retrieve() + .method("DELETE") + .with(ASSIGNEES, getLogins(assignees)) + .inBody() .to(getIssuesApiRoute() + "/assignees", this); } @@ -645,8 +654,8 @@ public class GHIssue extends GHObject implements Reactable { /** * The type PullRequest. */ - @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", - "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") + @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" }, + justification = "JSON API") public static class PullRequest { private String diff_url, patch_url, html_url; @@ -694,7 +703,9 @@ public class GHIssue extends GHObject implements Reactable { * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve().asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)), - GHIssueEvent[].class, item -> item.wrapUp(GHIssue.this)); + return root.retrieve() + .asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)), + GHIssueEvent[].class, + item -> item.wrapUp(GHIssue.this)); } } diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index a2893c2e1..ae7fd8b51 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -5,7 +5,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import javax.annotation.CheckForNull; import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; @@ -13,6 +12,8 @@ import java.util.Date; import java.util.List; import java.util.Map; +import javax.annotation.CheckForNull; + /** * Most (all?) domain objects in GitHub seems to have these 4 properties. */ diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index c7edefdb4..390f7b4b9 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; + import static org.kohsuke.github.Previews.INERTIA; /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 831309b88..f8a9bb4bc 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -23,7 +23,6 @@ */ package org.kohsuke.github; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.URL; import java.util.ArrayList; @@ -33,6 +32,8 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import javax.annotation.CheckForNull; + import static org.kohsuke.github.Previews.SHADOW_CAT; /** @@ -392,8 +393,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { * @return the paged iterable */ public PagedIterable listFiles() { - return root.retrieve().asPagedIterable(String.format("%s/files", getApiRoute()), - GHPullRequestFileDetail[].class, null); + return root.retrieve() + .asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null); } /** @@ -402,8 +403,10 @@ public class GHPullRequest extends GHIssue implements Refreshable { * @return the paged iterable */ public PagedIterable listReviews() { - return root.retrieve().asPagedIterable(String.format("%s/reviews", getApiRoute()), GHPullRequestReview[].class, - item -> item.wrapUp(GHPullRequest.this)); + return root.retrieve() + .asPagedIterable(String.format("%s/reviews", getApiRoute()), + GHPullRequestReview[].class, + item -> item.wrapUp(GHPullRequest.this)); } /** @@ -414,8 +417,10 @@ public class GHPullRequest extends GHIssue implements Refreshable { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return root.retrieve().asPagedIterable(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment[].class, - item -> item.wrapUp(GHPullRequest.this)); + return root.retrieve() + .asPagedIterable(getApiRoute() + COMMENTS_ACTION, + GHPullRequestReviewComment[].class, + item -> item.wrapUp(GHPullRequest.this)); } /** @@ -424,8 +429,10 @@ public class GHPullRequest extends GHIssue implements Refreshable { * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve().asPagedIterable(String.format("%s/commits", getApiRoute()), - GHPullRequestCommitDetail[].class, item -> item.wrapUp(GHPullRequest.this)); + return root.retrieve() + .asPagedIterable(String.format("%s/commits", getApiRoute()), + GHPullRequestCommitDetail[].class, + item -> item.wrapUp(GHPullRequest.this)); } /** @@ -442,7 +449,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { * the io exception * @deprecated Use {@link #createReview()} */ - public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event, + public GHPullRequestReview createReview(String body, + @CheckForNull GHPullRequestReviewState event, GHPullRequestReviewComment... comments) throws IOException { return createReview(body, event, Arrays.asList(comments)); } @@ -461,7 +469,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { * the io exception * @deprecated Use {@link #createReview()} */ - public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event, + public GHPullRequestReview createReview(String body, + @CheckForNull GHPullRequestReviewState event, List comments) throws IOException { GHPullRequestReviewBuilder b = createReview().body(body); for (GHPullRequestReviewComment c : comments) { @@ -496,8 +505,12 @@ public class GHPullRequest extends GHIssue implements Refreshable { */ public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException { - return new Requester(root).method("POST").with("body", body).with("commit_id", sha).with("path", path) - .with("position", position).to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class) + return new Requester(root).method("POST") + .with("body", body) + .with("commit_id", sha) + .with("path", path) + .with("position", position) + .to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class) .wrapUp(this); } @@ -510,7 +523,8 @@ public class GHPullRequest extends GHIssue implements Refreshable { * the io exception */ public void requestReviewers(List reviewers) throws IOException { - new Requester(root).method("POST").with("reviewers", getLogins(reviewers)) + new Requester(root).method("POST") + .with("reviewers", getLogins(reviewers)) .to(getApiRoute() + REQUEST_REVIEWERS); } @@ -575,7 +589,10 @@ public class GHPullRequest extends GHIssue implements Refreshable { * the io exception */ public void merge(String msg, String sha, MergeMethod method) throws IOException { - new Requester(root).method("PUT").with("commit_message", msg).with("sha", sha).with("merge_method", method) + new Requester(root).method("PUT") + .with("commit_message", msg) + .with("sha", sha) + .with("merge_method", method) .to(getApiRoute() + "/merge"); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 6dc1ee359..65a29d33a 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -25,10 +25,11 @@ package org.kohsuke.github; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.URL; +import java.util.Date; + +import javax.annotation.CheckForNull; /** * Review to a pull request. diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index e1e6a1cf7..74f9dd8d0 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -25,6 +25,7 @@ package org.kohsuke.github; import java.io.IOException; import java.net.URL; + import javax.annotation.CheckForNull; import static org.kohsuke.github.Previews.*; diff --git a/src/main/java/org/kohsuke/github/GHRateLimit.java b/src/main/java/org/kohsuke/github/GHRateLimit.java index 08e2cfa53..00d788b29 100644 --- a/src/main/java/org/kohsuke/github/GHRateLimit.java +++ b/src/main/java/org/kohsuke/github/GHRateLimit.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; -import javax.annotation.Nonnull; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -13,6 +12,8 @@ import java.util.Date; import java.util.Objects; import java.util.logging.Logger; +import javax.annotation.Nonnull; + import static java.util.logging.Level.FINEST; /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 758803428..58047b342 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -24,9 +24,6 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.exc.MismatchedInputException; import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; @@ -54,7 +51,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.WeakHashMap; -import java.util.NoSuchElementException; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 6edeb733c..043a585f1 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.MismatchedInputException; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.io.IOException; import java.io.InputStream; import java.net.URL; diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index a6918e4b6..4ef0782f4 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -32,8 +32,6 @@ import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import java.io.*; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -46,6 +44,9 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; import java.util.logging.Logger; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; diff --git a/src/main/java/org/kohsuke/github/HttpException.java b/src/main/java/org/kohsuke/github/HttpException.java index 8367fbe57..df29f269d 100644 --- a/src/main/java/org/kohsuke/github/HttpException.java +++ b/src/main/java/org/kohsuke/github/HttpException.java @@ -1,10 +1,11 @@ package org.kohsuke.github; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import javax.annotation.CheckForNull; + /** * {@link IOException} for http exceptions because {@link HttpURLConnection} throws un-discerned {@link IOException} and * it can help to know the http response code to decide how to handle an http exceptions. diff --git a/src/main/java/org/kohsuke/github/Refreshable.java b/src/main/java/org/kohsuke/github/Refreshable.java index 1f92457c1..1793a3c43 100644 --- a/src/main/java/org/kohsuke/github/Refreshable.java +++ b/src/main/java/org/kohsuke/github/Refreshable.java @@ -1,9 +1,6 @@ package org.kohsuke.github; -import org.kohsuke.github.extras.ImpatientHttpConnector; - import java.io.IOException; -import java.net.HttpURLConnection; import java.net.URL; /** diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 1a86bf407..51b8e5be8 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -28,8 +28,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import javax.annotation.CheckForNull; -import javax.annotation.WillClose; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -46,7 +44,6 @@ import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -60,6 +57,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import javax.annotation.CheckForNull; +import javax.annotation.WillClose; + import static java.util.Arrays.asList; import static java.util.logging.Level.*; import static org.apache.commons.lang3.StringUtils.defaultString; @@ -723,8 +723,9 @@ class Requester { private void setupConnection(URL url) throws IOException { if (LOGGER.isLoggable(FINE)) { - LOGGER.log(FINE, "GitHub API request [" + (root.login == null ? "anonymous" : root.login) + "]: " + method - + " " + url.toString()); + LOGGER.log(FINE, + "GitHub API request [" + (root.login == null ? "anonymous" : root.login) + "]: " + method + " " + + url.toString()); } uc = root.getConnector().connect(url); @@ -811,7 +812,7 @@ class Requester { throw (IOException) new IOException("Failed to deserialize " + data).initCause(e); } if (instance != null) { - return setResponseHeaders(MAPPER.readerForUpdating(instance). readValue(data)); + return setResponseHeaders(MAPPER.readerForUpdating(instance).readValue(data)); } return null; } catch (FileNotFoundException e) { @@ -872,8 +873,10 @@ class Requester { // likely to be a network exception (e.g. SSLHandshakeException), // uc.getResponseCode() and any other getter on the response will cause an exception if (LOGGER.isLoggable(FINE)) - LOGGER.log(FINE, "Silently ignore exception retrieving response code for '" + uc.getURL() + "'" - + " handling exception " + e, e); + LOGGER.log(FINE, + "Silently ignore exception retrieving response code for '" + uc.getURL() + "'" + + " handling exception " + e, + e); throw e; } InputStream es = wrapStream(uc.getErrorStream()); diff --git a/src/main/java/org/kohsuke/github/example/dataobject/ReadOnlyObjects.java b/src/main/java/org/kohsuke/github/example/dataobject/ReadOnlyObjects.java index ea39c8e00..c9e96613b 100644 --- a/src/main/java/org/kohsuke/github/example/dataobject/ReadOnlyObjects.java +++ b/src/main/java/org/kohsuke/github/example/dataobject/ReadOnlyObjects.java @@ -4,11 +4,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.annotation.Nonnull; + /** * {@link org.kohsuke.github.GHMeta} wraps the list of GitHub's IP addresses. *

@@ -504,8 +505,10 @@ public final class ReadOnlyObjects { @JsonCreator private GHMetaGettersFinalCreator(@Nonnull @JsonProperty("hooks") List hooks, - @Nonnull @JsonProperty("git") List git, @Nonnull @JsonProperty("web") List web, - @Nonnull @JsonProperty("api") List api, @Nonnull @JsonProperty("pages") List pages, + @Nonnull @JsonProperty("git") List git, + @Nonnull @JsonProperty("web") List web, + @Nonnull @JsonProperty("api") List api, + @Nonnull @JsonProperty("pages") List pages, @Nonnull @JsonProperty("importer") List importer, @JsonProperty("verifiable_password_authentication") boolean verifiablePasswordAuthentication) { this.verifiablePasswordAuthentication = verifiablePasswordAuthentication; @@ -545,4 +548,4 @@ public final class ReadOnlyObjects { return importer; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java index 43c2da4c1..9c54c71cb 100644 --- a/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java +++ b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java @@ -4,17 +4,13 @@ import com.squareup.okhttp.CacheControl; import com.squareup.okhttp.ConnectionSpec; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.OkUrlFactory; - import org.kohsuke.github.HttpConnector; import java.io.IOException; - import java.net.HttpURLConnection; import java.net.URL; - import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; - import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java b/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java index 3c453ed11..ba38334d0 100644 --- a/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java +++ b/src/main/java/org/kohsuke/github/extras/okhttp3/ObsoleteUrlFactory.java @@ -1,5 +1,25 @@ package org.kohsuke.github.extras.okhttp3; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Dispatcher; +import okhttp3.Handshake; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.Interceptor; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okio.Buffer; +import okio.BufferedSink; +import okio.Okio; +import okio.Pipe; +import okio.Timeout; + /* * Copyright (C) 2014 Square, Inc. * @@ -15,7 +35,6 @@ package org.kohsuke.github.extras.okhttp3; * See the License for the specific language governing permissions and * limitations under the License. */ - import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -40,31 +59,12 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; + import javax.annotation.Nullable; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSocketFactory; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Dispatcher; -import okhttp3.Handshake; -import okhttp3.Headers; -import okhttp3.HttpUrl; -import okhttp3.Interceptor; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Protocol; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okio.Buffer; -import okio.BufferedSink; -import okio.Okio; -import okio.Pipe; -import okio.Timeout; - import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; @@ -1366,4 +1366,4 @@ public final class ObsoleteUrlFactory implements URLStreamHandlerFactory, Clonea super(cause); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/kohsuke/github/extras/okhttp3/OkHttpConnector.java b/src/main/java/org/kohsuke/github/extras/okhttp3/OkHttpConnector.java index d9bd2b027..ebfc09ad6 100644 --- a/src/main/java/org/kohsuke/github/extras/okhttp3/OkHttpConnector.java +++ b/src/main/java/org/kohsuke/github/extras/okhttp3/OkHttpConnector.java @@ -3,13 +3,11 @@ package org.kohsuke.github.extras.okhttp3; import com.squareup.okhttp.CacheControl; import okhttp3.ConnectionSpec; import okhttp3.OkHttpClient; - import org.kohsuke.github.HttpConnector; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; - import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; @@ -81,4 +79,4 @@ public class OkHttpConnector implements HttpConnector { private List TlsConnectionSpecs() { return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT); } -} \ No newline at end of file +} diff --git a/src/test/java/org/kohsuke/HookApp.java b/src/test/java/org/kohsuke/HookApp.java index 32f2e0157..9ee51407a 100644 --- a/src/test/java/org/kohsuke/HookApp.java +++ b/src/test/java/org/kohsuke/HookApp.java @@ -26,8 +26,8 @@ public class HookApp { public void doIndex(StaplerRequest req) throws IOException { String str = req.getParameter("payload"); // System.out.println(str); - GHEventPayload.PullRequest o = GitHub.connect().parseEventPayload(new StringReader(str), - GHEventPayload.PullRequest.class); + GHEventPayload.PullRequest o = GitHub.connect() + .parseEventPayload(new StringReader(str), GHEventPayload.PullRequest.class); // System.out.println(o); } } diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java index 797362e50..ff5d5955a 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java @@ -1,17 +1,8 @@ package org.kohsuke.github; -import java.io.FileInputStream; -import java.util.Properties; - -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Assume; import org.junit.Before; import org.kohsuke.randname.RandomNameGenerator; -import java.io.File; -import java.io.IOException; - import static org.junit.Assume.assumeTrue; /** diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 64edd8728..fd223bb28 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -2,8 +2,6 @@ package org.kohsuke.github; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - import org.apache.commons.io.IOUtils; import org.junit.Ignore; import org.junit.Test; diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index eb9f96be7..980f3c8f6 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -20,7 +20,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest { protected GitHubBuilder getGitHubBuilder() { return super.getGitHubBuilder() // ensure that only JWT will be used against the tests below - .withPassword(null, null).withJwtToken("bogus"); + .withPassword(null, null) + .withJwtToken("bogus"); } @Test @@ -101,7 +102,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest { permissions.put("metadata", GHPermissionType.READ); GHAppInstallationToken installationToken = installation.createToken(permissions) - .repositoryIds(Arrays.asList((long) 111111111)).create(); + .repositoryIds(Arrays.asList((long) 111111111)) + .create(); assertThat(installationToken.getToken(), is("bogus")); assertThat(installation.getPermissions(), is(permissions)); diff --git a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java index 8717d6775..ee6c62695 100644 --- a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java +++ b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java @@ -48,9 +48,14 @@ public class GHBranchProtectionTest extends AbstractGitHubApiTestBase { @Test public void testEnableBranchProtections() throws Exception { // team/user restrictions require an organization repo to test against - GHBranchProtection protection = branch.enableProtection().addRequiredChecks("test-status-check") - .requireBranchIsUpToDate().requireCodeOwnReviews().dismissStaleReviews().requiredReviewers(2) - .includeAdmins().enable(); + GHBranchProtection protection = branch.enableProtection() + .addRequiredChecks("test-status-check") + .requireBranchIsUpToDate() + .requireCodeOwnReviews() + .dismissStaleReviews() + .requiredReviewers(2) + .includeAdmins() + .enable(); RequiredStatusChecks statusChecks = protection.getRequiredStatusChecks(); assertNotNull(statusChecks); diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 32e0f0090..4b4b59135 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -73,7 +72,8 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest { @Test public void testCRUDContent() throws Exception { GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", - "Creating a file for integration tests.", createdFilename); + "Creating a file for integration tests.", + createdFilename); GHContent createdContent = created.getContent(); assertNotNull(created.getCommit()); diff --git a/src/test/java/org/kohsuke/github/GHDeploymentTest.java b/src/test/java/org/kohsuke/github/GHDeploymentTest.java index 1c228c7aa..b2dc602b1 100644 --- a/src/test/java/org/kohsuke/github/GHDeploymentTest.java +++ b/src/test/java/org/kohsuke/github/GHDeploymentTest.java @@ -3,6 +3,7 @@ package org.kohsuke.github; import org.junit.Test; import java.io.IOException; + import static org.junit.Assert.assertNotNull; /** diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 4f3b92a07..481396a48 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -14,8 +14,8 @@ public class GHEventPayloadTest { @Test public void commit_comment() throws Exception { - GHEventPayload.CommitComment event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.CommitComment.class); + GHEventPayload.CommitComment event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.CommitComment.class); assertThat(event.getAction(), is("created")); assertThat(event.getComment().getSHA1(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b")); assertThat(event.getComment().getUser().getLogin(), is("baxterthehacker")); @@ -26,8 +26,8 @@ public class GHEventPayloadTest { @Test public void create() throws Exception { - GHEventPayload.Create event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.Create.class); + GHEventPayload.Create event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Create.class); assertThat(event.getRef(), is("0.0.1")); assertThat(event.getRefType(), is("tag")); assertThat(event.getMasterBranch(), is("master")); @@ -39,8 +39,8 @@ public class GHEventPayloadTest { @Test public void delete() throws Exception { - GHEventPayload.Delete event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.Delete.class); + GHEventPayload.Delete event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Delete.class); assertThat(event.getRef(), is("simple-tag")); assertThat(event.getRefType(), is("tag")); assertThat(event.getRepository().getName(), is("public-repo")); @@ -50,8 +50,8 @@ public class GHEventPayloadTest { @Test public void deployment() throws Exception { - GHEventPayload.Deployment event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.Deployment.class); + GHEventPayload.Deployment event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Deployment.class); assertThat(event.getDeployment().getSha(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b")); assertThat(event.getDeployment().getEnvironment(), is("production")); assertThat(event.getDeployment().getCreator().getLogin(), is("baxterthehacker")); @@ -62,8 +62,8 @@ public class GHEventPayloadTest { @Test public void deployment_status() throws Exception { - GHEventPayload.DeploymentStatus event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.DeploymentStatus.class); + GHEventPayload.DeploymentStatus event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.DeploymentStatus.class); assertThat(event.getDeploymentStatus().getState(), is(GHDeploymentState.SUCCESS)); assertThat(event.getDeploymentStatus().getTargetUrl(), nullValue()); assertThat(event.getDeployment().getSha(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b")); @@ -104,8 +104,8 @@ public class GHEventPayloadTest { @Test public void issue_comment() throws Exception { - GHEventPayload.IssueComment event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.IssueComment.class); + GHEventPayload.IssueComment event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.IssueComment.class); assertThat(event.getAction(), is("created")); assertThat(event.getIssue().getNumber(), is(2)); assertThat(event.getIssue().getTitle(), is("Spelling error in the README file")); @@ -156,8 +156,8 @@ public class GHEventPayloadTest { @Test @Payload("public") public void public_() throws Exception { - GHEventPayload.Public event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.Public.class); + GHEventPayload.Public event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Public.class); assertThat(event.getRepository().getName(), is("public-repo")); assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker")); assertThat(event.getSender().getLogin(), is("baxterthehacker")); @@ -165,8 +165,8 @@ public class GHEventPayloadTest { @Test public void pull_request() throws Exception { - GHEventPayload.PullRequest event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.PullRequest.class); + GHEventPayload.PullRequest event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class); assertThat(event.getAction(), is("opened")); assertThat(event.getNumber(), is(1)); assertThat(event.getPullRequest().getNumber(), is(1)); @@ -198,8 +198,8 @@ public class GHEventPayloadTest { @Test public void pull_request_review() throws Exception { - GHEventPayload.PullRequestReview event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.PullRequestReview.class); + GHEventPayload.PullRequestReview event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.PullRequestReview.class); assertThat(event.getAction(), is("submitted")); assertThat(event.getReview().getId(), is(2626884L)); @@ -227,8 +227,8 @@ public class GHEventPayloadTest { @Test public void pull_request_review_comment() throws Exception { - GHEventPayload.PullRequestReviewComment event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.PullRequestReviewComment.class); + GHEventPayload.PullRequestReviewComment event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.PullRequestReviewComment.class); assertThat(event.getAction(), is("created")); assertThat(event.getComment().getBody(), is("Maybe you should use more emojji on this line.")); @@ -285,8 +285,8 @@ public class GHEventPayloadTest { @Test public void repository() throws Exception { - GHEventPayload.Repository event = GitHub.offline().parseEventPayload(payload.asReader(), - GHEventPayload.Repository.class); + GHEventPayload.Repository event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Repository.class); assertThat(event.getAction(), is("created")); assertThat(event.getRepository().getName(), is("new-repository")); assertThat(event.getRepository().getOwner().getLogin(), is("baxterandthehackers")); diff --git a/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java b/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java index 89d5b0f3e..83156723f 100644 --- a/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java +++ b/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java @@ -21,9 +21,13 @@ public class GHGistUpdaterTest extends AbstractGitHubWireMockTest { @Before public void setUp() throws IOException { GHGistBuilder builder = new GHGistBuilder(gitHub); - gist = builder.description("Test for the API").file("unmodified.txt", "Should be unmodified") + gist = builder.description("Test for the API") + .file("unmodified.txt", "Should be unmodified") // .file("delete-me.txt", "To be deleted") - .file("rename-me.py", "print 'hello'").file("update-me.txt", "To be updated").public_(true).create(); + .file("rename-me.py", "print 'hello'") + .file("update-me.txt", "To be updated") + .public_(true) + .create(); } @After @@ -42,7 +46,8 @@ public class GHGistUpdaterTest extends AbstractGitHubWireMockTest { GHGist updatedGist = updater.description("Description updated by API") .addFile("new-file.txt", "Added by updater") // .deleteFile("delete-me.txt") - .renameFile("rename-me.py", "renamed.py").updateFile("update-me.txt", "Content updated by API") + .renameFile("rename-me.py", "renamed.py") + .updateFile("update-me.txt", "Content updated by API") .update(); assertEquals("Description updated by API", updatedGist.getDescription()); diff --git a/src/test/java/org/kohsuke/github/GHHookTest.java b/src/test/java/org/kohsuke/github/GHHookTest.java index 6fee386ca..d52709782 100644 --- a/src/test/java/org/kohsuke/github/GHHookTest.java +++ b/src/test/java/org/kohsuke/github/GHHookTest.java @@ -13,7 +13,6 @@ import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.hasValue; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertThat; @@ -58,8 +57,8 @@ public class GHHookTest { try { // fails because application isn't approved in organisation and you can find it only after doing real call - final GHHook hook = repository.createHook("my-hook", singletonMap("url", "http://localhost"), - singletonList(GHEvent.PUSH), true); + final GHHook hook = repository + .createHook("my-hook", singletonMap("url", "http://localhost"), singletonList(GHEvent.PUSH), true); } catch (IOException ex) { assertThat(ex, instanceOf(GHFileNotFoundException.class)); final GHFileNotFoundException ghFileNotFoundException = (GHFileNotFoundException) ex; diff --git a/src/test/java/org/kohsuke/github/GHIssueEventTest.java b/src/test/java/org/kohsuke/github/GHIssueEventTest.java index 82417e321..e65f7d59c 100644 --- a/src/test/java/org/kohsuke/github/GHIssueEventTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueEventTest.java @@ -1,8 +1,9 @@ package org.kohsuke.github; +import org.junit.Test; + import java.io.IOException; import java.util.List; -import org.junit.Test; /** * @author Martin van Zijl diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index d9f693ede..11d5adb66 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import com.jcraft.jsch.IO; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -33,8 +32,10 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest { GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); GHRepository repository = org.createRepository(GITHUB_API_TEST, - "a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", - "Core Developers", true); + "a test repository used to test kohsuke's github-api", + "http://github-api.kohsuke.org/", + "Core Developers", + true); Assert.assertNotNull(repository); } @@ -45,7 +46,9 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest { GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); GHRepository repository = org.createRepository(GITHUB_API_TEST) .description("a test repository used to test kohsuke's github-api") - .homepage("http://github-api.kohsuke.org/").team(org.getTeamByName("Core Developers")).autoInit(true) + .homepage("http://github-api.kohsuke.org/") + .team(org.getTeamByName("Core Developers")) + .autoInit(true) .create(); Assert.assertNotNull(repository); Assert.assertNotNull(repository.getReadme()); diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index 71ae5db66..4ee175090 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -85,8 +85,10 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { public void pullRequestReviews() throws Exception { String name = "testPullRequestReviews"; GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test"); - GHPullRequestReview draftReview = p.createReview().body("Some draft review") - .comment("Some niggle", "README.md", 1).create(); + GHPullRequestReview draftReview = p.createReview() + .body("Some draft review") + .comment("Some niggle", "README.md", 1) + .create(); assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING)); assertThat(draftReview.getBody(), is("Some draft review")); assertThat(draftReview.getCommitId(), notNullValue()); @@ -156,13 +158,17 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { int baseRequestCount = mockGitHub.getRequestCount(); p.refresh(); assertThat("We should not eagerly load organizations for teams", - mockGitHub.getRequestCount() - baseRequestCount, equalTo(1)); + mockGitHub.getRequestCount() - baseRequestCount, + equalTo(1)); assertThat(p.getRequestedTeams().size(), equalTo(1)); assertThat("We should not eagerly load organizations for teams", - mockGitHub.getRequestCount() - baseRequestCount, equalTo(1)); + mockGitHub.getRequestCount() - baseRequestCount, + equalTo(1)); assertThat("Org should be queried for automatically if asked for", - p.getRequestedTeams().get(0).getOrganization(), notNullValue()); - assertThat("Request count should show lazy load occurred", mockGitHub.getRequestCount() - baseRequestCount, + p.getRequestedTeams().get(0).getOrganization(), + notNullValue()); + assertThat("Request count should show lazy load occurred", + mockGitHub.getRequestCount() - baseRequestCount, equalTo(2)); } @@ -224,8 +230,13 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { GHContentUpdateResponse response = getRepository().createContent(name, name, name, branchName); Thread.sleep(1000); - getRepository().createContent().content(name + name).path(name).branch(branchName).message(name) - .sha(response.getContent().getSha()).commit(); + getRepository().createContent() + .content(name + name) + .path(name) + .branch(branchName) + .message(name) + .sha(response.getContent().getSha()) + .commit(); GHPullRequest p = getRepository().createPullRequest(name, branchName, "master", "## test squash"); Thread.sleep(1000); p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH); @@ -239,8 +250,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { repo.createPullRequest("queryPullRequestsQualifiedHead_rc", "test/rc", "master", null); // Query by one of the heads and make sure we only get that branch's PR back. - List prs = repo.queryPullRequests().state(GHIssueState.OPEN) - .head("github-api-test-org:test/stable").base("master").list().asList(); + List prs = repo.queryPullRequests() + .state(GHIssueState.OPEN) + .head("github-api-test-org:test/stable") + .base("master") + .list() + .asList(); assertNotNull(prs); assertEquals(1, prs.size()); assertEquals("test/stable", prs.get(0).getHead().getRef()); @@ -254,8 +269,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { repo.createPullRequest("queryPullRequestsUnqualifiedHead_rc", "test/rc", "master", null); // Query by one of the heads and make sure we only get that branch's PR back. - List prs = repo.queryPullRequests().state(GHIssueState.OPEN).head("test/stable").base("master") - .list().asList(); + List prs = repo.queryPullRequests() + .state(GHIssueState.OPEN) + .head("test/stable") + .base("master") + .list() + .asList(); assertNotNull(prs); assertEquals(1, prs.size()); assertEquals("test/stable", prs.get(0).getHead().getRef()); diff --git a/src/test/java/org/kohsuke/github/GHRateLimitTest.java b/src/test/java/org/kohsuke/github/GHRateLimitTest.java index bf7e49f1a..2aa9e78bf 100644 --- a/src/test/java/org/kohsuke/github/GHRateLimitTest.java +++ b/src/test/java/org/kohsuke/github/GHRateLimitTest.java @@ -2,16 +2,10 @@ package org.kohsuke.github; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; -import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; -import okhttp3.Cache; -import okhttp3.OkHttpClient; -import org.apache.commons.io.FileUtils; import org.hamcrest.CoreMatchers; -import org.junit.Before; import org.junit.Test; import org.kohsuke.github.extras.okhttp3.OkHttpConnector; -import java.io.File; import java.io.IOException; import java.util.Date; diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index ca3e14573..64a738fdc 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -11,7 +11,6 @@ import java.util.List; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; /** * @author Liam Newman @@ -197,8 +196,11 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { @Test public void searchRepositories() throws Exception { - PagedSearchIterable r = gitHub.searchRepositories().q("tetris").language("assembly") - .sort(GHRepositorySearchBuilder.Sort.STARS).list(); + PagedSearchIterable r = gitHub.searchRepositories() + .q("tetris") + .language("assembly") + .sort(GHRepositorySearchBuilder.Sort.STARS) + .list(); GHRepository u = r.iterator().next(); // System.out.println(u.getName()); assertNotNull(u.getId()); @@ -279,7 +281,8 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { topics.add("java"); topics.add("api-test-dummy"); repo.setTopics(topics); - assertThat("Topics retain input order (are not sort when stored)", repo.listTopics(), + assertThat("Topics retain input order (are not sort when stored)", + repo.listTopics(), contains("java", "api-test-dummy")); topics = new ArrayList<>(); @@ -287,18 +290,20 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest { topics.add("api-test-dummy"); topics.add("java"); repo.setTopics(topics); - assertThat("Topics behave as a set and retain order from previous calls", repo.listTopics(), + assertThat("Topics behave as a set and retain order from previous calls", + repo.listTopics(), contains("java", "api-test-dummy", "ordered-state")); topics = new ArrayList<>(); topics.add("ordered-state"); topics.add("api-test-dummy"); repo.setTopics(topics); - assertThat("Topics retain order even when some are removed", repo.listTopics(), + assertThat("Topics retain order even when some are removed", + repo.listTopics(), contains("api-test-dummy", "ordered-state")); topics = new ArrayList<>(); repo.setTopics(topics); assertTrue("Topics can be set to empty", repo.listTopics().isEmpty()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index 8fbe267ab..742d89a3b 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -3,7 +3,6 @@ package org.kohsuke.github; import org.junit.Test; import java.io.IOException; -import java.util.Random; public class GHTeamTest extends AbstractGitHubWireMockTest { diff --git a/src/test/java/org/kohsuke/github/GistTest.java b/src/test/java/org/kohsuke/github/GistTest.java index ed11bc528..117a76d6a 100644 --- a/src/test/java/org/kohsuke/github/GistTest.java +++ b/src/test/java/org/kohsuke/github/GistTest.java @@ -1,11 +1,9 @@ package org.kohsuke.github; -import com.github.tomakehurst.wiremock.stubbing.Scenario; import org.junit.Test; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.hamcrest.Matchers.notNullValue; - import static org.hamcrest.core.Is.is; /** diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 83bed2f04..8066dd9f1 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -1,7 +1,5 @@ package org.kohsuke.github; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import org.eclipse.jgit.api.Git; import org.junit.Assert; import org.junit.Test; diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index f89d1faa5..6b4d3b7a0 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -1,12 +1,12 @@ package org.kohsuke.github; -import java.io.IOException; -import java.util.*; - import com.google.common.collect.Iterables; import org.junit.Test; import org.kohsuke.github.example.dataobject.ReadOnlyObjects; +import java.io.IOException; +import java.util.*; + import static org.hamcrest.CoreMatchers.*; /** diff --git a/src/test/java/org/kohsuke/github/Github2faTest.java b/src/test/java/org/kohsuke/github/Github2faTest.java index 7681a5068..fb3c9cb6b 100644 --- a/src/test/java/org/kohsuke/github/Github2faTest.java +++ b/src/test/java/org/kohsuke/github/Github2faTest.java @@ -1,11 +1,11 @@ package org.kohsuke.github; +import org.junit.Test; + import java.io.IOException; import java.util.Arrays; import java.util.List; -import org.junit.Test; - /** * @author Kevin Harrington mad.hephaestus@gmail.com */ diff --git a/src/test/java/org/kohsuke/github/LifecycleTest.java b/src/test/java/org/kohsuke/github/LifecycleTest.java index ad892a1de..fc8ed6424 100644 --- a/src/test/java/org/kohsuke/github/LifecycleTest.java +++ b/src/test/java/org/kohsuke/github/LifecycleTest.java @@ -25,19 +25,30 @@ public class LifecycleTest extends AbstractGitHubApiTestBase { repository.delete(); Thread.sleep(1000); } - repository = org.createRepository("github-api-test", "a test repository used to test kohsuke's github-api", - "http://github-api.kohsuke.org/", "Core Developers", true); + repository = org.createRepository("github-api-test", + "a test repository used to test kohsuke's github-api", + "http://github-api.kohsuke.org/", + "Core Developers", + true); Thread.sleep(1000); // wait for the repository to become ready assertTrue(repository.getReleases().isEmpty()); try { GHMilestone milestone = repository.createMilestone("Initial Release", "first one"); - GHIssue issue = repository.createIssue("Test Issue").body("issue body just for grins").milestone(milestone) - .assignee(myself).label("bug").create(); + GHIssue issue = repository.createIssue("Test Issue") + .body("issue body just for grins") + .milestone(milestone) + .assignee(myself) + .label("bug") + .create(); File repoDir = new File(System.getProperty("java.io.tmpdir"), "github-api-test"); delete(repoDir); - Git origin = Git.cloneRepository().setBare(false).setURI(repository.getSshUrl()).setDirectory(repoDir) - .setCredentialsProvider(getCredentialsProvider(myself)).call(); + Git origin = Git.cloneRepository() + .setBare(false) + .setURI(repository.getSshUrl()) + .setDirectory(repoDir) + .setCredentialsProvider(getCredentialsProvider(myself)) + .call(); commitTestFile(myself, repoDir, origin); @@ -74,8 +85,10 @@ public class LifecycleTest extends AbstractGitHubApiTestBase { } private GHRelease createRelease(GHRepository repository) throws IOException { - GHRelease builder = repository.createRelease("release_tag").name("Test Release") - .body("How exciting! To be able to programmatically create releases is a dream come true!").create(); + GHRelease builder = repository.createRelease("release_tag") + .name("Test Release") + .body("How exciting! To be able to programmatically create releases is a dream come true!") + .create(); List releases = repository.getReleases(); assertEquals(1, releases.size()); GHRelease release = releases.get(0); diff --git a/src/test/java/org/kohsuke/github/PayloadRule.java b/src/test/java/org/kohsuke/github/PayloadRule.java index 6a24a8e5c..063441ccc 100644 --- a/src/test/java/org/kohsuke/github/PayloadRule.java +++ b/src/test/java/org/kohsuke/github/PayloadRule.java @@ -1,5 +1,10 @@ package org.kohsuke.github; +import org.apache.commons.io.IOUtils; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -7,11 +12,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; -import org.apache.commons.io.IOUtils; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - /** * @author Stephen Connolly */ @@ -44,7 +44,8 @@ public class PayloadRule implements TestRule { } public InputStream asInputStream() throws FileNotFoundException { - String name = resourceName.startsWith("/") ? resourceName + type + String name = resourceName.startsWith("/") + ? resourceName + type : testClass.getSimpleName() + "/" + resourceName + type; InputStream stream = testClass.getResourceAsStream(name); if (stream == null) { diff --git a/src/test/java/org/kohsuke/github/RepositoryMockTest.java b/src/test/java/org/kohsuke/github/RepositoryMockTest.java index 5805ba66e..6e8969ada 100644 --- a/src/test/java/org/kohsuke/github/RepositoryMockTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryMockTest.java @@ -39,7 +39,7 @@ public class RepositoryMockTest { user2.login = "login2"; when(iterator.hasNext()).thenReturn(true, false, true); - when(iterator.next()).thenReturn(new GHUser[] { user1 }, new GHUser[] { user2 }); + when(iterator.next()).thenReturn(new GHUser[]{ user1 }, new GHUser[]{ user2 }); Requester requester = Mockito.mock(Requester.class); when(mockGitHub.retrieve()).thenReturn(requester); diff --git a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java index b921d5ea4..4ba98b0a7 100644 --- a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java @@ -91,7 +91,8 @@ public class RepositoryTrafficTest extends AbstractGitHubApiTestBase { @Test public void testGetViews() throws IOException { - GHRepositoryViewTraffic expectedResult = new GHRepositoryViewTraffic(21523359, 65534, + GHRepositoryViewTraffic expectedResult = new GHRepositoryViewTraffic(21523359, + 65534, Arrays.asList(new GHRepositoryViewTraffic.DailyInfo("2016-10-10T00:00:00Z", 3, 2), new GHRepositoryViewTraffic.DailyInfo("2016-10-11T00:00:00Z", 9, 4), new GHRepositoryViewTraffic.DailyInfo("2016-10-12T00:00:00Z", 27, 8), @@ -112,7 +113,8 @@ public class RepositoryTrafficTest extends AbstractGitHubApiTestBase { @Test public void testGetClones() throws IOException { - GHRepositoryCloneTraffic expectedResult = new GHRepositoryCloneTraffic(1500, 455, + GHRepositoryCloneTraffic expectedResult = new GHRepositoryCloneTraffic(1500, + 455, Arrays.asList(new GHRepositoryCloneTraffic.DailyInfo("2016-10-10T00:00:00Z", 10, 3), new GHRepositoryCloneTraffic.DailyInfo("2016-10-11T00:00:00Z", 20, 6), new GHRepositoryCloneTraffic.DailyInfo("2016-10-12T00:00:00Z", 30, 5), diff --git a/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java b/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java index 975881ac7..843becc14 100644 --- a/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java +++ b/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import org.kohsuke.github.junit.WireMockRule; import org.hamcrest.Matchers; import org.junit.Ignore; import org.junit.Test; @@ -25,7 +24,8 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest { assertThat( "GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_USER and GITHUB_PASSWORD environment variables", - gitHub.isAnonymous(), is(false)); + gitHub.isAnonymous(), + is(false)); assertThat(gitHub.login, not(equalTo(STUBBED_USER_LOGIN))); @@ -80,7 +80,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest { e = ex; } - assertThat(e, Matchers. instanceOf(GHFileNotFoundException.class)); + assertThat(e, Matchers.instanceOf(GHFileNotFoundException.class)); assertThat(e.getMessage(), containsString("Request was not matched")); // Invalid repository, without stub - fails 404 when not proxying @@ -92,7 +92,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest { e = ex; } - assertThat(e, Matchers. instanceOf(GHFileNotFoundException.class)); + assertThat(e, Matchers.instanceOf(GHFileNotFoundException.class)); assertThat(e.getMessage(), containsString("Request was not matched")); } @@ -120,9 +120,9 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest { e = ex; } - assertThat(e, Matchers. instanceOf(GHFileNotFoundException.class)); - assertThat(e.getMessage(), equalTo( - "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/#get\"}")); + assertThat(e, Matchers.instanceOf(GHFileNotFoundException.class)); + assertThat(e.getMessage(), + equalTo("{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/#get\"}")); } @Test diff --git a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java index c9bdda95e..00f85bdfd 100644 --- a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java @@ -2,10 +2,9 @@ package org.kohsuke.github.extras; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; -import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; -import com.squareup.okhttp.OkUrlFactory; import com.squareup.okhttp.Cache; import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.OkUrlFactory; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Ignore; diff --git a/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java b/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java index 5992bf84c..a60221f8d 100644 --- a/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java @@ -108,7 +108,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest { OkHttpClient client = createClient(false); OkHttpConnector connector = new OkHttpConnector(client); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -133,7 +134,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(client, -1); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -163,7 +165,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(client, 3); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -187,7 +190,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest { OkHttpClient client = createClient(true); OkHttpConnector connector = new OkHttpConnector(client); - this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector) + this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withConnector(connector) .build(); doTestActions(); @@ -207,7 +211,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest { assertThat("Request Count", getRequestCount(), is(networkRequestCount + userRequestCount)); // Rate limit must be under this value, but if it wiggles we don't care - assertThat("Rate Limit Change", rateLimitBefore.remaining - rateLimitAfter.remaining, + assertThat("Rate Limit Change", + rateLimitBefore.remaining - rateLimitAfter.remaining, is(lessThanOrEqualTo(rateLimitUsed + userRequestCount))); } diff --git a/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java b/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java index 47600bf0a..e53f6e433 100644 --- a/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java +++ b/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java @@ -1,10 +1,8 @@ package org.kohsuke.github.junit; import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.client.VerificationException; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.core.Options; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.extension.Parameters; import com.github.tomakehurst.wiremock.extension.ResponseTransformer; @@ -12,11 +10,6 @@ import com.github.tomakehurst.wiremock.http.*; import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; import com.github.tomakehurst.wiremock.verification.*; import com.google.gson.*; -import org.junit.rules.MethodRule; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; import java.io.File; import java.io.IOException; @@ -24,7 +17,6 @@ import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; -import java.util.List; import java.util.Map; import static com.github.tomakehurst.wiremock.client.WireMock.*; @@ -94,11 +86,15 @@ public class GitHubWireMockRule extends WireMockMultiServerRule { protected void after() { super.after(); if (isTakeSnapshot()) { - this.apiServer().snapshotRecord(recordSpec().forTarget("https://api.github.com") - .captureHeader("If-None-Match").extractTextBodiesOver(255)); + this.apiServer() + .snapshotRecord(recordSpec().forTarget("https://api.github.com") + .captureHeader("If-None-Match") + .extractTextBodiesOver(255)); - this.rawServer().snapshotRecord(recordSpec().forTarget("https://raw.githubusercontent.com") - .captureHeader("If-None-Match").extractTextBodiesOver(255)); + this.rawServer() + .snapshotRecord(recordSpec().forTarget("https://raw.githubusercontent.com") + .captureHeader("If-None-Match") + .extractTextBodiesOver(255)); // After taking the snapshot, format the output formatJsonFiles(new File(this.apiServer().getOptions().filesRoot().getPath()).toPath()); @@ -118,7 +114,10 @@ public class GitHubWireMockRule extends WireMockMultiServerRule { private void formatJsonFiles(Path path) { // The more consistent we can make the json output the more meaningful it will be. - Gson g = new Gson().newBuilder().serializeNulls().disableHtmlEscaping().setPrettyPrinting() + Gson g = new Gson().newBuilder() + .serializeNulls() + .disableHtmlEscaping() + .setPrettyPrinting() .registerTypeAdapter(Double.class, new JsonSerializer() { @Override public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { @@ -128,7 +127,8 @@ public class GitHubWireMockRule extends WireMockMultiServerRule { return new JsonPrimitive(src.longValue()); return new JsonPrimitive(src); } - }).create(); + }) + .create(); try { Files.walk(path).forEach(filePath -> { diff --git a/src/test/java/org/kohsuke/github/junit/WireMockMultiServerRule.java b/src/test/java/org/kohsuke/github/junit/WireMockMultiServerRule.java index f11b4ca02..81e1a958d 100644 --- a/src/test/java/org/kohsuke/github/junit/WireMockMultiServerRule.java +++ b/src/test/java/org/kohsuke/github/junit/WireMockMultiServerRule.java @@ -88,7 +88,8 @@ public class WireMockMultiServerRule implements MethodRule, TestRule { directoryName += "_" + serverId; } - final Options localOptions = new WireMockRuleConfiguration(WireMockMultiServerRule.this.options, directoryName, + final Options localOptions = new WireMockRuleConfiguration(WireMockMultiServerRule.this.options, + directoryName, extensions); new File(localOptions.filesRoot().getPath(), "mappings").mkdirs(); diff --git a/src/test/java/org/kohsuke/github/junit/WireMockRule.java b/src/test/java/org/kohsuke/github/junit/WireMockRule.java index 2f5dc3c3f..4ddc9d00b 100644 --- a/src/test/java/org/kohsuke/github/junit/WireMockRule.java +++ b/src/test/java/org/kohsuke/github/junit/WireMockRule.java @@ -7,14 +7,9 @@ import com.github.tomakehurst.wiremock.client.VerificationException; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.common.*; import com.github.tomakehurst.wiremock.core.*; -import com.github.tomakehurst.wiremock.extension.Extension; import com.github.tomakehurst.wiremock.global.GlobalSettings; import com.github.tomakehurst.wiremock.global.GlobalSettingsHolder; -import com.github.tomakehurst.wiremock.http.CaseInsensitiveKey; -import com.github.tomakehurst.wiremock.http.HttpServerFactory; import com.github.tomakehurst.wiremock.http.RequestListener; -import com.github.tomakehurst.wiremock.http.ThreadPoolFactory; -import com.github.tomakehurst.wiremock.http.trafficlistener.WiremockNetworkTrafficListener; import com.github.tomakehurst.wiremock.junit.Stubbing; import com.github.tomakehurst.wiremock.matching.RequestPattern; import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; @@ -23,27 +18,20 @@ import com.github.tomakehurst.wiremock.recording.RecordSpec; import com.github.tomakehurst.wiremock.recording.RecordSpecBuilder; import com.github.tomakehurst.wiremock.recording.RecordingStatusResult; import com.github.tomakehurst.wiremock.recording.SnapshotRecordResult; -import com.github.tomakehurst.wiremock.security.Authenticator; -import com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource; import com.github.tomakehurst.wiremock.standalone.MappingsLoader; -import com.github.tomakehurst.wiremock.standalone.MappingsSource; import com.github.tomakehurst.wiremock.stubbing.ServeEvent; import com.github.tomakehurst.wiremock.stubbing.StubImport; import com.github.tomakehurst.wiremock.stubbing.StubMapping; import com.github.tomakehurst.wiremock.verification.*; - -import java.io.File; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import com.github.tomakehurst.wiremock.verification.notmatched.NotMatchedRenderer; import org.junit.rules.MethodRule; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; -import wiremock.com.google.common.base.Optional; + +import java.io.File; +import java.util.List; +import java.util.UUID; /** * @author Liam Newman