diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index 9bafb4d9d1..05b8a606aa 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -2,6 +2,9 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import org.apache.commons.io.IOUtils; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.StringDescription; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -13,6 +16,7 @@ import java.io.IOException; import java.util.*; +import static org.hamcrest.Matchers.is; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -37,11 +41,7 @@ public abstract class AbstractGitHubWireMockTest extends Assert { */ protected GitHub gitHub; - /** - * {@link GitHub} instance for use before/after test. Traffic will not be part of snapshot when taken. Should only - * be used when isUseProxy() or isTakeSnapShot(). - */ - protected GitHub gitHubBeforeAfter; + private GitHub gitHubBeforeAfter; protected final String baseFilesClassPath = this.getClass().getName().replace('.', '/'); protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock"; @@ -126,6 +126,13 @@ protected void requireProxy(String reason) { mockGitHub.isUseProxy()); } + protected void verifyAuthenticated(GitHub instance) { + assertThat( + "GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_USER and GITHUB_PASSWORD environment variables", + instance.isAnonymous(), + is(false)); + } + protected GHUser getUser() { return getUser(gitHub); } @@ -163,9 +170,10 @@ protected GHRepository getTempRepository() throws IOException { protected GHRepository getTempRepository(String name) throws IOException { String fullName = GITHUB_API_TEST_ORG + '/' + name; if (mockGitHub.isUseProxy()) { + cleanupRepository(fullName); - GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG) + GHRepository repository = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG) .createRepository(name) .description("A test repository for testing the github-api project: " + name) .homepage("http://github-api.kohsuke.org/") @@ -199,7 +207,7 @@ protected void cleanupRepository(String fullName) throws IOException { if (mockGitHub.isUseProxy()) { tempGitHubRepositories.add(fullName); try { - GHRepository repository = gitHubBeforeAfter.getRepository(fullName); + GHRepository repository = getGitHubBeforeAfter().getRepository(fullName); if (repository != null) { repository.delete(); } @@ -210,6 +218,17 @@ protected void cleanupRepository(String fullName) throws IOException { } } + /** + * {@link GitHub} instance for use before/after test. Traffic will not be part of snapshot when taken. Should only + * be used when isUseProxy() or isTakeSnapShot(). + * + * @return a github instance after checking Authentication + */ + public GitHub getGitHubBeforeAfter() { + verifyAuthenticated(gitHubBeforeAfter); + return gitHubBeforeAfter; + } + protected void kohsuke() { // No-op for now // Generally this means the test is doing something that requires additional access rights @@ -219,4 +238,28 @@ protected void kohsuke() { // assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2")); } + public static void assertThat(T actual, Matcher matcher) { + assertThat("", actual, matcher); + } + + public static void assertThat(String reason, T actual, Matcher matcher) { + if (!matcher.matches(actual)) { + Description description = new StringDescription(); + description.appendText(reason) + .appendText(System.lineSeparator()) + .appendText("Expected: ") + .appendDescriptionOf(matcher) + .appendText(System.lineSeparator()) + .appendText(" but: "); + matcher.describeMismatch(actual, description); + throw new AssertionError(description.toString()); + } + } + + public static void assertThat(String reason, boolean assertion) { + if (!assertion) { + throw new AssertionError(reason); + } + } + } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index e60f040d27..cb41c73ba5 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -19,7 +19,6 @@ import java.util.regex.Pattern; import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasProperty; /** @@ -69,7 +68,7 @@ public void testRepositoryWithAutoInitializationCRUD() throws Exception { private void cleanupUserRepository(final String name) throws IOException { if (mockGitHub.isUseProxy()) { - cleanupRepository(getUser(gitHubBeforeAfter).getLogin() + "/" + name); + cleanupRepository(getUser(getGitHubBeforeAfter()).getLogin() + "/" + name); } } @@ -432,7 +431,7 @@ public void tryHook() throws Exception { // System.out.println(hook); if (mockGitHub.isUseProxy()) { - r = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api"); + r = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api"); for (GHHook h : r.getHooks()) { h.delete(); } @@ -821,7 +820,7 @@ public void testRepoLabel() throws IOException { void cleanupLabel(String name) { if (mockGitHub.isUseProxy()) { try { - GHLabel t = gitHubBeforeAfter.getRepository("github-api-test-org/test-labels").getLabel("test"); + GHLabel t = getGitHubBeforeAfter().getRepository("github-api-test-org/test-labels").getLabel("test"); t.delete(); } catch (IOException e) { diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 240ae271cc..aa75f9113d 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -26,7 +26,7 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest { @After public void cleanup() throws Exception { if (mockGitHub.isUseProxy()) { - repo = gitHubBeforeAfter.getRepository("github-api-test-org/GHContentIntegrationTest"); + repo = getGitHubBeforeAfter().getRepository("github-api-test-org/GHContentIntegrationTest"); try { GHContent content = repo.getFileContent(createdFilename); if (content != null) { diff --git a/src/test/java/org/kohsuke/github/GHDeploymentTest.java b/src/test/java/org/kohsuke/github/GHDeploymentTest.java index b2dc602b15..edc0203138 100644 --- a/src/test/java/org/kohsuke/github/GHDeploymentTest.java +++ b/src/test/java/org/kohsuke/github/GHDeploymentTest.java @@ -4,8 +4,6 @@ import java.io.IOException; -import static org.junit.Assert.assertNotNull; - /** * @author Martin van Zijl */ diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 09add4d0c4..a4360618fb 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -5,7 +5,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class GHEventPayloadTest { diff --git a/src/test/java/org/kohsuke/github/GHGistTest.java b/src/test/java/org/kohsuke/github/GHGistTest.java index beae248f27..cbb70d77aa 100644 --- a/src/test/java/org/kohsuke/github/GHGistTest.java +++ b/src/test/java/org/kohsuke/github/GHGistTest.java @@ -2,7 +2,6 @@ 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/GHGistUpdaterTest.java b/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java index 83156723f4..9fef615a80 100644 --- a/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java +++ b/src/test/java/org/kohsuke/github/GHGistUpdaterTest.java @@ -7,10 +7,6 @@ import java.io.IOException; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * @author Martin van Zijl */ diff --git a/src/test/java/org/kohsuke/github/GHHookTest.java b/src/test/java/org/kohsuke/github/GHHookTest.java index d527097821..3f3b40cbc9 100644 --- a/src/test/java/org/kohsuke/github/GHHookTest.java +++ b/src/test/java/org/kohsuke/github/GHHookTest.java @@ -11,10 +11,10 @@ import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertThat; /** * @author Kanstantsin Shautsou diff --git a/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java b/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java index d8b290cfcf..7b28bb7006 100644 --- a/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java +++ b/src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java @@ -5,6 +5,11 @@ import java.io.IOException; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.kohsuke.github.GHDirection.DESC; import static org.kohsuke.github.GHMarketplaceAccountType.ORGANIZATION; import static org.kohsuke.github.GHMarketplaceListAccountBuilder.Sort.UPDATED; diff --git a/src/test/java/org/kohsuke/github/GHMilestoneTest.java b/src/test/java/org/kohsuke/github/GHMilestoneTest.java index 10ccc9a1a2..4bdb79cdc9 100644 --- a/src/test/java/org/kohsuke/github/GHMilestoneTest.java +++ b/src/test/java/org/kohsuke/github/GHMilestoneTest.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.util.Date; +import static org.junit.Assert.assertEquals; + /** * @author Martin van Zijl */ @@ -20,7 +22,7 @@ public void cleanUp() throws Exception { return; } - for (GHMilestone milestone : getRepository(gitHubBeforeAfter).listMilestones(GHIssueState.ALL)) { + for (GHMilestone milestone : getRepository(getGitHubBeforeAfter()).listMilestones(GHIssueState.ALL)) { if ("Original Title".equals(milestone.getTitle()) || "Updated Title".equals(milestone.getTitle())) { milestone.delete(); } diff --git a/src/test/java/org/kohsuke/github/GHObjectTest.java b/src/test/java/org/kohsuke/github/GHObjectTest.java index b9a19a5fda..d322d76568 100644 --- a/src/test/java/org/kohsuke/github/GHObjectTest.java +++ b/src/test/java/org/kohsuke/github/GHObjectTest.java @@ -13,4 +13,4 @@ public void test_toString() throws Exception { containsString( "login=github-api-test-org,location=,blog=,email=,name=,company=,type=Organization,followers=0,following=0")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index 53d6da33b1..5c3cf2140a 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -21,7 +21,7 @@ public void cleanUpTeam() throws IOException { return; } - GHTeam team = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE); + GHTeam team = getGitHubBeforeAfter().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE); if (team != null) { team.delete(); } diff --git a/src/test/java/org/kohsuke/github/GHProjectCardTest.java b/src/test/java/org/kohsuke/github/GHProjectCardTest.java index e6bf0b06b3..b2f00e6220 100644 --- a/src/test/java/org/kohsuke/github/GHProjectCardTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectCardTest.java @@ -74,7 +74,7 @@ public void testDeleteCard() throws IOException { public void after() throws IOException { if (mockGitHub.isUseProxy()) { if (card != null) { - card = gitHubBeforeAfter.getProjectCard(card.getId()); + card = getGitHubBeforeAfter().getProjectCard(card.getId()); try { card.delete(); card = null; @@ -83,7 +83,7 @@ public void after() throws IOException { } } if (column != null) { - column = gitHubBeforeAfter.getProjectColumn(column.getId()); + column = getGitHubBeforeAfter().getProjectColumn(column.getId()); try { column.delete(); column = null; @@ -92,7 +92,7 @@ public void after() throws IOException { } } if (project != null) { - project = gitHubBeforeAfter.getProject(project.getId()); + project = getGitHubBeforeAfter().getProject(project.getId()); try { project.delete(); project = null; diff --git a/src/test/java/org/kohsuke/github/GHProjectColumnTest.java b/src/test/java/org/kohsuke/github/GHProjectColumnTest.java index 29c7e0fd8e..0973eeb32c 100644 --- a/src/test/java/org/kohsuke/github/GHProjectColumnTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectColumnTest.java @@ -48,7 +48,7 @@ public void testDeleteColumn() throws IOException { public void after() throws IOException { if (mockGitHub.isUseProxy()) { if (column != null) { - column = gitHubBeforeAfter.getProjectColumn(column.getId()); + column = getGitHubBeforeAfter().getProjectColumn(column.getId()); try { column.delete(); column = null; @@ -57,7 +57,7 @@ public void after() throws IOException { } } if (project != null) { - project = gitHubBeforeAfter.getProject(project.getId()); + project = getGitHubBeforeAfter().getProject(project.getId()); try { project.delete(); project = null; diff --git a/src/test/java/org/kohsuke/github/GHProjectTest.java b/src/test/java/org/kohsuke/github/GHProjectTest.java index 178a1d2b54..cc10b1fb89 100644 --- a/src/test/java/org/kohsuke/github/GHProjectTest.java +++ b/src/test/java/org/kohsuke/github/GHProjectTest.java @@ -69,7 +69,7 @@ public void testDeleteProject() throws IOException { public void after() throws IOException { if (mockGitHub.isUseProxy()) { if (project != null) { - project = gitHubBeforeAfter.getProject(project.getId()); + project = getGitHubBeforeAfter().getProject(project.getId()); try { project.delete(); project = null; diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index 4ee1750908..dfeb164843 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -24,7 +24,7 @@ public void cleanUp() throws Exception { return; } - for (GHPullRequest pr : getRepository(this.gitHubBeforeAfter).getPullRequests(GHIssueState.OPEN)) { + for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) { pr.close(); } } diff --git a/src/test/java/org/kohsuke/github/GHRateLimitTest.java b/src/test/java/org/kohsuke/github/GHRateLimitTest.java index 3b6bf731b4..c68e574603 100644 --- a/src/test/java/org/kohsuke/github/GHRateLimitTest.java +++ b/src/test/java/org/kohsuke/github/GHRateLimitTest.java @@ -12,6 +12,7 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.core.IsInstanceOf.instanceOf; /** * Test showing the behavior of OkHttpConnector with and without cache. diff --git a/src/test/java/org/kohsuke/github/GHTagTest.java b/src/test/java/org/kohsuke/github/GHTagTest.java index 186740b6aa..5aac4d083f 100644 --- a/src/test/java/org/kohsuke/github/GHTagTest.java +++ b/src/test/java/org/kohsuke/github/GHTagTest.java @@ -24,7 +24,7 @@ public void cleanUpTags() throws Exception { } try { - GHRef ref = getRepository(this.gitHubBeforeAfter).getRef("tags/create_tag_test"); + GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef("tags/create_tag_test"); if (ref != null) { ref.delete(); } diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index 81628a6e39..1d369acfd3 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -5,6 +5,8 @@ import java.io.IOException; +import static org.junit.Assert.assertEquals; + public class GHTeamTest extends AbstractGitHubWireMockTest { @Test diff --git a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java index 7b091cfb45..b2bb175dce 100644 --- a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.util.Arrays; +import static org.junit.Assert.assertEquals; + public class GHTreeBuilderTest extends AbstractGitHubWireMockTest { private static String REPO_NAME = "github-api-test-org/GHTreeBuilderTest"; @@ -31,7 +33,7 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest { @After public void cleanup() throws Exception { if (mockGitHub.isUseProxy()) { - repo = gitHubBeforeAfter.getRepository(REPO_NAME); + repo = getGitHubBeforeAfter().getRepository(REPO_NAME); Arrays.asList(PATH_SCRIPT, PATH_README, PATH_DATA1, PATH_DATA2).forEach(path -> { try { GHContent content = repo.getFileContent(path); diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java index e40db4ad2f..4acd3fcc4e 100644 --- a/src/test/java/org/kohsuke/github/GHUserTest.java +++ b/src/test/java/org/kohsuke/github/GHUserTest.java @@ -6,6 +6,11 @@ import java.util.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class GHUserTest extends AbstractGitHubWireMockTest { @Test diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 8066dd9f1a..89c95c3337 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import org.junit.Assert; import org.junit.Test; import java.text.SimpleDateFormat; @@ -18,7 +17,7 @@ * * @author Liam Newman */ -public class GitHubStaticTest extends Assert { +public class GitHubStaticTest extends AbstractGitHubWireMockTest { @Test public void timeRoundTrip() throws Exception { diff --git a/src/test/java/org/kohsuke/github/Github2faTest.java b/src/test/java/org/kohsuke/github/Github2faTest.java index fb3c9cb6bf..6b77b12976 100644 --- a/src/test/java/org/kohsuke/github/Github2faTest.java +++ b/src/test/java/org/kohsuke/github/Github2faTest.java @@ -6,6 +6,9 @@ import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Kevin Harrington mad.hephaestus@gmail.com */ diff --git a/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java b/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java index 843becc145..680873889e 100644 --- a/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java +++ b/src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java @@ -22,10 +22,7 @@ public void user_whenProxying_AuthCorrectlyConfigured() throws Exception { snapshotNotAllowed(); requireProxy("Tests proper configuration when proxying."); - 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)); + verifyAuthenticated(gitHub); assertThat(gitHub.login, not(equalTo(STUBBED_USER_LOGIN))); @@ -47,7 +44,7 @@ public void user_whenNotProxying_Stubbed() throws Exception { assumeFalse("Test only valid when not proxying", mockGitHub.isUseProxy()); - assertThat(gitHub.isAnonymous(), is(false)); + verifyAuthenticated(gitHub); assertThat(gitHub.login, equalTo(STUBBED_USER_LOGIN)); GHUser user = gitHub.getMyself(); diff --git a/src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java b/src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java index c98d5b9589..35007b9bf6 100644 --- a/src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java +++ b/src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java @@ -21,6 +21,8 @@ import java.io.File; import java.io.IOException; +import static org.junit.Assert.fail; + /** * Test showing the behavior of OkHttpConnector cache with GitHub 404 responses. * @@ -43,11 +45,11 @@ protected WireMockConfiguration getWireMockOptions() { @Before public void setupRepo() throws Exception { if (mockGitHub.isUseProxy()) { - for (GHPullRequest pr : getRepository(this.gitHubBeforeAfter).getPullRequests(GHIssueState.OPEN)) { + for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) { pr.close(); } try { - GHRef ref = getRepository(this.gitHubBeforeAfter).getRef(testRefName); + GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef(testRefName); ref.delete(); } catch (IOException e) { } diff --git a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java index 00f85bdfd2..2f940b5439 100644 --- a/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java @@ -14,6 +14,7 @@ import java.io.File; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.hamcrest.core.Is.is; import static org.junit.Assume.assumeFalse; @@ -74,7 +75,7 @@ protected WireMockConfiguration getWireMockOptions() { @Before public void setupRepo() throws Exception { if (mockGitHub.isUseProxy()) { - GHRepository repo = getRepository(gitHubBeforeAfter); + GHRepository repo = getRepository(getGitHubBeforeAfter()); repo.setDescription("Resetting"); // Let things settle a bit between tests when working against the live site @@ -253,7 +254,7 @@ private void doTestActions() throws Exception { // Get Tricky - make a change via a different client if (mockGitHub.isUseProxy()) { - GHRepository altRepo = getRepository(gitHubBeforeAfter); + GHRepository altRepo = getRepository(getGitHubBeforeAfter()); altRepo.setDescription("Tricky"); } diff --git a/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java b/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java index b13a516593..8467e30a0d 100644 --- a/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java +++ b/src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java @@ -20,6 +20,8 @@ import java.io.File; import java.io.IOException; +import static org.junit.Assert.fail; + /** * Test showing the behavior of OkHttpConnector cache with GitHub 404 responses. * @@ -44,11 +46,11 @@ protected WireMockConfiguration getWireMockOptions() { @Before public void setupRepo() throws Exception { if (mockGitHub.isUseProxy()) { - for (GHPullRequest pr : getRepository(this.gitHubBeforeAfter).getPullRequests(GHIssueState.OPEN)) { + for (GHPullRequest pr : getRepository(this.getGitHubBeforeAfter()).getPullRequests(GHIssueState.OPEN)) { pr.close(); } try { - GHRef ref = getRepository(this.gitHubBeforeAfter).getRef(testRefName); + GHRef ref = getRepository(this.getGitHubBeforeAfter()).getRef(testRefName); ref.delete(); } catch (IOException e) { } 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 a60221f8d4..dea66e4b81 100644 --- a/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java +++ b/src/test/java/org/kohsuke/github/extras/okhttp3/OkHttpConnectorTest.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -79,7 +80,7 @@ protected WireMockConfiguration getWireMockOptions() { @Before public void setupRepo() throws Exception { if (mockGitHub.isUseProxy()) { - GHRepository repo = getRepository(gitHubBeforeAfter); + GHRepository repo = getRepository(getGitHubBeforeAfter()); repo.setDescription("Resetting"); // Let things settle a bit between tests when working against the live site @@ -261,7 +262,7 @@ private void doTestActions() throws Exception { // Get Tricky - make a change via a different client if (mockGitHub.isUseProxy()) { - GHRepository altRepo = getRepository(gitHubBeforeAfter); + GHRepository altRepo = getRepository(getGitHubBeforeAfter()); altRepo.setDescription("Tricky"); }