From 70b6e22317762faff41336bf377acb5b5093d449 Mon Sep 17 00:00:00 2001
From: strangelookingnerd
<49242855+strangelookingnerd@users.noreply.github.com>
Date: Wed, 1 Oct 2025 14:16:29 +0200
Subject: [PATCH] Migrate tests to JUnit5
* Migrate annotations and imports
* Migrate assertions
* Remove public visibility for test classes and methods
* Minor code cleanup
---
pom.xml | 7 +
.../AbstractGitHubWireMockTest.java | 59 +-
.../ApiRateLimitCheckerTest.java | 84 ++-
.../BranchDiscoveryTraitTest.java | 64 +-
...DefaultGitHubNotificationStrategyTest.java | 26 +-
.../github_branch_source/EndpointTest.java | 66 +-
.../github_branch_source/EventsTest.java | 83 +--
.../ForkPullRequestDiscoveryTrait2Test.java | 40 +-
.../ForkPullRequestDiscoveryTraitTest.java | 65 +-
...ubAppCredentialsContextualizationTest.java | 14 +-
...bAppCredentialsJCasCCompatibilityTest.java | 31 +-
...ubBranchSourcesJCasCCompatibilityTest.java | 12 +-
.../GitHubNotificationTest.java | 35 +-
.../GitHubOrgWebHookTest.java | 41 +-
.../GitHubSCMBuilderTest.java | 618 +++++++++++-------
.../GitHubSCMFileSystemTest.java | 173 +++--
.../GitHubSCMNavigatorTest.java | 84 +--
.../GitHubSCMNavigatorTraitsTest.java | 233 +++----
.../GitHubSCMProbeTest.java | 66 +-
.../GitHubSCMSourceHelperTest.java | 10 +-
.../GitHubSCMSourceTest.java | 146 ++---
.../GitHubSCMSourceTraitsTest.java | 218 +++---
.../GitSCMSourceBase.java | 21 +-
...ppCredentialsAppInstallationTokenTest.java | 9 +-
.../GithubAppCredentialsTest.java | 60 +-
.../GithubSCMSourceBranchesTest.java | 49 +-
.../GithubSCMSourcePRsTest.java | 58 +-
.../GithubSCMSourceTagsTest.java | 113 ++--
...IgnoreDraftPullRequestFilterTraitTest.java | 13 +-
.../OriginPullRequestDiscoveryTraitTest.java | 75 +--
.../PullRequestSCMRevisionTest.java | 88 +--
.../SSHCheckoutTraitTest.java | 44 +-
.../TagDiscoveryTraitTest.java | 27 +-
...ory.java => WireMockExtensionFactory.java} | 35 +-
.../AccessInferredOwnerTest.java | 8 +-
.../AccessInferredRepositoryTest.java | 15 +-
.../AccessSpecifiedRepositoriesTest.java | 8 +-
.../MigrationAdminMonitorTest.java | 20 +-
.../RunWithCredentialsTest.java | 63 +-
39 files changed, 1499 insertions(+), 1382 deletions(-)
rename src/test/java/org/jenkinsci/plugins/github_branch_source/{WireMockRuleFactory.java => WireMockExtensionFactory.java} (60%)
diff --git a/pom.xml b/pom.xml
index 357a97b38..6381f627a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,6 +37,7 @@
2.504
${jenkins.baseline}.1
false
+ false
@@ -135,6 +136,12 @@
workflow-multibranch
test
+
+ org.junit-pioneer
+ junit-pioneer
+ 2.3.0
+ test
+
org.mockito
mockito-core
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/AbstractGitHubWireMockTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/AbstractGitHubWireMockTest.java
index f4636fa52..a48cada70 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/AbstractGitHubWireMockTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/AbstractGitHubWireMockTest.java
@@ -1,42 +1,40 @@
package org.jenkinsci.plugins.github_branch_source;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import com.github.tomakehurst.wiremock.common.FileSource;
-import com.github.tomakehurst.wiremock.common.SingleRootFileSource;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.Parameters;
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.Response;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import java.io.File;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
/** @author Liam Newman */
+@WithJenkins
public abstract class AbstractGitHubWireMockTest {
// By default the wiremock tests will run without proxy
// The tests will use only the stubbed data and will fail if requests are made for missing data.
// You can use the proxy while writing and debugging tests.
- private static final boolean useProxy =
+ private static final boolean USE_PROXY =
!System.getProperty("test.github.useProxy", "false").equals("false");
- @ClassRule
- public static JenkinsRule r = new JenkinsRule();
+ protected static JenkinsRule r;
- public static WireMockRuleFactory factory = new WireMockRuleFactory();
+ private static final WireMockExtensionFactory FACTORY = new WireMockExtensionFactory();
- @Rule
- public WireMockRule githubRaw =
- factory.getRule(WireMockConfiguration.options().dynamicPort().usingFilesUnderClasspath("raw"));
+ @RegisterExtension
+ protected final WireMockExtension githubRaw =
+ FACTORY.getExtension(WireMockConfiguration.options().dynamicPort().usingFilesUnderClasspath("raw"));
- @Rule
- public WireMockRule githubApi = factory.getRule(WireMockConfiguration.options()
+ @RegisterExtension
+ protected final WireMockExtension githubApi = FACTORY.getExtension(WireMockConfiguration.options()
.dynamicPort()
.usingFilesUnderClasspath("api")
.extensions(new ResponseTransformer() {
@@ -48,10 +46,11 @@ public Response transform(Request request, Response response, FileSource files,
.but()
.body(response.getBodyAsString()
.replace(
- "https://api.github.com/", "http://localhost:" + githubApi.port() + "/")
+ "https://api.github.com/",
+ "http://localhost:" + githubApi.getPort() + "/")
.replace(
"https://raw.githubusercontent.com/",
- "http://localhost:" + githubRaw.port() + "/"))
+ "http://localhost:" + githubRaw.getPort() + "/"))
.build();
}
return response;
@@ -63,11 +62,14 @@ public String getName() {
}
}));
- @Before
- public void prepareMockGitHub() {
- prepareMockGitHubFileMappings();
+ @BeforeAll
+ static void beforeAll(JenkinsRule rule) {
+ r = rule;
+ }
- if (useProxy) {
+ @BeforeEach
+ void beforeEach() throws Exception {
+ if (USE_PROXY) {
githubApi.stubFor(get(urlMatching(".*"))
.atPriority(10)
.willReturn(aResponse().proxiedFrom("https://api.github.com/")));
@@ -76,17 +78,4 @@ public void prepareMockGitHub() {
.willReturn(aResponse().proxiedFrom("https://raw.githubusercontent.com/")));
}
}
-
- void prepareMockGitHubFileMappings() {
- new File("src/test/resources/api/mappings").mkdirs();
- new File("src/test/resources/api/__files").mkdirs();
- new File("src/test/resources/raw/mappings").mkdirs();
- new File("src/test/resources/raw/__files").mkdirs();
- githubApi.enableRecordMappings(
- new SingleRootFileSource("src/test/resources/api/mappings"),
- new SingleRootFileSource("src/test/resources/api/__files"));
- githubRaw.enableRecordMappings(
- new SingleRootFileSource("src/test/resources/raw/mappings"),
- new SingleRootFileSource("src/test/resources/raw/__files"));
- }
}
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java
index c1770c8ff..1cba5643a 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java
@@ -2,15 +2,11 @@
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.resetAllScenarios;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
-import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.ScenarioMappingBuilder;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.stubbing.Scenario;
import hudson.util.LogTaskListener;
@@ -25,14 +21,14 @@
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
-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;
import org.kohsuke.github.GHRateLimit;
import org.kohsuke.github.GitHub;
import org.mockito.Mockito;
-public class ApiRateLimitCheckerTest extends AbstractGitHubWireMockTest {
+class ApiRateLimitCheckerTest extends AbstractGitHubWireMockTest {
private RingBufferLogHandler handler;
private LogTaskListener listener;
@@ -57,26 +53,21 @@ private long countOfOutputLinesContaining(String substring) {
return countOfOutputLines(m -> m.contains(substring));
}
- public static int getRequestCount(WireMockServer server) {
- return server.countRequestsMatching(RequestPatternBuilder.allRequests().build())
+ private static int getRequestCount(WireMockExtension extension) {
+ return extension
+ .countRequestsMatching(RequestPatternBuilder.allRequests().build())
.getCount();
}
- private class RateLimit {
- final int remaining;
- final int limit;
- final Date reset;
+ private record RateLimit(int limit, int remaining, Date reset) {}
- RateLimit(int limit, int remaining, Date reset) {
- this.limit = limit;
- this.remaining = remaining;
- this.reset = reset;
- }
- }
+ @Override
+ @BeforeEach
+ void beforeEach() throws Exception {
+ super.beforeEach();
- @Before
- public void setUp() throws Exception {
- resetAllScenarios();
+ githubApi.resetScenarios();
+ githubRaw.resetScenarios();
handler = new RingBufferLogHandler(1000);
final Logger logger = Logger.getLogger(getClass().getName());
@@ -98,13 +89,12 @@ public void setUp() throws Exception {
ApiRateLimitChecker.resetLocalChecker();
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void afterEach() {
GitHubConfiguration.get().setEndpoints(new ArrayList<>());
}
private void setupStubs(List scenarios) throws Exception {
-
githubApi.stubFor(get(urlEqualTo("/meta"))
.willReturn(aResponse().withStatus(200).withBody("{\"verifiable_password_authentication\": false}")));
@@ -159,13 +149,13 @@ private void setupStubs(List scenarios) throws Exception {
githubApi.stubFor(scenario);
}
- github = Connector.connect("http://localhost:" + githubApi.port(), null);
+ github = Connector.connect("http://localhost:" + githubApi.getPort(), null);
initialRequestCount = getRequestCount(githubApi);
assertEquals(2, initialRequestCount);
}
@Test
- public void NoCheckerConfigured() throws Exception {
+ void NoCheckerConfigured() throws Exception {
// set up scenarios
List scenarios = new ArrayList<>();
long now = System.currentTimeMillis();
@@ -204,7 +194,7 @@ public void NoCheckerConfigured() throws Exception {
}
@Test
- public void NoCheckerConfiguredWithEndpoint() throws Exception {
+ void NoCheckerConfiguredWithEndpoint() throws Exception {
// set up scenarios
List scenarios = new ArrayList<>();
long now = System.currentTimeMillis();
@@ -240,7 +230,7 @@ public void NoCheckerConfiguredWithEndpoint() throws Exception {
* @author Julian V. Modesto
*/
@Test
- public void ThrottleOnOverTestWithQuota() throws Exception {
+ void ThrottleOnOverTestWithQuota() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// set up scenarios
@@ -269,7 +259,7 @@ public void ThrottleOnOverTestWithQuota() throws Exception {
* @author Julian V. Modesto
*/
@Test
- public void ThrottleOnNormalizeTestWithQuota() throws Exception {
+ void ThrottleOnNormalizeTestWithQuota() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
// set up scenarios
@@ -296,7 +286,7 @@ public void ThrottleOnNormalizeTestWithQuota() throws Exception {
* @author Marc Salles Navarro
*/
@Test
- public void NoThrottleTestShouldNotThrottle() throws Exception {
+ void NoThrottleTestShouldNotThrottle() throws Exception {
// set up scenarios
List scenarios = new ArrayList<>();
int limit = 5000;
@@ -324,8 +314,7 @@ public void NoThrottleTestShouldNotThrottle() throws Exception {
* @author Marc Salles Navarro
*/
@Test
- public void NoThrottleTestShouldNotThrottle404() throws Exception {
-
+ void NoThrottleTestShouldNotThrottle404() throws Exception {
setupStubs(new ArrayList<>());
GHRateLimit.Record initial = github.lastRateLimit().getCore();
assertEquals(2, getRequestCount(githubApi));
@@ -341,7 +330,8 @@ public void NoThrottleTestShouldNotThrottle404() throws Exception {
github.getMeta();
// The core should be unknown, but different from initial
- assertTrue(github.rateLimit().getCore() instanceof GHRateLimit.UnknownLimitRecord);
+ assertInstanceOf(
+ GHRateLimit.UnknownLimitRecord.class, github.rateLimit().getCore());
assertNotEquals(initial, github.rateLimit().getCore());
// there should be no output
@@ -357,7 +347,7 @@ public void NoThrottleTestShouldNotThrottle404() throws Exception {
* @author Marc Salles Navarro
*/
@Test
- public void NoThrottleTestShouldFallbackToThrottleOnOverForGitHubDotCom() throws Exception {
+ void NoThrottleTestShouldFallbackToThrottleOnOverForGitHubDotCom() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// set up scenarios
@@ -391,7 +381,7 @@ public void NoThrottleTestShouldFallbackToThrottleOnOverForGitHubDotCom() throws
* @author Julian V. Modesto
*/
@Test
- public void ThrottleOnOverTest() throws Exception {
+ void ThrottleOnOverTest() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// set up scenarios
@@ -462,7 +452,7 @@ public void ThrottleOnOverTest() throws Exception {
* @author Julian V. Modesto
*/
@Test
- public void ThrottleForNormalizeTestWithinIdeal() throws Exception {
+ void ThrottleForNormalizeTestWithinIdeal() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
List scenarios = new ArrayList<>();
@@ -552,7 +542,7 @@ public void ThrottleForNormalizeTestWithinIdeal() throws Exception {
* @author Julian V. Modesto
*/
@Test
- public void NormalizeThrottleWithBurnedBuffer() throws Exception {
+ void NormalizeThrottleWithBurnedBuffer() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
long now = System.currentTimeMillis();
@@ -614,7 +604,7 @@ public void NormalizeThrottleWithBurnedBuffer() throws Exception {
* @author Alex Taylor
*/
@Test
- public void OnOverThrottleTimingRateLimitCheck() throws Exception {
+ void OnOverThrottleTimingRateLimitCheck() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// Longer timings that test defaults for more consistent measurements.
@@ -695,7 +685,7 @@ public void OnOverThrottleTimingRateLimitCheck() throws Exception {
* @author Alex Taylor
*/
@Test
- public void NormalizeThrottleTimingRateLimitCheck() throws Exception {
+ void NormalizeThrottleTimingRateLimitCheck() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
ApiRateLimitChecker.setExpirationWaitMillis(60);
@@ -763,7 +753,7 @@ public void NormalizeThrottleTimingRateLimitCheck() throws Exception {
* @author Alex Taylor
*/
@Test
- public void NormalizeExpectedIdealOverTime() throws Exception {
+ void NormalizeExpectedIdealOverTime() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
// Set up scenarios
@@ -840,7 +830,7 @@ public void NormalizeExpectedIdealOverTime() throws Exception {
* @author Alex Taylor
*/
@Test
- public void OnOverExpectedIdealOverTime() throws Exception {
+ void OnOverExpectedIdealOverTime() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
long start = System.currentTimeMillis();
@@ -894,7 +884,7 @@ public void OnOverExpectedIdealOverTime() throws Exception {
* @author Alex Taylor
*/
@Test
- public void ExpectedResetTimingNormalize() throws Exception {
+ void ExpectedResetTimingNormalize() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleForNormalize);
// Use a longer notification interval to make the test produce stable output
@@ -940,7 +930,7 @@ public void ExpectedResetTimingNormalize() throws Exception {
* @author Alex Taylor
*/
@Test
- public void ExpectedResetTimingOnOver() throws Exception {
+ void ExpectedResetTimingOnOver() throws Exception {
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// Use a longer notification interval to make the test produce stable output
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTraitTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTraitTest.java
index 2b1540fcf..afab3740d 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTraitTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTraitTest.java
@@ -1,34 +1,42 @@
package org.jenkinsci.plugins.github_branch_source;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assume.assumeThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import hudson.util.ListBoxModel;
import java.util.Collections;
import jenkins.scm.api.SCMHeadObserver;
import jenkins.scm.api.trait.SCMHeadFilter;
import jenkins.scm.api.trait.SCMHeadPrefilter;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
-public class BranchDiscoveryTraitTest {
- @ClassRule
- public static JenkinsRule j = new JenkinsRule();
+@WithJenkins
+class BranchDiscoveryTraitTest {
+
+ private static JenkinsRule j;
+
+ @BeforeAll
+ static void beforeAll(JenkinsRule rule) {
+ j = rule;
+ }
@Test
- public void given__discoverAll__when__appliedToContext__then__noFilter() throws Exception {
+ void given__discoverAll__when__appliedToContext__then__noFilter() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(BranchDiscoveryTrait.BranchSCMHeadAuthority.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof BranchDiscoveryTrait.BranchSCMHeadAuthority));
BranchDiscoveryTrait instance = new BranchDiscoveryTrait(true, true);
instance.decorateContext(ctx);
assertThat(ctx.wantBranches(), is(true));
@@ -39,13 +47,14 @@ public void given__discoverAll__when__appliedToContext__then__noFilter() throws
}
@Test
- public void given__excludingPRs__when__appliedToContext__then__filter() throws Exception {
+ void given__excludingPRs__when__appliedToContext__then__filter() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(BranchDiscoveryTrait.BranchSCMHeadAuthority.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof BranchDiscoveryTrait.BranchSCMHeadAuthority));
BranchDiscoveryTrait instance = new BranchDiscoveryTrait(true, false);
instance.decorateContext(ctx);
assertThat(ctx.wantBranches(), is(true));
@@ -57,13 +66,14 @@ public void given__excludingPRs__when__appliedToContext__then__filter() throws E
}
@Test
- public void given__onlyPRs__when__appliedToContext__then__filter() throws Exception {
+ void given__onlyPRs__when__appliedToContext__then__filter() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(BranchDiscoveryTrait.BranchSCMHeadAuthority.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof BranchDiscoveryTrait.BranchSCMHeadAuthority));
BranchDiscoveryTrait instance = new BranchDiscoveryTrait(false, true);
instance.decorateContext(ctx);
assertThat(ctx.wantBranches(), is(true));
@@ -74,7 +84,7 @@ public void given__onlyPRs__when__appliedToContext__then__filter() throws Except
}
@Test
- public void given__descriptor__when__displayingOptions__then__allThreePresent() {
+ void given__descriptor__when__displayingOptions__then__allThreePresent() {
ListBoxModel options = j.jenkins
.getDescriptorByType(BranchDiscoveryTrait.DescriptorImpl.class)
.doFillStrategyIdItems();
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/DefaultGitHubNotificationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/DefaultGitHubNotificationStrategyTest.java
index c5b50f679..fcf5f839f 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/DefaultGitHubNotificationStrategyTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/DefaultGitHubNotificationStrategyTest.java
@@ -24,8 +24,9 @@
package org.jenkinsci.plugins.github_branch_source;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
@@ -36,16 +37,23 @@
import java.util.logging.Logger;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
-public class DefaultGitHubNotificationStrategyTest {
- @Rule
- public JenkinsRule j = new JenkinsRule();
+@WithJenkins
+class DefaultGitHubNotificationStrategyTest {
+
+ private JenkinsRule j;
+
+ @BeforeEach
+ void beforeEach(JenkinsRule rule) {
+ j = rule;
+ }
@Test
- public void given_basicJob_then_singleNotification() throws Exception {
+ void given_basicJob_then_singleNotification() throws Exception {
List srcs = Arrays.asList(
new GitHubSCMSource("example", "test", null, false),
new GitHubSCMSource("", "", "http://github.com/example/test", true));
@@ -61,7 +69,7 @@ public void given_basicJob_then_singleNotification() throws Exception {
}
@Test
- public void given_differentSCMheads_then_distinctNotifications() throws Exception {
+ void given_differentSCMheads_then_distinctNotifications() throws Exception {
List srcs = Arrays.asList(
new GitHubSCMSource("example", "test", "http://github.com/ignored/ignored", false),
new GitHubSCMSource("", "", "http://github.com/example/test", true));
@@ -110,7 +118,7 @@ public void given_differentSCMheads_then_distinctNotifications() throws Exceptio
}
@Test
- public void given_jobOrRun_then_differentURLs() throws Exception {
+ void given_jobOrRun_then_differentURLs() throws Exception {
List srcs = Arrays.asList(
new GitHubSCMSource("example", "test", null, false),
new GitHubSCMSource("", "", "http://github.com/example/test", true));
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/EndpointTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/EndpointTest.java
index 9693adbfb..afaf4c853 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/EndpointTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/EndpointTest.java
@@ -1,9 +1,6 @@
package org.jenkinsci.plugins.github_branch_source;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
import hudson.ExtensionList;
import hudson.Functions;
@@ -24,26 +21,26 @@
import org.htmlunit.WebRequest;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.util.NameValuePair;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.TestExtension;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
-import org.xml.sax.SAXException;
-public class EndpointTest {
-
- @Rule
- public final JenkinsRule j = new JenkinsRule();
+@WithJenkins
+class EndpointTest {
private String testUrl;
- @Before
- public void setUp() throws Exception {
+ private JenkinsRule j;
+
+ @BeforeEach
+ void beforeEach(JenkinsRule rule) throws Exception {
+ j = rule;
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
MockAuthorizationStrategy auth = new MockAuthorizationStrategy();
auth.grant(Jenkins.MANAGE).everywhere().to("alice");
@@ -54,37 +51,34 @@ public void setUp() throws Exception {
@Test
@Issue("SECURITY-806")
- public void cantGet_doCheckApiUri() throws IOException, SAXException {
- try {
- j.createWebClient()
- .goTo(appendCrumb(
- "descriptorByName/org.jenkinsci.plugins.github_branch_source.Endpoint/checkApiUri?apiUri="
- + testUrl));
- fail("Should not be able to do that");
- } catch (FailingHttpStatusCodeException e) {
- assertEquals(405, e.getStatusCode());
- }
+ void cantGet_doCheckApiUri() {
+ FailingHttpStatusCodeException e = assertThrows(FailingHttpStatusCodeException.class, () -> j.createWebClient()
+ .goTo(
+ appendCrumb(
+ "descriptorByName/org.jenkinsci.plugins.github_branch_source.Endpoint/checkApiUri?apiUri="
+ + testUrl),
+ "Should not be able to do that"));
+ assertEquals(405, e.getStatusCode());
assertFalse(TestRoot.get().visited);
}
@Test
@Issue("SECURITY-806")
- public void cantPostAsAnonymous_doCheckApiUri() throws Exception {
- try {
- post(
- "descriptorByName/org.jenkinsci.plugins.github_branch_source.Endpoint/checkApiUri?apiUri="
- + testUrl,
- null);
- fail("Should not be able to do that");
- } catch (FailingHttpStatusCodeException e) {
- assertEquals(403, e.getStatusCode());
- }
+ void cantPostAsAnonymous_doCheckApiUri() {
+ FailingHttpStatusCodeException e = assertThrows(
+ FailingHttpStatusCodeException.class,
+ () -> post(
+ "descriptorByName/org.jenkinsci.plugins.github_branch_source.Endpoint/checkApiUri?apiUri="
+ + testUrl,
+ null),
+ "Should not be able to do that");
+ assertEquals(403, e.getStatusCode());
assertFalse(TestRoot.get().visited);
}
@Test
@Issue("SECURITY-806")
- public void canPostAsAdmin_doCheckApiUri() throws Exception {
+ void canPostAsAdmin_doCheckApiUri() throws Exception {
post(
"descriptorByName/org.jenkinsci.plugins.github_branch_source.Endpoint/checkApiUri?apiUri=" + testUrl,
"alice");
@@ -93,7 +87,7 @@ public void canPostAsAdmin_doCheckApiUri() throws Exception {
@Test
@Issue("JENKINS-73053")
- public void manageCanSetupEndpoints() throws Exception {
+ void manageCanSetupEndpoints() throws Exception {
HtmlPage htmlPage = j.createWebClient().login("alice").goTo("manage/configure");
assertTrue(htmlPage.getVisibleText().contains("GitHub Enterprise Servers"));
}
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java
index 1f92a3fa1..ada82ed70 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/EventsTest.java
@@ -27,9 +27,9 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import jenkins.scm.api.SCMEvent;
import jenkins.scm.api.SCMEvents;
@@ -38,44 +38,46 @@
import org.apache.commons.io.IOUtils;
import org.awaitility.Awaitility;
import org.jenkinsci.plugins.github.extension.GHSubscriberEvent;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
-public class EventsTest {
+@WithJenkins
+class EventsTest {
/** All tests in this class only use Jenkins for the extensions */
- @ClassRule
- public static JenkinsRule r = new JenkinsRule();
+ @SuppressWarnings("unused")
+ private static JenkinsRule r;
- private static int defaultFireDelayInSeconds = GitHubSCMSource.getEventDelaySeconds();
+ private static final int DEFAULT_FIRE_DELAY_IN_SECONDS = GitHubSCMSource.getEventDelaySeconds();
private static SCMEvent.Type firedEventType;
private static GHSubscriberEvent ghEvent;
- @BeforeClass
- public static void setupDelay() {
+ @BeforeAll
+ static void beforeAll(JenkinsRule rule) {
+ r = rule;
GitHubSCMSource.setEventDelaySeconds(0); // fire immediately without delay
}
- @Before
- public void resetFiredEvent() {
+ @BeforeEach
+ void beforeEach() {
firedEventType = null;
ghEvent = null;
TestSCMEventListener.setReceived(false);
}
- @AfterClass
- public static void resetDelay() {
- GitHubSCMSource.setEventDelaySeconds(defaultFireDelayInSeconds);
+ @AfterAll
+ static void afterAll() {
+ GitHubSCMSource.setEventDelaySeconds(DEFAULT_FIRE_DELAY_IN_SECONDS);
}
@Test
- public void given_ghPushEventCreated_then_createdHeadEventFired() throws Exception {
+ void given_ghPushEventCreated_then_createdHeadEventFired() throws Exception {
PushGHEventSubscriber subscriber = new PushGHEventSubscriber();
firedEventType = SCMEvent.Type.CREATED;
@@ -84,7 +86,7 @@ public void given_ghPushEventCreated_then_createdHeadEventFired() throws Excepti
}
@Test
- public void given_ghPushEventDeleted_then_removedHeadEventFired() throws Exception {
+ void given_ghPushEventDeleted_then_removedHeadEventFired() throws Exception {
PushGHEventSubscriber subscriber = new PushGHEventSubscriber();
firedEventType = SCMEvent.Type.REMOVED;
@@ -93,7 +95,7 @@ public void given_ghPushEventDeleted_then_removedHeadEventFired() throws Excepti
}
@Test
- public void given_ghPushEventUpdated_then_updatedHeadEventFired() throws Exception {
+ void given_ghPushEventUpdated_then_updatedHeadEventFired() throws Exception {
PushGHEventSubscriber subscriber = new PushGHEventSubscriber();
firedEventType = SCMEvent.Type.UPDATED;
@@ -102,7 +104,7 @@ public void given_ghPushEventUpdated_then_updatedHeadEventFired() throws Excepti
}
@Test
- public void given_ghPullRequestEventOpened_then_createdHeadEventFired() throws Exception {
+ void given_ghPullRequestEventOpened_then_createdHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.CREATED;
@@ -111,7 +113,7 @@ public void given_ghPullRequestEventOpened_then_createdHeadEventFired() throws E
}
@Test
- public void given_ghPullRequestEventClosed_then_removedHeadEventFired() throws Exception {
+ void given_ghPullRequestEventClosed_then_removedHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.REMOVED;
@@ -120,7 +122,7 @@ public void given_ghPullRequestEventClosed_then_removedHeadEventFired() throws E
}
@Test
- public void given_ghPullRequestEventReopened_then_updatedHeadEventFired() throws Exception {
+ void given_ghPullRequestEventReopened_then_updatedHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.UPDATED;
@@ -129,7 +131,7 @@ public void given_ghPullRequestEventReopened_then_updatedHeadEventFired() throws
}
@Test
- public void given_ghPullRequestEventSync_then_updatedHeadEventFired() throws Exception {
+ void given_ghPullRequestEventSync_then_updatedHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.UPDATED;
@@ -138,7 +140,7 @@ public void given_ghPullRequestEventSync_then_updatedHeadEventFired() throws Exc
}
@Test
- public void given_ghPullRequestEventConvertedToDraft_then_updatedHeadEventFired() throws Exception {
+ void given_ghPullRequestEventConvertedToDraft_then_updatedHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.UPDATED;
@@ -147,7 +149,7 @@ public void given_ghPullRequestEventConvertedToDraft_then_updatedHeadEventFired(
}
@Test
- public void given_ghPullRequestEventReadyForReview_then_updatedHeadEventFired() throws Exception {
+ void given_ghPullRequestEventReadyForReview_then_updatedHeadEventFired() throws Exception {
PullRequestGHEventSubscriber subscriber = new PullRequestGHEventSubscriber();
firedEventType = SCMEvent.Type.UPDATED;
@@ -156,7 +158,7 @@ public void given_ghPullRequestEventReadyForReview_then_updatedHeadEventFired()
}
@Test
- public void given_ghRepositoryEventCreatedFromFork_then_createdSourceEventFired() throws Exception {
+ void given_ghRepositoryEventCreatedFromFork_then_createdSourceEventFired() throws Exception {
GitHubRepositoryEventSubscriber subscriber = new GitHubRepositoryEventSubscriber();
firedEventType = SCMEvent.Type.CREATED;
@@ -165,7 +167,7 @@ public void given_ghRepositoryEventCreatedFromFork_then_createdSourceEventFired(
}
@Test
- public void given_ghRepositoryEventCreatedNotFork_then_noSourceEventFired() throws Exception {
+ void given_ghRepositoryEventCreatedNotFork_then_noSourceEventFired() throws Exception {
GitHubRepositoryEventSubscriber subscriber = new GitHubRepositoryEventSubscriber();
ghEvent = callOnEvent(subscriber, "EventsTest/repositoryEventNotFiredNotFork.json");
@@ -173,40 +175,39 @@ public void given_ghRepositoryEventCreatedNotFork_then_noSourceEventFired() thro
}
@Test
- public void given_ghRepositoryEventWrongAction_then_noSourceEventFired() throws Exception {
+ void given_ghRepositoryEventWrongAction_then_noSourceEventFired() throws Exception {
GitHubRepositoryEventSubscriber subscriber = new GitHubRepositoryEventSubscriber();
ghEvent = callOnEvent(subscriber, "EventsTest/repositoryEventNotFiredWrongAction.json");
waitAndAssertReceived(false);
}
- private GHSubscriberEvent callOnEvent(PushGHEventSubscriber subscriber, String eventPayloadFile)
- throws IOException {
+ private GHSubscriberEvent callOnEvent(PushGHEventSubscriber subscriber, String eventPayloadFile) throws Exception {
GHSubscriberEvent event = createEvent(eventPayloadFile);
subscriber.onEvent(event);
return event;
}
private GHSubscriberEvent callOnEvent(PullRequestGHEventSubscriber subscriber, String eventPayloadFile)
- throws IOException {
+ throws Exception {
GHSubscriberEvent event = createEvent(eventPayloadFile);
subscriber.onEvent(event);
return event;
}
private GHSubscriberEvent callOnEvent(GitHubRepositoryEventSubscriber subscriber, String eventPayloadFile)
- throws IOException {
+ throws Exception {
GHSubscriberEvent event = createEvent(eventPayloadFile);
subscriber.onEvent(event);
return event;
}
- private GHSubscriberEvent createEvent(String eventPayloadFile) throws IOException {
- String payload = IOUtils.toString(getClass().getResourceAsStream(eventPayloadFile));
+ private GHSubscriberEvent createEvent(String eventPayloadFile) throws Exception {
+ String payload = IOUtils.toString(getClass().getResourceAsStream(eventPayloadFile), StandardCharsets.UTF_8);
return new GHSubscriberEvent("myOrigin", null, payload);
}
- private void waitAndAssertReceived(boolean received) throws InterruptedException {
+ private void waitAndAssertReceived(boolean received) throws Exception {
long watermark = SCMEvents.getWatermark();
// event will be fired by subscriber at some point
SCMEvents.awaitOne(watermark, received ? 20 : 200, TimeUnit.MILLISECONDS);
@@ -216,9 +217,9 @@ private void waitAndAssertReceived(boolean received) throws InterruptedException
}
assertEquals(
- "Event should have " + ((!received) ? "not " : "") + "been received",
received,
- TestSCMEventListener.didReceive());
+ TestSCMEventListener.didReceive(),
+ "Event should have " + ((!received) ? "not " : "") + "been received");
}
@TestExtension
@@ -237,8 +238,8 @@ public void onSCMSourceEvent(SCMSourceEvent> event) {
private void receiveEvent(SCMEvent.Type type, String origin) {
eventReceived = true;
- assertEquals("Event type should be the same", type, firedEventType);
- assertEquals("Event origin should be the same", origin, ghEvent.getOrigin());
+ assertEquals(type, firedEventType, "Event type should be the same");
+ assertEquals(origin, ghEvent.getOrigin(), "Event origin should be the same");
}
public static boolean didReceive() {
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java
index cb61162c6..c8efb3b45 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java
@@ -23,29 +23,35 @@
*/
package org.jenkinsci.plugins.github_branch_source;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import java.util.List;
import jenkins.branch.BranchSource;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.For;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
@For(ForkPullRequestDiscoveryTrait.class)
-public class ForkPullRequestDiscoveryTrait2Test {
+@WithJenkins
+class ForkPullRequestDiscoveryTrait2Test {
- @Rule
- public JenkinsRule r = new JenkinsRule();
+ private JenkinsRule r;
- @Ignore(
+ @BeforeEach
+ void beforeEach(JenkinsRule rule) {
+ r = rule;
+ }
+
+ @Disabled(
"These tests fail because users get automatically migrated to URL-based configuration if they re-save the GitHubSCMSource")
@Test
- public void configRoundtrip() throws Exception {
+ void configRoundtrip() throws Exception {
WorkflowMultiBranchProject p = r.createProject(WorkflowMultiBranchProject.class);
assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustNobody(), false);
@@ -55,13 +61,17 @@ public void configRoundtrip() throws Exception {
}
@Test
- public void configRoundtripWithRawUrl() throws Exception {
+ void configRoundtripWithRawUrl() throws Exception {
WorkflowMultiBranchProject p = r.createProject(WorkflowMultiBranchProject.class);
-
- assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustNobody(), true);
- assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustEveryone(), true);
- assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustContributors(), true);
- assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustPermission(), true);
+ try {
+ assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustNobody(), true);
+ assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustEveryone(), true);
+ assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustContributors(), true);
+ assertRoundTrip(p, new ForkPullRequestDiscoveryTrait.TrustPermission(), true);
+ } finally {
+ // branch indexing may still be running which causes problems during shutdown
+ p.delete();
+ }
}
private void assertRoundTrip(
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTraitTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTraitTest.java
index dbf93e8ee..2dd024c22 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTraitTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTraitTest.java
@@ -1,11 +1,11 @@
package org.jenkinsci.plugins.github_branch_source;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assume.assumeThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import hudson.util.XStream2;
import java.util.Collections;
@@ -15,23 +15,25 @@
import jenkins.scm.api.trait.SCMHeadFilter;
import jenkins.scm.api.trait.SCMHeadPrefilter;
import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+class ForkPullRequestDiscoveryTraitTest {
-public class ForkPullRequestDiscoveryTraitTest {
@Test
- public void xstream() throws Exception {
+ void xstream() {
System.out.println(new XStream2()
.toXML(new ForkPullRequestDiscoveryTrait(3, new ForkPullRequestDiscoveryTrait.TrustContributors())));
}
@Test
- public void given__discoverHeadMerge__when__appliedToContext__then__strategiesCorrect() throws Exception {
+ void given__discoverHeadMerge__when__appliedToContext__then__strategiesCorrect() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(ForkPullRequestDiscoveryTrait.TrustContributors.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof ForkPullRequestDiscoveryTrait.TrustContributors));
ForkPullRequestDiscoveryTrait instance = new ForkPullRequestDiscoveryTrait(
EnumSet.allOf(ChangeRequestCheckoutStrategy.class),
new ForkPullRequestDiscoveryTrait.TrustContributors());
@@ -45,13 +47,14 @@ public void given__discoverHeadMerge__when__appliedToContext__then__strategiesCo
}
@Test
- public void given__discoverHeadOnly__when__appliedToContext__then__strategiesCorrect() throws Exception {
+ void given__discoverHeadOnly__when__appliedToContext__then__strategiesCorrect() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(ForkPullRequestDiscoveryTrait.TrustContributors.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof ForkPullRequestDiscoveryTrait.TrustContributors));
ForkPullRequestDiscoveryTrait instance = new ForkPullRequestDiscoveryTrait(
EnumSet.of(ChangeRequestCheckoutStrategy.HEAD), new ForkPullRequestDiscoveryTrait.TrustContributors());
instance.decorateContext(ctx);
@@ -64,13 +67,14 @@ public void given__discoverHeadOnly__when__appliedToContext__then__strategiesCor
}
@Test
- public void given__discoverMergeOnly__when__appliedToContext__then__strategiesCorrect() throws Exception {
+ void given__discoverMergeOnly__when__appliedToContext__then__strategiesCorrect() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(ForkPullRequestDiscoveryTrait.TrustContributors.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof ForkPullRequestDiscoveryTrait.TrustContributors));
ForkPullRequestDiscoveryTrait instance = new ForkPullRequestDiscoveryTrait(
EnumSet.of(ChangeRequestCheckoutStrategy.MERGE), new ForkPullRequestDiscoveryTrait.TrustContributors());
instance.decorateContext(ctx);
@@ -83,13 +87,14 @@ public void given__discoverMergeOnly__when__appliedToContext__then__strategiesCo
}
@Test
- public void given__nonDefaultTrust__when__appliedToContext__then__authoritiesCorrect() throws Exception {
+ void given__nonDefaultTrust__when__appliedToContext__then__authoritiesCorrect() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.wantBranches(), is(false));
- assumeThat(ctx.wantPRs(), is(false));
- assumeThat(ctx.prefilters(), is(Collections.emptyList()));
- assumeThat(ctx.filters(), is(Collections.emptyList()));
- assumeThat(ctx.authorities(), not(hasItem(instanceOf(ForkPullRequestDiscoveryTrait.TrustContributors.class))));
+ assumeFalse(ctx.wantBranches());
+ assumeFalse(ctx.wantPRs());
+ assumeTrue(ctx.prefilters().isEmpty());
+ assumeTrue(ctx.filters().isEmpty());
+ assumeTrue(ctx.authorities().stream()
+ .noneMatch(item -> item instanceof ForkPullRequestDiscoveryTrait.TrustContributors));
ForkPullRequestDiscoveryTrait instance = new ForkPullRequestDiscoveryTrait(
EnumSet.allOf(ChangeRequestCheckoutStrategy.class), new ForkPullRequestDiscoveryTrait.TrustEveryone());
instance.decorateContext(ctx);
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsContextualizationTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsContextualizationTest.java
index 186700790..902c8ace2 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsContextualizationTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsContextualizationTest.java
@@ -17,15 +17,17 @@
import java.util.Arrays;
import jenkins.branch.BranchSource;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
@Issue("JENKINS-73474")
-public class GitHubAppCredentialsContextualizationTest extends AbstractGitHubWireMockTest {
+class GitHubAppCredentialsContextualizationTest extends AbstractGitHubWireMockTest {
- @Before
- public void setUpWireMock() throws Exception {
+ @Override
+ @BeforeEach
+ void beforeEach() throws Exception {
+ super.beforeEach();
GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);
// Add wiremock responses for App, App Installation, and App Installation Token
@@ -67,7 +69,7 @@ public void setUpWireMock() throws Exception {
}
@Test
- public void ownerMustBeInferredFromRepository() throws Exception {
+ void ownerMustBeInferredFromRepository() throws Exception {
final var store = CredentialsProvider.lookupStores(r.jenkins).iterator().next();
final var credentials = GitHubApp.createCredentials("myAppCredentialsWithoutOwner");
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsJCasCCompatibilityTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsJCasCCompatibilityTest.java
index a3cbac1c8..227d69077 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsJCasCCompatibilityTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentialsJCasCCompatibilityTest.java
@@ -14,10 +14,9 @@
import io.jenkins.plugins.casc.ConfigurationContext;
import io.jenkins.plugins.casc.ConfiguratorRegistry;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
-import io.jenkins.plugins.casc.misc.EnvVarsRule;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
+import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
import io.jenkins.plugins.casc.model.CNode;
-import io.jenkins.plugins.casc.model.Mapping;
import java.util.List;
import java.util.Objects;
import jenkins.model.Jenkins;
@@ -26,24 +25,18 @@
import org.jenkinsci.plugins.github_branch_source.app_credentials.AccessSpecifiedRepositories;
import org.jenkinsci.plugins.github_branch_source.app_credentials.DefaultPermissionsStrategy;
import org.jenkinsci.plugins.github_branch_source.app_credentials.RepositoryAccessStrategy;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
+import org.junit.jupiter.api.Test;
+import org.junitpioneer.jupiter.SetEnvironmentVariable;
-public class GitHubAppCredentialsJCasCCompatibilityTest {
+@WithJenkinsConfiguredWithCode
+@SetEnvironmentVariable(key = "GITHUB_APP_KEY", value = GitHubAppCredentialsJCasCCompatibilityTest.GITHUB_APP_KEY)
+class GitHubAppCredentialsJCasCCompatibilityTest {
- @ConfiguredWithCode("github-app-jcasc-minimal.yaml")
- public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
-
- private static final String GITHUB_APP_KEY = "SomeString";
-
- @ClassRule
- public static RuleChain chain = RuleChain.outerRule(new EnvVarsRule().set("GITHUB_APP_KEY", GITHUB_APP_KEY))
- .around(j);
+ protected static final String GITHUB_APP_KEY = "SomeString";
@Test
@ConfiguredWithCode("github-app-jcasc-minimal.yaml")
- public void should_support_configuration_as_code() throws Exception {
+ void should_support_configuration_as_code(JenkinsConfiguredWithCodeRule j) {
List domainCredentials =
SystemCredentialsProvider.getInstance().getDomainCredentials();
@@ -80,7 +73,7 @@ public void should_support_configuration_as_code() throws Exception {
@Test
@ConfiguredWithCode("github-app-jcasc-minimal.yaml")
- public void should_support_configuration_export() throws Exception {
+ void should_support_configuration_export(JenkinsConfiguredWithCodeRule j) throws Exception {
CNode credentials = getCredentials();
String exported = toYamlString(credentials)
@@ -102,9 +95,8 @@ private CNode getCredentials() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
- Mapping configNode = Objects.requireNonNull(root.describe(root.getTargetComponent(context), context))
+ return Objects.requireNonNull(root.describe(root.getTargetComponent(context), context))
.asMapping();
- return configNode;
}
private static void assertGitHubAppCredential(
@@ -127,8 +119,7 @@ private static void assertGitHubAppCredential(
assertThat(appCredentials.getDefaultPermissionsStrategy(), is(permissionsStrategy));
var actualRepoStrategy = appCredentials.getRepositoryAccessStrategy();
assertThat(actualRepoStrategy.getClass(), is(repoStrategy.getClass()));
- if (actualRepoStrategy instanceof AccessSpecifiedRepositories) {
- var actualRepos = (AccessSpecifiedRepositories) actualRepoStrategy;
+ if (actualRepoStrategy instanceof AccessSpecifiedRepositories actualRepos) {
var expectedRepos = (AccessSpecifiedRepositories) repoStrategy;
assertThat(actualRepos.getOwner(), is(expectedRepos.getOwner()));
assertThat(actualRepos.getRepositories(), is(expectedRepos.getRepositories()));
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubBranchSourcesJCasCCompatibilityTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubBranchSourcesJCasCCompatibilityTest.java
index a76d1b614..d4b364fb4 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubBranchSourcesJCasCCompatibilityTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubBranchSourcesJCasCCompatibilityTest.java
@@ -1,21 +1,21 @@
package org.jenkinsci.plugins.github_branch_source;
import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
+import io.jenkins.plugins.casc.misc.junit.jupiter.AbstractRoundTripTest;
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever;
import org.jvnet.hudson.test.Issue;
-import org.jvnet.hudson.test.RestartableJenkinsRule;
+import org.jvnet.hudson.test.JenkinsRule;
-public class GitHubBranchSourcesJCasCCompatibilityTest extends RoundTripAbstractTest {
+class GitHubBranchSourcesJCasCCompatibilityTest extends AbstractRoundTripTest {
@Issue("JENKINS-57557")
@Override
- protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
+ protected void assertConfiguredAsExpected(JenkinsRule rule, String s) {
assertEquals(1, GlobalLibraries.get().getLibraries().size());
final LibraryConfiguration library =
GlobalLibraries.get().getLibraries().get(0);
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationTest.java
index bba0c496b..126990b77 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationTest.java
@@ -24,23 +24,24 @@
package org.jenkinsci.plugins.github_branch_source;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assume.assumeThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import hudson.model.TaskListener;
import java.util.Collections;
import java.util.List;
import jenkins.scm.api.SCMHeadObserver;
import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class GitHubNotificationTest {
+class GitHubNotificationTest {
@Test
- public void given__notificationsDisabled__when__appliedToContext__then__notificationsDisabled() throws Exception {
+ void given__notificationsDisabled__when__appliedToContext__then__notificationsDisabled() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationsDisabled(), is(false));
+ assumeFalse(ctx.notificationsDisabled());
ctx.withNotificationsDisabled(true);
assertThat(ctx.notificationsDisabled(), is(true));
ctx.withNotificationsDisabled(false);
@@ -48,25 +49,25 @@ public void given__notificationsDisabled__when__appliedToContext__then__notifica
}
@Test
- public void given__defaultNotificationStrategy__when__appliedToContext__then__duplicatesRemoved() throws Exception {
+ void given__defaultNotificationStrategy__when__appliedToContext__then__duplicatesRemoved() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationStrategies().size(), is(1));
+ assumeTrue(ctx.notificationStrategies().size() == 1);
ctx.withNotificationStrategy(new DefaultGitHubNotificationStrategy());
assertThat(ctx.notificationStrategies().size(), is(1));
}
@Test
- public void given__emptyStrategiesList__when__appliedToContext__then__defaultApplied() throws Exception {
+ void given__emptyStrategiesList__when__appliedToContext__then__defaultApplied() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationStrategies().size(), is(1));
+ assumeTrue(ctx.notificationStrategies().size() == 1);
ctx.withNotificationStrategies(Collections.emptyList());
assertThat(ctx.notificationStrategies().size(), is(1));
}
@Test
- public void given__defaultStrategy__when__emptyStrategyList__then__strategyAdded() throws Exception {
+ void given__defaultStrategy__when__emptyStrategyList__then__strategyAdded() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationStrategies().size(), is(1));
+ assumeTrue(ctx.notificationStrategies().size() == 1);
ctx.withNotificationStrategies(Collections.emptyList());
assertThat(ctx.notificationStrategies().size(), is(1));
ctx.withNotificationStrategy(new DefaultGitHubNotificationStrategy());
@@ -74,9 +75,9 @@ public void given__defaultStrategy__when__emptyStrategyList__then__strategyAdded
}
@Test
- public void given__defaultStrategyList__when__emptyStrategyList__then__strategyAdded() throws Exception {
+ void given__defaultStrategyList__when__emptyStrategyList__then__strategyAdded() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationStrategies().size(), is(1));
+ assumeTrue(ctx.notificationStrategies().size() == 1);
ctx.withNotificationStrategies(Collections.emptyList());
assertThat(ctx.notificationStrategies().size(), is(1));
ctx.withNotificationStrategies(Collections.singletonList(new DefaultGitHubNotificationStrategy()));
@@ -84,16 +85,16 @@ public void given__defaultStrategyList__when__emptyStrategyList__then__strategyA
}
@Test
- public void given__customStrategy__when__emptyStrategyList__then__noDefaultStrategy() throws Exception {
+ void given__customStrategy__when__emptyStrategyList__then__noDefaultStrategy() {
GitHubSCMSourceContext ctx = new GitHubSCMSourceContext(null, SCMHeadObserver.none());
- assumeThat(ctx.notificationStrategies().size(), is(1));
+ assumeTrue(ctx.notificationStrategies().size() == 1);
ctx.withNotificationStrategy(new TestNotificationStrategy());
List strategies = ctx.notificationStrategies();
assertThat(strategies.size(), is(1));
assertThat(strategies.get(0), Matchers.instanceOf(TestNotificationStrategy.class));
}
- private final class TestNotificationStrategy extends AbstractGitHubNotificationStrategy {
+ private static class TestNotificationStrategy extends AbstractGitHubNotificationStrategy {
@Override
public List notifications(
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java
index 61e64bf1f..8057bd5ea 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java
@@ -27,43 +27,52 @@
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import org.junit.Rule;
-import org.junit.Test;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.kohsuke.github.GitHub;
-public class GitHubOrgWebHookTest {
+@WithJenkins
+class GitHubOrgWebHookTest {
- @Rule
- public JenkinsRule r = new JenkinsRule();
+ @RegisterExtension
+ private static final WireMockExtension WIRE_MOCK_EXTENSION = WireMockExtension.newInstance()
+ .options(wireMockConfig().dynamicPort())
+ .build();
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+ private JenkinsRule r;
+
+ @BeforeEach
+ void beforeEach(JenkinsRule rule) {
+ r = rule;
+ }
@Issue("JENKINS-58942")
@Test
- public void registerCustom() throws Exception {
+ void registerCustom() throws Exception {
System.setProperty("jenkins.hook.url", "https://mycorp/hook-proxy/");
// Return 404 for /rate_limit
- wireMockRule.stubFor(
+ WIRE_MOCK_EXTENSION.stubFor(
get(urlEqualTo("/api/rate_limit")).willReturn(aResponse().withStatus(404)));
// validate api url
- wireMockRule.stubFor(get(urlEqualTo("/api/"))
+ WIRE_MOCK_EXTENSION.stubFor(get(urlEqualTo("/api/"))
.willReturn(aResponse().withBody("{\"rate_limit_url\": \"https://localhost/placeholder/\"}")));
- wireMockRule.stubFor(
+ WIRE_MOCK_EXTENSION.stubFor(
get(urlEqualTo("/api/users/myorg")).willReturn(aResponse().withBody("{\"login\":\"myorg\"}")));
- wireMockRule.stubFor(get(urlEqualTo("/api/orgs/myorg"))
+ WIRE_MOCK_EXTENSION.stubFor(get(urlEqualTo("/api/orgs/myorg"))
.willReturn(aResponse().withBody("{\"login\":\"myorg\",\"html_url\":\"https://github.com/myorg\"}")));
- wireMockRule.stubFor(
+ WIRE_MOCK_EXTENSION.stubFor(
get(urlEqualTo("/api/orgs/myorg/hooks")).willReturn(aResponse().withBody("[]")));
- wireMockRule.stubFor(post(urlEqualTo("/api/orgs/myorg/hooks"))
+ WIRE_MOCK_EXTENSION.stubFor(post(urlEqualTo("/api/orgs/myorg/hooks"))
.withRequestBody(matchingJsonPath("$.config.url", equalTo("https://mycorp/hook-proxy/github-webhook/")))
.willReturn(aResponse().withBody("{}")));
- GitHub hub = Connector.connect("http://localhost:" + wireMockRule.port() + "/api/", null);
+ GitHub hub = Connector.connect("http://localhost:" + WIRE_MOCK_EXTENSION.getPort() + "/api/", null);
try {
GitHubOrgWebHook.register(hub, "myorg");
} finally {
diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java
index 1b39e0f4c..99a699b9b 100644
--- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java
+++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java
@@ -4,6 +4,7 @@
import static java.util.logging.Logger.getAnonymousLogger;
import static jenkins.plugins.git.AbstractGitSCMSource.SCMRevisionImpl;
import static jenkins.plugins.git.AbstractGitSCMSource.SpecificRevisionBuildChooser;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
@@ -11,7 +12,6 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
@@ -20,7 +20,6 @@
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
-import hudson.model.Descriptor;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.UserRemoteConfig;
@@ -28,7 +27,6 @@
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.BuildChooserSetting;
import hudson.util.LogTaskListener;
-import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -42,39 +40,34 @@
import org.eclipse.jgit.transport.RemoteConfig;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.ValueSource;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.mockito.Mockito;
-@RunWith(Parameterized.class)
-public class GitHubSCMBuilderTest {
- @ClassRule
- public static JenkinsRule j = new JenkinsRule();
+@ParameterizedClass
+@ValueSource(booleans = {true, false})
+@WithJenkins
+class GitHubSCMBuilderTest {
+
+ private static JenkinsRule j;
private GitHubSCMSource source;
private WorkflowMultiBranchProject owner;
- private boolean configuredByUrl;
- @Parameterized.Parameters
- public static Collection