diff --git a/pom.xml b/pom.xml index b033dfd3..2fc0fb3d 100644 --- a/pom.xml +++ b/pom.xml @@ -93,15 +93,15 @@ 32.1.3-jre 3.0.2 1.1.1 - 4.13.1 + 5.10.0 1.7.36 - 3.2.4 + 5.6.0 2.6 2.15.3 2.9.3 - 2.0.2 - 3.0.1 + 3.3 0.31.1 + 4.11.0 ${project.groupId}.githubclient.shade @@ -137,7 +137,7 @@ com.squareup.okhttp3 okhttp - 3.14.7 + ${okhttp.version} org.slf4j @@ -210,17 +210,18 @@ test - junit - junit + org.junit.jupiter + junit-jupiter-engine ${junit.version} test org.junit.jupiter - junit-jupiter-engine - 5.5.0 + junit-jupiter-api + ${junit.version} test + org.mockito mockito-core @@ -242,32 +243,8 @@ com.squareup.okhttp3 mockwebserver - 3.14.7 - test - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.mockito - mockito-core - - - - - org.powermock - powermock-api-mockito2 - ${powermock.version} + ${okhttp.version} test - - - org.mockito - mockito-core - - commons-io @@ -409,7 +386,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.19.1 + 3.2.1 maven-jar-plugin diff --git a/src/test/java/com/spotify/github/GitHubInstantTest.java b/src/test/java/com/spotify/github/GitHubInstantTest.java index 32fc51ff..8d8e8428 100644 --- a/src/test/java/com/spotify/github/GitHubInstantTest.java +++ b/src/test/java/com/spotify/github/GitHubInstantTest.java @@ -25,7 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import java.time.Instant; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GitHubInstantTest { diff --git a/src/test/java/com/spotify/github/hooks/PullRequestEventTest.java b/src/test/java/com/spotify/github/hooks/PullRequestEventTest.java index 29e4e422..c6b8163d 100644 --- a/src/test/java/com/spotify/github/hooks/PullRequestEventTest.java +++ b/src/test/java/com/spotify/github/hooks/PullRequestEventTest.java @@ -27,7 +27,7 @@ import com.spotify.github.jackson.Json; import com.spotify.github.v3.activity.events.PullRequestEvent; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PullRequestEventTest { diff --git a/src/test/java/com/spotify/github/http/LinkTest.java b/src/test/java/com/spotify/github/http/LinkTest.java index 70d42edc..975934e6 100644 --- a/src/test/java/com/spotify/github/http/LinkTest.java +++ b/src/test/java/com/spotify/github/http/LinkTest.java @@ -26,7 +26,7 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LinkTest { diff --git a/src/test/java/com/spotify/github/jackson/GitHubInstantModuleTest.java b/src/test/java/com/spotify/github/jackson/GitHubInstantModuleTest.java index ddf60b36..7432720e 100644 --- a/src/test/java/com/spotify/github/jackson/GitHubInstantModuleTest.java +++ b/src/test/java/com/spotify/github/jackson/GitHubInstantModuleTest.java @@ -26,14 +26,14 @@ import com.spotify.github.GitHubInstant; import java.io.IOException; import java.time.Instant; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class GitHubInstantModuleTest { private Json mapper; - @Before + @BeforeEach public void setUp() throws Exception { mapper = Json.create(); } diff --git a/src/test/java/com/spotify/github/opencensus/OpenCensusSpanTest.java b/src/test/java/com/spotify/github/opencensus/OpenCensusSpanTest.java index 73f9c354..1a7bbcc3 100644 --- a/src/test/java/com/spotify/github/opencensus/OpenCensusSpanTest.java +++ b/src/test/java/com/spotify/github/opencensus/OpenCensusSpanTest.java @@ -26,7 +26,6 @@ import io.opencensus.trace.Status; import org.junit.jupiter.api.Test; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/src/test/java/com/spotify/github/opencensus/OpenCensusTracerTest.java b/src/test/java/com/spotify/github/opencensus/OpenCensusTracerTest.java index add341d6..27b5c52b 100644 --- a/src/test/java/com/spotify/github/opencensus/OpenCensusTracerTest.java +++ b/src/test/java/com/spotify/github/opencensus/OpenCensusTracerTest.java @@ -28,11 +28,9 @@ import io.opencensus.trace.export.SpanData; import io.opencensus.trace.samplers.Samplers; import io.opencensus.trace.unsafe.ContextUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -115,13 +113,13 @@ private SpanData findSpan(final List spans, final String name) { return spans.stream().filter(s -> s.getName().equals(name)).findFirst().get(); } - @Before + @BeforeEach public void setUpExporter() { spanExporterHandler = new TestExportHandler(); Tracing.getExportComponent().getSpanExporter().registerHandler("test", spanExporterHandler); } - @BeforeClass + @BeforeAll public static void setupTracing() { final TraceConfig traceConfig = Tracing.getTraceConfig(); final Sampler sampler = Samplers.alwaysSample(); diff --git a/src/test/java/com/spotify/github/v3/TeamTest.java b/src/test/java/com/spotify/github/v3/TeamTest.java index 95cbd94a..d6c48f0c 100644 --- a/src/test/java/com/spotify/github/v3/TeamTest.java +++ b/src/test/java/com/spotify/github/v3/TeamTest.java @@ -29,9 +29,8 @@ import com.spotify.github.jackson.Json; import java.io.IOException; import java.net.URI; -import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TeamTest { @@ -50,7 +49,7 @@ public static final void assertTeam(final Team team) { assertThat(team.repositoriesUrl(), is(URI.create(team.url() + "/repos"))); } - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "team.json"), defaultCharset()); } diff --git a/src/test/java/com/spotify/github/v3/TreeItemTest.java b/src/test/java/com/spotify/github/v3/TreeItemTest.java index 9f48a012..4d9c71c4 100644 --- a/src/test/java/com/spotify/github/v3/TreeItemTest.java +++ b/src/test/java/com/spotify/github/v3/TreeItemTest.java @@ -29,8 +29,8 @@ import com.spotify.github.jackson.Json; import com.spotify.github.v3.git.TreeItem; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TreeItemTest { @@ -42,7 +42,7 @@ public static final void assertTreeItem(final TreeItem treeItem) { assertThat(treeItem.size(), is(12L)); } - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "treeItem.json"), defaultCharset()); } diff --git a/src/test/java/com/spotify/github/v3/UserTest.java b/src/test/java/com/spotify/github/v3/UserTest.java index 3d268cb1..4e9578d2 100644 --- a/src/test/java/com/spotify/github/v3/UserTest.java +++ b/src/test/java/com/spotify/github/v3/UserTest.java @@ -30,8 +30,8 @@ import java.io.IOException; import java.net.URI; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class UserTest { @@ -50,7 +50,7 @@ public static final void assertUser(final User user) { assertThat(user.siteAdmin().get(), is(false)); } - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "user.json"), defaultCharset()); } diff --git a/src/test/java/com/spotify/github/v3/activity/events/CheckRunEventTest.java b/src/test/java/com/spotify/github/v3/activity/events/CheckRunEventTest.java index 61fee8c7..3ba9e507 100644 --- a/src/test/java/com/spotify/github/v3/activity/events/CheckRunEventTest.java +++ b/src/test/java/com/spotify/github/v3/activity/events/CheckRunEventTest.java @@ -29,8 +29,7 @@ import com.spotify.github.jackson.Json; import java.io.IOException; - -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CheckRunEventTest { diff --git a/src/test/java/com/spotify/github/v3/activity/events/PullRequestEventTest.java b/src/test/java/com/spotify/github/v3/activity/events/PullRequestEventTest.java index b558428d..f07bc2ca 100644 --- a/src/test/java/com/spotify/github/v3/activity/events/PullRequestEventTest.java +++ b/src/test/java/com/spotify/github/v3/activity/events/PullRequestEventTest.java @@ -29,7 +29,7 @@ import com.spotify.github.jackson.Json; import com.spotify.github.v3.prs.PullRequestActionState; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PullRequestEventTest { diff --git a/src/test/java/com/spotify/github/v3/activity/events/PullRequestReviewEventTest.java b/src/test/java/com/spotify/github/v3/activity/events/PullRequestReviewEventTest.java index ec4640ae..b71ede72 100644 --- a/src/test/java/com/spotify/github/v3/activity/events/PullRequestReviewEventTest.java +++ b/src/test/java/com/spotify/github/v3/activity/events/PullRequestReviewEventTest.java @@ -28,7 +28,7 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PullRequestReviewEventTest { @Test diff --git a/src/test/java/com/spotify/github/v3/activity/events/StatusEventTest.java b/src/test/java/com/spotify/github/v3/activity/events/StatusEventTest.java index 0a686533..2a195d41 100644 --- a/src/test/java/com/spotify/github/v3/activity/events/StatusEventTest.java +++ b/src/test/java/com/spotify/github/v3/activity/events/StatusEventTest.java @@ -28,7 +28,7 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StatusEventTest { @Test diff --git a/src/test/java/com/spotify/github/v3/checks/AccessTokenTest.java b/src/test/java/com/spotify/github/v3/checks/AccessTokenTest.java index 0d62c6ff..0e404040 100644 --- a/src/test/java/com/spotify/github/v3/checks/AccessTokenTest.java +++ b/src/test/java/com/spotify/github/v3/checks/AccessTokenTest.java @@ -27,7 +27,7 @@ import com.spotify.github.jackson.Json; import java.io.IOException; import java.time.ZonedDateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AccessTokenTest { private final Json json = Json.create(); diff --git a/src/test/java/com/spotify/github/v3/checks/AnnotationTest.java b/src/test/java/com/spotify/github/v3/checks/AnnotationTest.java index 934b0426..46730a28 100644 --- a/src/test/java/com/spotify/github/v3/checks/AnnotationTest.java +++ b/src/test/java/com/spotify/github/v3/checks/AnnotationTest.java @@ -22,14 +22,14 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import com.spotify.github.jackson.Json; import com.spotify.github.v3.checks.ImmutableAnnotation.Builder; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AnnotationTest { private Builder builder() { @@ -88,16 +88,16 @@ public void serializesWithEmptyFields() { @Test public void clearsColumnFieldsForMultiLineAnnotation() { Annotation multiLineAnnotation = builder().startLine(1).endLine(2).build(); - assertTrue(multiLineAnnotation.startColumn().isEmpty()); - assertTrue(multiLineAnnotation.endColumn().isEmpty()); + Assertions.assertTrue(multiLineAnnotation.startColumn().isEmpty()); + Assertions.assertTrue(multiLineAnnotation.endColumn().isEmpty()); Annotation anotherMultiLineAnnotation = builder().startLine(1).endLine(2).startColumn(Optional.empty()).endColumn(1).build(); - assertTrue(anotherMultiLineAnnotation.startColumn().isEmpty()); - assertTrue(anotherMultiLineAnnotation.endColumn().isEmpty()); + Assertions.assertTrue(anotherMultiLineAnnotation.startColumn().isEmpty()); + Assertions.assertTrue(anotherMultiLineAnnotation.endColumn().isEmpty()); Annotation yetAnotherMultiLineAnnotation = builder().startLine(1).endLine(2).startColumn(1).endColumn(Optional.empty()).build(); - assertTrue(yetAnotherMultiLineAnnotation.startColumn().isEmpty()); - assertTrue(yetAnotherMultiLineAnnotation.endColumn().isEmpty()); + Assertions.assertTrue(yetAnotherMultiLineAnnotation.startColumn().isEmpty()); + Assertions.assertTrue(yetAnotherMultiLineAnnotation.endColumn().isEmpty()); Annotation singleLineAnnotation = builder().startLine(1).endLine(1).build(); assertEquals(1, singleLineAnnotation.startColumn().orElse(0)); diff --git a/src/test/java/com/spotify/github/v3/checks/CheckRunActionTest.java b/src/test/java/com/spotify/github/v3/checks/CheckRunActionTest.java index 2e7bbe0d..49d487b9 100644 --- a/src/test/java/com/spotify/github/v3/checks/CheckRunActionTest.java +++ b/src/test/java/com/spotify/github/v3/checks/CheckRunActionTest.java @@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import com.spotify.github.v3.checks.ImmutableCheckRunAction.Builder; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CheckRunActionTest { private Builder builder() { diff --git a/src/test/java/com/spotify/github/v3/checks/CheckRunOutputTest.java b/src/test/java/com/spotify/github/v3/checks/CheckRunOutputTest.java index e8658c90..1bf0cfaa 100644 --- a/src/test/java/com/spotify/github/v3/checks/CheckRunOutputTest.java +++ b/src/test/java/com/spotify/github/v3/checks/CheckRunOutputTest.java @@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import com.spotify.github.v3.checks.ImmutableCheckRunOutput.Builder; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CheckRunOutputTest { diff --git a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java index 443a6fe4..8da6ab50 100644 --- a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java +++ b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java @@ -39,7 +39,7 @@ public void testDeserialization() throws IOException { Resources.toString( getResource(this.getClass(), "check-suites-response.json"), defaultCharset()); final CheckSuiteResponseList checkSuiteResponseList = Json.create().fromJson(fixture, CheckSuiteResponseList.class); - assertThat(checkSuiteResponseList.checkSuites().get(0).id(), is(5)); + assertThat(checkSuiteResponseList.checkSuites().get(0).id(), is(5L)); assertThat(checkSuiteResponseList.checkSuites().get(0).app().get().slug().get(), is("octoapp")); } diff --git a/src/test/java/com/spotify/github/v3/clients/ChecksClientTest.java b/src/test/java/com/spotify/github/v3/clients/ChecksClientTest.java index 04615e25..8c137faa 100644 --- a/src/test/java/com/spotify/github/v3/clients/ChecksClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/ChecksClientTest.java @@ -43,8 +43,8 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.util.concurrent.CompletableFuture; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ChecksClientTest { @@ -61,7 +61,7 @@ public static String loadResource(final String path) { } } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); checksClient = new ChecksClient(github, "someowner", "somerepo"); diff --git a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java index 3874dd74..cc0bdd55 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java @@ -50,8 +50,8 @@ import java.time.Instant; import java.util.List; import java.util.concurrent.CompletableFuture; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class GitDataClientTest { @@ -63,7 +63,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(GitDataClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); gitDataClient = new GitDataClient(github, "someowner", "somerepo"); diff --git a/src/test/java/com/spotify/github/v3/clients/GitHubAuthTest.java b/src/test/java/com/spotify/github/v3/clients/GitHubAuthTest.java index d20edce2..c5308407 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitHubAuthTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitHubAuthTest.java @@ -22,12 +22,11 @@ import static com.spotify.github.v3.clients.ChecksClientTest.loadResource; import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.fasterxml.jackson.core.JsonProcessingException; import com.spotify.github.jackson.Json; @@ -44,9 +43,9 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class GitHubAuthTest { @@ -82,7 +81,7 @@ public class GitHubAuthTest { public GitHubAuthTest() throws JsonProcessingException {} - @Before + @BeforeEach public void setUp() throws IOException { client = new OkHttpClient.Builder() @@ -98,7 +97,7 @@ public void setUp() throws IOException { .createChecksApiClient(); } - @After + @AfterEach public void tearDown() throws IOException { mockServer.shutdown(); } @@ -261,10 +260,12 @@ public void assertNoPrivateKeyProvidedUsesAccessToken() throws Exception { assertThat(request.getMethod(), is("GET")); } - @Test(expected = IllegalArgumentException.class) + @Test public void assertNoTokenThrowsException() { final GitHubClient apiWithNoKey = GitHubClient.create(URI.create("someurl"), "a-token"); - apiWithNoKey.createRepositoryClient("foo", "bar").createChecksApiClient(); + assertThrows( + IllegalArgumentException.class, + () -> apiWithNoKey.createRepositoryClient("foo", "bar").createChecksApiClient()); } private AccessToken getTestInstallationToken() { diff --git a/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java b/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java index 64b24bc8..d030b17b 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java @@ -25,7 +25,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -49,8 +49,9 @@ import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class GitHubClientTest { @@ -63,13 +64,13 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(GitHubClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { client = mock(OkHttpClient.class); github = GitHubClient.create(client, URI.create("http://bogus"), "token"); } - @Test(expected = ReadOnlyRepositoryException.class) + @Test public void testSearchIssue() throws Throwable { final Call call = mock(Call.class); @@ -103,11 +104,10 @@ public void testSearchIssue() throws Throwable { CompletableFuture maybeSucceeded = issueClient.editComment(1, "some comment"); capture.getValue().onResponse(call, response); verify(tracer,times(1)).span(anyString(), anyString(),any()); - try { - maybeSucceeded.get(); - } catch (Exception e) { - throw e.getCause(); - } + + Exception exception = assertThrows(ExecutionException.class, + maybeSucceeded::get); + Assertions.assertEquals(ReadOnlyRepositoryException.class, exception.getCause().getClass()); } @Test @@ -135,7 +135,7 @@ public void testRequestNotOkException() throws Throwable { capture.getValue().onResponse(call, response); try { future.get(); - fail("Did not throw"); + Assertions.fail("Did not throw"); } catch (ExecutionException e) { assertThat(e.getCause() instanceof RequestNotOkException, is(true)); RequestNotOkException e1 = (RequestNotOkException) e.getCause(); diff --git a/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java b/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java index d7616bbc..a26711dc 100644 --- a/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java @@ -22,11 +22,9 @@ import static com.google.common.io.Resources.getResource; import static java.nio.charset.Charset.defaultCharset; -import static java.util.concurrent.CompletableFuture.completedFuture; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.core.Is.is; -import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.io.Resources; @@ -38,18 +36,15 @@ import java.net.URI; import java.time.ZonedDateTime; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class GithubAppClientTest { - @Rule public final MockWebServer mockServer = new MockWebServer(); private final ObjectMapper objectMapper = new ObjectMapper(); @@ -60,7 +55,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(GithubAppClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() throws Exception { URI uri = mockServer.url("").uri(); File key = FixtureHelper.loadFile("githubapp/key.pem"); diff --git a/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java b/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java index 3d3cc719..8c98235a 100644 --- a/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java @@ -33,8 +33,8 @@ import static org.hamcrest.core.Is.is; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.mock; import com.google.common.collect.Lists; import com.google.common.io.Resources; @@ -43,23 +43,16 @@ import com.spotify.github.v3.comment.Comment; import java.io.IOException; import java.util.List; -import okhttp3.Headers; import okhttp3.Response; -import okhttp3.ResponseBody; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Headers.class, ResponseBody.class, Response.class}) +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + public class IssueClientTest { private GitHubClient github; private IssueClient issueClient; - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); when(github.json()).thenReturn(Json.create()); diff --git a/src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.java b/src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.java index 437bc4cc..4bb1622d 100644 --- a/src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.java +++ b/src/test/java/com/spotify/github/v3/clients/JwtTokenIssuerTest.java @@ -26,7 +26,7 @@ import com.google.common.io.Resources; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JwtTokenIssuerTest { diff --git a/src/test/java/com/spotify/github/v3/clients/MockHelper.java b/src/test/java/com/spotify/github/v3/clients/MockHelper.java index f6537e8f..3bb896ca 100644 --- a/src/test/java/com/spotify/github/v3/clients/MockHelper.java +++ b/src/test/java/com/spotify/github/v3/clients/MockHelper.java @@ -20,8 +20,8 @@ package com.spotify.github.v3.clients; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.mock; import java.io.IOException; import okhttp3.Headers; diff --git a/src/test/java/com/spotify/github/v3/clients/OrganisationClientTest.java b/src/test/java/com/spotify/github/v3/clients/OrganisationClientTest.java index 9e4edcf9..1ac3c1ed 100644 --- a/src/test/java/com/spotify/github/v3/clients/OrganisationClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/OrganisationClientTest.java @@ -38,8 +38,8 @@ import com.spotify.github.v3.orgs.requests.OrgMembershipCreate; import java.io.IOException; import java.util.concurrent.CompletableFuture; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class OrganisationClientTest { @@ -53,7 +53,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(TeamClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); organisationClient = new OrganisationClient(github, "github"); diff --git a/src/test/java/com/spotify/github/v3/clients/PullRequestClientTest.java b/src/test/java/com/spotify/github/v3/clients/PullRequestClientTest.java index 45d52575..da3eea4d 100644 --- a/src/test/java/com/spotify/github/v3/clients/PullRequestClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/PullRequestClientTest.java @@ -20,24 +20,20 @@ package com.spotify.github.v3.clients; -import static com.google.common.collect.ImmutableMap.of; import static com.google.common.io.Resources.getResource; import static java.nio.charset.Charset.defaultCharset; -import static java.util.concurrent.CompletableFuture.completedFuture; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.io.Resources; -import com.spotify.github.jackson.Json; import com.spotify.github.v3.exceptions.RequestNotOkException; -import com.spotify.github.v3.git.Reference; import com.spotify.github.v3.prs.ImmutableRequestReviewParameters; import com.spotify.github.v3.prs.PullRequest; import com.spotify.github.v3.prs.ReviewRequests; @@ -59,8 +55,8 @@ import okhttp3.Response; import okhttp3.ResponseBody; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class PullRequestClientTest { @@ -72,7 +68,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(PullRequestClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { client = mock(OkHttpClient.class); github = GitHubClient.create(client, URI.create("http://bogus"), "token"); @@ -227,7 +223,7 @@ public void testRemoveRequestedReview() throws Throwable { // Passes without throwing } - @Test(expected = RequestNotOkException.class) + @Test public void testRemoveRequestedReview_failure() throws Throwable { final Call call = mock(Call.class); @@ -254,12 +250,8 @@ public void testRemoveRequestedReview_failure() throws Throwable { capture.getValue().onResponse(call, response); - try { - result.get(); - } catch (ExecutionException e) { - throw e.getCause(); - // expecting RequestNotOkException - } + Exception exception = assertThrows(ExecutionException.class, result::get); + assertEquals(RequestNotOkException.class, exception.getCause().getClass()); } @Test diff --git a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java index f2eea5ef..bee911d9 100644 --- a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java @@ -37,8 +37,8 @@ import static java.util.stream.StreamSupport.stream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -69,21 +69,15 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -import okhttp3.Headers; import okhttp3.MediaType; import okhttp3.Protocol; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ Headers.class, ResponseBody.class, Response.class}) public class RepositoryClientTest { private GitHubClient github; @@ -94,7 +88,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(RepositoryTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); repoClient = new RepositoryClient(github, "someowner", "somerepo"); diff --git a/src/test/java/com/spotify/github/v3/clients/SearchClientTest.java b/src/test/java/com/spotify/github/v3/clients/SearchClientTest.java index 53d74d10..40e6c571 100644 --- a/src/test/java/com/spotify/github/v3/clients/SearchClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/SearchClientTest.java @@ -35,8 +35,8 @@ import com.spotify.github.v3.search.requests.ImmutableSearchParameters; import java.io.IOException; import java.util.concurrent.CompletableFuture; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SearchClientTest { @@ -48,7 +48,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(SearchTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); searchClient = SearchClient.create(github); diff --git a/src/test/java/com/spotify/github/v3/clients/TeamClientTest.java b/src/test/java/com/spotify/github/v3/clients/TeamClientTest.java index aa33abf2..8ceb0f17 100644 --- a/src/test/java/com/spotify/github/v3/clients/TeamClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/TeamClientTest.java @@ -44,18 +44,11 @@ import java.io.IOException; import java.util.List; import java.util.concurrent.CompletableFuture; -import okhttp3.Headers; import okhttp3.Response; -import okhttp3.ResponseBody; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest({Headers.class, ResponseBody.class, Response.class}) public class TeamClientTest { private GitHubClient github; @@ -68,7 +61,7 @@ private static String getFixture(String resource) throws IOException { return Resources.toString(getResource(TeamClientTest.class, resource), defaultCharset()); } - @Before + @BeforeEach public void setUp() { github = mock(GitHubClient.class); teamClient = new TeamClient(github, "github"); diff --git a/src/test/java/com/spotify/github/v3/prs/PullRequestTest.java b/src/test/java/com/spotify/github/v3/prs/PullRequestTest.java index 2549fc37..a9c3c3a1 100644 --- a/src/test/java/com/spotify/github/v3/prs/PullRequestTest.java +++ b/src/test/java/com/spotify/github/v3/prs/PullRequestTest.java @@ -29,7 +29,7 @@ import com.spotify.github.jackson.Json; import java.io.IOException; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PullRequestTest { diff --git a/src/test/java/com/spotify/github/v3/prs/RequestReviewParametersTest.java b/src/test/java/com/spotify/github/v3/prs/RequestReviewParametersTest.java index a225fccf..863eccbb 100644 --- a/src/test/java/com/spotify/github/v3/prs/RequestReviewParametersTest.java +++ b/src/test/java/com/spotify/github/v3/prs/RequestReviewParametersTest.java @@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableList; import com.spotify.github.jackson.Json; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RequestReviewParametersTest { diff --git a/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java b/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java index 33d6e5f3..0d5919e8 100644 --- a/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java +++ b/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java @@ -20,17 +20,16 @@ package com.spotify.github.v3.prs; -import com.google.common.io.Resources; -import com.spotify.github.jackson.Json; -import org.junit.Test; - -import java.io.IOException; - import static com.google.common.io.Resources.getResource; import static java.nio.charset.Charset.defaultCharset; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import com.google.common.io.Resources; +import com.spotify.github.jackson.Json; +import java.io.IOException; +import org.junit.jupiter.api.Test; + public class ReviewParametersTest { @Test public void testDeserialization() throws IOException { diff --git a/src/test/java/com/spotify/github/v3/prs/ReviewRequestsTest.java b/src/test/java/com/spotify/github/v3/prs/ReviewRequestsTest.java index 6ae82907..99a2d0ee 100644 --- a/src/test/java/com/spotify/github/v3/prs/ReviewRequestsTest.java +++ b/src/test/java/com/spotify/github/v3/prs/ReviewRequestsTest.java @@ -28,8 +28,8 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ReviewRequestsTest { @@ -42,7 +42,7 @@ public static final void assertRequiredReviews(final ReviewRequests reviewReques assertThat(reviewRequests.teams().get(0).slug(), is("justice-league")); } - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "required_reviews.json"), defaultCharset()); diff --git a/src/test/java/com/spotify/github/v3/prs/ReviewTest.java b/src/test/java/com/spotify/github/v3/prs/ReviewTest.java index 387b16bc..db54fc29 100644 --- a/src/test/java/com/spotify/github/v3/prs/ReviewTest.java +++ b/src/test/java/com/spotify/github/v3/prs/ReviewTest.java @@ -28,7 +28,7 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ReviewTest { @Test diff --git a/src/test/java/com/spotify/github/v3/prs/requests/PullRequestCreateTest.java b/src/test/java/com/spotify/github/v3/prs/requests/PullRequestCreateTest.java index 4c2ff152..b8ed39e3 100644 --- a/src/test/java/com/spotify/github/v3/prs/requests/PullRequestCreateTest.java +++ b/src/test/java/com/spotify/github/v3/prs/requests/PullRequestCreateTest.java @@ -20,17 +20,14 @@ package com.spotify.github.v3.prs.requests; -import com.spotify.github.jackson.Json; -import com.spotify.github.v3.prs.ImmutablePullRequest; -import org.junit.Assert; -import org.junit.Test; - -import java.util.function.Function; - import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import com.spotify.github.jackson.Json; +import java.util.function.Function; +import org.junit.jupiter.api.Test; + public class PullRequestCreateTest { @Test diff --git a/src/test/java/com/spotify/github/v3/prs/requests/PullRequestParametersTest.java b/src/test/java/com/spotify/github/v3/prs/requests/PullRequestParametersTest.java index c99faec3..60ea9262 100644 --- a/src/test/java/com/spotify/github/v3/prs/requests/PullRequestParametersTest.java +++ b/src/test/java/com/spotify/github/v3/prs/requests/PullRequestParametersTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PullRequestParametersTest { diff --git a/src/test/java/com/spotify/github/v3/repos/LanguagesTest.java b/src/test/java/com/spotify/github/v3/repos/LanguagesTest.java index 5a026bef..633ddfcd 100644 --- a/src/test/java/com/spotify/github/v3/repos/LanguagesTest.java +++ b/src/test/java/com/spotify/github/v3/repos/LanguagesTest.java @@ -28,7 +28,7 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LanguagesTest { diff --git a/src/test/java/com/spotify/github/v3/repos/PushCommitTest.java b/src/test/java/com/spotify/github/v3/repos/PushCommitTest.java index 6ddf78fe..2d580388 100644 --- a/src/test/java/com/spotify/github/v3/repos/PushCommitTest.java +++ b/src/test/java/com/spotify/github/v3/repos/PushCommitTest.java @@ -28,14 +28,14 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class PushCommitTest { private String fixture; - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "push_commit.json"), defaultCharset()); diff --git a/src/test/java/com/spotify/github/v3/repos/RepositoryTest.java b/src/test/java/com/spotify/github/v3/repos/RepositoryTest.java index f3570d3b..82f28aa7 100644 --- a/src/test/java/com/spotify/github/v3/repos/RepositoryTest.java +++ b/src/test/java/com/spotify/github/v3/repos/RepositoryTest.java @@ -29,14 +29,14 @@ import com.google.common.io.Resources; import com.spotify.github.jackson.Json; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class RepositoryTest { private String fixture; - @Before + @BeforeEach public void setUp() throws Exception { fixture = Resources.toString(getResource(this.getClass(), "repository.json"), defaultCharset()); } diff --git a/src/test/java/com/spotify/github/v3/repos/StatusTest.java b/src/test/java/com/spotify/github/v3/repos/StatusTest.java index 291721be..0cf5d1ec 100644 --- a/src/test/java/com/spotify/github/v3/repos/StatusTest.java +++ b/src/test/java/com/spotify/github/v3/repos/StatusTest.java @@ -30,7 +30,7 @@ import java.io.IOException; import java.net.URI; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StatusTest { diff --git a/src/test/java/com/spotify/github/v3/repos/requests/RepositoryCreateStatusTest.java b/src/test/java/com/spotify/github/v3/repos/requests/RepositoryCreateStatusTest.java index 66325633..7abf1bf9 100644 --- a/src/test/java/com/spotify/github/v3/repos/requests/RepositoryCreateStatusTest.java +++ b/src/test/java/com/spotify/github/v3/repos/requests/RepositoryCreateStatusTest.java @@ -28,7 +28,7 @@ import com.spotify.github.jackson.Json; import com.spotify.github.v3.repos.StatusState; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RepositoryCreateStatusTest { diff --git a/src/test/java/com/spotify/github/v3/search/SearchTest.java b/src/test/java/com/spotify/github/v3/search/SearchTest.java index 3fa80009..ab04989c 100644 --- a/src/test/java/com/spotify/github/v3/search/SearchTest.java +++ b/src/test/java/com/spotify/github/v3/search/SearchTest.java @@ -30,7 +30,7 @@ import com.spotify.github.v3.issues.Issue; import java.io.IOException; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SearchTest { diff --git a/src/test/java/com/spotify/github/v3/search/requests/SearchParametersTest.java b/src/test/java/com/spotify/github/v3/search/requests/SearchParametersTest.java index 00e0d617..5120c088 100644 --- a/src/test/java/com/spotify/github/v3/search/requests/SearchParametersTest.java +++ b/src/test/java/com/spotify/github/v3/search/requests/SearchParametersTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SearchParametersTest {