From 3349fb3698cd89fe06dc29fe480740fad2da675f Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Thu, 4 Aug 2022 12:45:08 -0700 Subject: [PATCH 1/2] Upgrade plugin parent POM --- pom.xml | 38 +------------------ .../cloudbees/jenkins/GitHubPushTrigger.java | 5 +++ .../plugins/github/GithubLinkAction.java | 2 +- .../plugins/github/GithubLinkAnnotator.java | 6 +-- .../plugins/github/GithubProjectProperty.java | 2 +- .../hudson/plugins/github/GithubUrl.java | 2 +- .../github/config/GitHubServerConfig.java | 2 +- .../plugins/github/util/BuildDataHelper.java | 2 +- .../webhook/RequirePostWithGHHookPayload.java | 2 +- .../jenkins/GitHubCommitNotifierTest.java | 15 +++----- .../GitHubSetCommitStatusBuilderTest.java | 15 +++----- .../GitHubWebHookCrumbExclusionTest.java | 4 +- .../cloudbees/jenkins/GitHubWebHookTest.java | 2 +- .../jenkins/GlobalConfigSubmitTest.java | 1 - .../github/GitHubRepositoryNameTest.java | 2 +- .../github/GithubLinkActionFactoryTest.java | 2 +- .../github/GithubProjectPropertyTest.java | 4 +- .../hudson/plugins/github/GithubUrlTest.java | 2 +- .../plugins/github/admin/GHRepoNameTest.java | 4 +- .../GitHubHookRegisterProblemMonitorTest.java | 4 +- .../github/admin/ValidateRepoNameTest.java | 2 +- .../common/CombineErrorHandlerTest.java | 4 +- .../github/config/ConfigAsCodeTest.java | 6 ++- .../github/config/GitHubServerConfigTest.java | 2 +- .../github/config/HookSecretConfigTest.java | 2 +- .../github/extension/CryptoUtilTest.java | 2 +- .../GitHubClientCacheCleanupTest.java | 2 - .../status/GitHubCommitStatusSetterTest.java | 15 +++----- .../github/status/err/ErrorHandlersTest.java | 4 +- .../sources/BuildRefBackrefSourceTest.java | 5 +-- .../ConditionalStatusResultSourceTest.java | 4 +- .../ManuallyEnteredRepositorySourceTest.java | 6 +-- .../sources/ManuallyEnteredSourcesTest.java | 12 +++--- .../sources/misc/AnyBuildResultTest.java | 2 +- .../BetterThanOrEqualBuildResultTest.java | 2 +- .../github/util/JobInfoHelpersTest.java | 2 +- .../github/webhook/GHEventHeaderTest.java | 2 +- .../github/webhook/GHEventPayloadTest.java | 2 +- .../RequirePostWithGHHookPayloadTest.java | 2 +- .../github/webhook/WebhookManagerTest.java | 37 ++++++++++-------- .../DefaultPushGHEventListenerTest.java | 2 +- 41 files changed, 99 insertions(+), 134 deletions(-) diff --git a/pom.xml b/pom.xml index 5e501f419..3a4ed8856 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.40 + 4.45 @@ -52,15 +52,7 @@ jenkinsci/github-plugin 2.346.1 false - true - 3.0.4 - 2.2 - 1 - 1.14.2 v@{project.version} - Low - Max - false @@ -146,37 +138,9 @@ test - - org.hamcrest - hamcrest - ${hamcrest.version} - test - - - - org.hamcrest - hamcrest-core - ${hamcrest.version} - test - - - - org.hamcrest - hamcrest-library - ${hamcrest.version} - test - - - - junit - junit - test - - org.mockito mockito-core - 1.10.19 test diff --git a/src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java b/src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java index 7d1154ee5..46360f93d 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java @@ -2,6 +2,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Preconditions; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.Util; import hudson.XmlFile; @@ -270,6 +271,10 @@ public String getLog() throws IOException { * * @since 1.350 */ + @SuppressFBWarnings( + value = "RV_RETURN_VALUE_IGNORED", + justification = + "method signature does not permit plumbing through the return value") public void writeLogTo(XMLOutput out) throws IOException { new AnnotatedLargeText(getLogFileForJob(job), Charsets.UTF_8, true, this) .writeHtmlTo(0, out.asWriter()); diff --git a/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAction.java b/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAction.java index 142b27b16..3bc03dc8a 100644 --- a/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAction.java +++ b/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAction.java @@ -12,7 +12,7 @@ /** * Add the Github Logo/Icon to the sidebar. * - * @author Stefan Saasen + * @author Stefan Saasen */ public final class GithubLinkAction implements Action { diff --git a/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAnnotator.java b/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAnnotator.java index 2556c2532..fcac430d8 100644 --- a/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAnnotator.java +++ b/src/main/java/com/coravy/hudson/plugins/github/GithubLinkAnnotator.java @@ -17,11 +17,11 @@ *

* It's based on the TracLinkAnnotator. *

- * - * @author Stefan Saasen - * @todo Change the annotator to use GithubUrl instead of the String url. + * TODO Change the annotator to use GithubUrl instead of the String url. * Knowledge about the github url structure should be encapsulated in * GithubUrl. + * + * @author Stefan Saasen */ @Extension public class GithubLinkAnnotator extends ChangeLogAnnotator { diff --git a/src/main/java/com/coravy/hudson/plugins/github/GithubProjectProperty.java b/src/main/java/com/coravy/hudson/plugins/github/GithubProjectProperty.java index 25e1a2bf5..25892809e 100644 --- a/src/main/java/com/coravy/hudson/plugins/github/GithubProjectProperty.java +++ b/src/main/java/com/coravy/hudson/plugins/github/GithubProjectProperty.java @@ -24,7 +24,7 @@ * - URL to the GitHub project * - Build status context name * - * @author Stefan Saasen + * @author Stefan Saasen */ public final class GithubProjectProperty extends JobProperty> { diff --git a/src/main/java/com/coravy/hudson/plugins/github/GithubUrl.java b/src/main/java/com/coravy/hudson/plugins/github/GithubUrl.java index b331adcb3..14c6e821a 100644 --- a/src/main/java/com/coravy/hudson/plugins/github/GithubUrl.java +++ b/src/main/java/com/coravy/hudson/plugins/github/GithubUrl.java @@ -3,7 +3,7 @@ import org.apache.commons.lang.StringUtils; /** - * @author Stefan Saasen + * @author Stefan Saasen */ public final class GithubUrl { diff --git a/src/main/java/org/jenkinsci/plugins/github/config/GitHubServerConfig.java b/src/main/java/org/jenkinsci/plugins/github/config/GitHubServerConfig.java index 68df0464b..4d6b29b75 100644 --- a/src/main/java/org/jenkinsci/plugins/github/config/GitHubServerConfig.java +++ b/src/main/java/org/jenkinsci/plugins/github/config/GitHubServerConfig.java @@ -214,7 +214,7 @@ public int getClientCacheSize() { } /** - * @param clientCacheSize capacity of cache for GitHub client in MB, set to <= 0 to turn off this feature + * @param clientCacheSize capacity of cache for GitHub client in MB, set to <= 0 to turn off this feature */ @DataBoundSetter public void setClientCacheSize(int clientCacheSize) { diff --git a/src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java b/src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java index fa89bc443..b4a8e72bd 100644 --- a/src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java +++ b/src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java @@ -15,7 +15,7 @@ /** * Stores common methods for {@link BuildData} handling. * - * @author Oleg Nenashev + * @author Oleg Nenashev * @since 1.10 */ public final class BuildDataHelper { diff --git a/src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java b/src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java index 5ff8c790a..4e19fe132 100644 --- a/src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java +++ b/src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java @@ -81,7 +81,7 @@ public Object invoke(StaplerRequest req, StaplerResponse rsp, Object instance, O } /** - * Duplicates {@link @org.kohsuke.stapler.interceptor.RequirePOST} precheck. + * Duplicates {@link org.kohsuke.stapler.interceptor.RequirePOST} precheck. * As of it can't guarantee order of multiply interceptor calls, * it should implement all features of required interceptors in one class * diff --git a/src/test/java/com/cloudbees/jenkins/GitHubCommitNotifierTest.java b/src/test/java/com/cloudbees/jenkins/GitHubCommitNotifierTest.java index 50f167f6b..31f620003 100644 --- a/src/test/java/com/cloudbees/jenkins/GitHubCommitNotifierTest.java +++ b/src/test/java/com/cloudbees/jenkins/GitHubCommitNotifierTest.java @@ -18,9 +18,9 @@ import org.jenkinsci.plugins.github.test.GHMockRule; import org.jenkinsci.plugins.github.test.GHMockRule.FixedGHRepoNameTestContributor; import org.jenkinsci.plugins.github.test.InjectJenkinsMembersRule; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExternalResource; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.jvnet.hudson.test.Issue; @@ -28,7 +28,7 @@ import org.jvnet.hudson.test.TestBuilder; import org.jvnet.hudson.test.TestExtension; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.inject.Inject; @@ -43,7 +43,7 @@ /** * Tests for {@link GitHubCommitNotifier}. * - * @author Oleg Nenashev + * @author Oleg Nenashev */ @RunWith(MockitoJUnitRunner.class) public class GitHubCommitNotifierTest { @@ -72,15 +72,12 @@ public class GitHubCommitNotifierTest { .stubStatuses(); - @Rule - public ExternalResource prep = new ExternalResource() { - @Override - protected void before() throws Throwable { + @Before + public void before() throws Throwable { when(data.getLastBuiltRevision()).thenReturn(rev); data.lastBuild = new hudson.plugins.git.util.Build(rev, rev, 0, Result.SUCCESS); when(rev.getSha1()).thenReturn(ObjectId.fromString(SOME_SHA)); - } - }; + } @Test @Issue("JENKINS-23641") diff --git a/src/test/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilderTest.java b/src/test/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilderTest.java index 7e03528b7..a28074f9c 100644 --- a/src/test/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilderTest.java +++ b/src/test/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilderTest.java @@ -17,9 +17,9 @@ import org.jenkinsci.plugins.github.test.GHMockRule; import org.jenkinsci.plugins.github.test.GHMockRule.FixedGHRepoNameTestContributor; import org.jenkinsci.plugins.github.test.InjectJenkinsMembersRule; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExternalResource; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.jvnet.hudson.test.Issue; @@ -28,7 +28,7 @@ import org.jvnet.hudson.test.TestExtension; import org.jvnet.hudson.test.recipes.LocalData; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.inject.Inject; import java.util.List; @@ -42,7 +42,7 @@ /** * Tests for {@link GitHubSetCommitStatusBuilder}. * - * @author Oleg Nenashev + * @author Oleg Nenashev */ @RunWith(MockitoJUnitRunner.class) public class GitHubSetCommitStatusBuilderTest { @@ -72,15 +72,12 @@ public class GitHubSetCommitStatusBuilderTest { .stubRepo() .stubStatuses(); - @Rule - public ExternalResource prep = new ExternalResource() { - @Override - protected void before() throws Throwable { + @Before + public void before() throws Throwable { when(data.getLastBuiltRevision()).thenReturn(rev); data.lastBuild = new hudson.plugins.git.util.Build(rev, rev, 0, Result.SUCCESS); when(rev.getSha1()).thenReturn(ObjectId.fromString(SOME_SHA)); - } - }; + } @Test @Issue("JENKINS-23641") diff --git a/src/test/java/com/cloudbees/jenkins/GitHubWebHookCrumbExclusionTest.java b/src/test/java/com/cloudbees/jenkins/GitHubWebHookCrumbExclusionTest.java index fcf8317e1..683eee85f 100644 --- a/src/test/java/com/cloudbees/jenkins/GitHubWebHookCrumbExclusionTest.java +++ b/src/test/java/com/cloudbees/jenkins/GitHubWebHookCrumbExclusionTest.java @@ -7,8 +7,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import static junit.framework.Assert.assertFalse; -import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/src/test/java/com/cloudbees/jenkins/GitHubWebHookTest.java b/src/test/java/com/cloudbees/jenkins/GitHubWebHookTest.java index 0f1c367e9..668d50783 100644 --- a/src/test/java/com/cloudbees/jenkins/GitHubWebHookTest.java +++ b/src/test/java/com/cloudbees/jenkins/GitHubWebHookTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.everyItem; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author lanwen (Merkushev Kirill) diff --git a/src/test/java/com/cloudbees/jenkins/GlobalConfigSubmitTest.java b/src/test/java/com/cloudbees/jenkins/GlobalConfigSubmitTest.java index c1c313f3b..847268cf3 100644 --- a/src/test/java/com/cloudbees/jenkins/GlobalConfigSubmitTest.java +++ b/src/test/java/com/cloudbees/jenkins/GlobalConfigSubmitTest.java @@ -14,7 +14,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; /** * Test Class for {@link GitHubPushTrigger}. diff --git a/src/test/java/com/coravy/hudson/plugins/github/GitHubRepositoryNameTest.java b/src/test/java/com/coravy/hudson/plugins/github/GitHubRepositoryNameTest.java index db2139aaf..b22dc7bc5 100644 --- a/src/test/java/com/coravy/hudson/plugins/github/GitHubRepositoryNameTest.java +++ b/src/test/java/com/coravy/hudson/plugins/github/GitHubRepositoryNameTest.java @@ -15,7 +15,7 @@ import static org.jenkinsci.plugins.github.test.GitHubRepoNameMatchers.withHost; import static org.jenkinsci.plugins.github.test.GitHubRepoNameMatchers.withRepoName; import static org.jenkinsci.plugins.github.test.GitHubRepoNameMatchers.withUserName; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Unit tests of {@link GitHubRepositoryName} diff --git a/src/test/java/com/coravy/hudson/plugins/github/GithubLinkActionFactoryTest.java b/src/test/java/com/coravy/hudson/plugins/github/GithubLinkActionFactoryTest.java index cef4e8bfa..60cd872f8 100644 --- a/src/test/java/com/coravy/hudson/plugins/github/GithubLinkActionFactoryTest.java +++ b/src/test/java/com/coravy/hudson/plugins/github/GithubLinkActionFactoryTest.java @@ -3,7 +3,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Collection; diff --git a/src/test/java/com/coravy/hudson/plugins/github/GithubProjectPropertyTest.java b/src/test/java/com/coravy/hudson/plugins/github/GithubProjectPropertyTest.java index 545e5aff5..f99b3ae27 100644 --- a/src/test/java/com/coravy/hudson/plugins/github/GithubProjectPropertyTest.java +++ b/src/test/java/com/coravy/hudson/plugins/github/GithubProjectPropertyTest.java @@ -4,7 +4,9 @@ import org.jenkinsci.plugins.workflow.structs.DescribableHelper; import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Rule; import org.jvnet.hudson.test.JenkinsRule; diff --git a/src/test/java/com/coravy/hudson/plugins/github/GithubUrlTest.java b/src/test/java/com/coravy/hudson/plugins/github/GithubUrlTest.java index 702dd9941..9ec0b032b 100644 --- a/src/test/java/com/coravy/hudson/plugins/github/GithubUrlTest.java +++ b/src/test/java/com/coravy/hudson/plugins/github/GithubUrlTest.java @@ -1,6 +1,6 @@ package com.coravy.hudson.plugins.github; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.Before; diff --git a/src/test/java/org/jenkinsci/plugins/github/admin/GHRepoNameTest.java b/src/test/java/org/jenkinsci/plugins/github/admin/GHRepoNameTest.java index e95f695c2..0ca4bf62c 100644 --- a/src/test/java/org/jenkinsci/plugins/github/admin/GHRepoNameTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/admin/GHRepoNameTest.java @@ -5,11 +5,11 @@ import org.junit.runner.RunWith; import org.kohsuke.stapler.StaplerRequest; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; /** diff --git a/src/test/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitorTest.java b/src/test/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitorTest.java index 8a4f3e875..93d2db50b 100644 --- a/src/test/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitorTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitorTest.java @@ -23,7 +23,7 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.inject.Inject; import java.io.IOException; @@ -39,7 +39,7 @@ 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.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; /** diff --git a/src/test/java/org/jenkinsci/plugins/github/admin/ValidateRepoNameTest.java b/src/test/java/org/jenkinsci/plugins/github/admin/ValidateRepoNameTest.java index 4cb120809..f0fdb0db4 100644 --- a/src/test/java/org/jenkinsci/plugins/github/admin/ValidateRepoNameTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/admin/ValidateRepoNameTest.java @@ -9,7 +9,7 @@ import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/jenkinsci/plugins/github/common/CombineErrorHandlerTest.java b/src/test/java/org/jenkinsci/plugins/github/common/CombineErrorHandlerTest.java index e478869e2..e64e248cf 100644 --- a/src/test/java/org/jenkinsci/plugins/github/common/CombineErrorHandlerTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/common/CombineErrorHandlerTest.java @@ -11,7 +11,7 @@ import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Collections; @@ -20,7 +20,7 @@ import static java.util.Arrays.asList; import static org.hamcrest.Matchers.is; import static org.jenkinsci.plugins.github.common.CombineErrorHandler.errorHandling; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; diff --git a/src/test/java/org/jenkinsci/plugins/github/config/ConfigAsCodeTest.java b/src/test/java/org/jenkinsci/plugins/github/config/ConfigAsCodeTest.java index 984e6e848..2888c7d3f 100755 --- a/src/test/java/org/jenkinsci/plugins/github/config/ConfigAsCodeTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/config/ConfigAsCodeTest.java @@ -13,7 +13,11 @@ import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static org.jenkinsci.plugins.github.test.GitHubServerConfigMatcher.*; public class ConfigAsCodeTest { diff --git a/src/test/java/org/jenkinsci/plugins/github/config/GitHubServerConfigTest.java b/src/test/java/org/jenkinsci/plugins/github/config/GitHubServerConfigTest.java index c1859bfaa..78a2c1d1f 100644 --- a/src/test/java/org/jenkinsci/plugins/github/config/GitHubServerConfigTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/config/GitHubServerConfigTest.java @@ -10,7 +10,7 @@ import static org.jenkinsci.plugins.github.config.GitHubServerConfig.allowedToManageHooks; import static org.jenkinsci.plugins.github.config.GitHubServerConfig.isUrlCustom; import static org.jenkinsci.plugins.github.config.GitHubServerConfig.withHost; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author lanwen (Merkushev Kirill) diff --git a/src/test/java/org/jenkinsci/plugins/github/config/HookSecretConfigTest.java b/src/test/java/org/jenkinsci/plugins/github/config/HookSecretConfigTest.java index d5d4bf708..8e73fcc11 100644 --- a/src/test/java/org/jenkinsci/plugins/github/config/HookSecretConfigTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/config/HookSecretConfigTest.java @@ -36,7 +36,7 @@ public void shouldStoreNewSecrets() { hookSecretConfig = GitHubPlugin.configuration().getHookSecretConfig(); assertNotNull("Secret is persistent", hookSecretConfig.getHookSecret()); - assertTrue("Secret correctly stored", SECRET_INIT.equals(hookSecretConfig.getHookSecret().getPlainText())); + assertEquals("Secret correctly stored", SECRET_INIT, hookSecretConfig.getHookSecret().getPlainText()); } @Test diff --git a/src/test/java/org/jenkinsci/plugins/github/extension/CryptoUtilTest.java b/src/test/java/org/jenkinsci/plugins/github/extension/CryptoUtilTest.java index c65877a15..0be1f0a13 100644 --- a/src/test/java/org/jenkinsci/plugins/github/extension/CryptoUtilTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/extension/CryptoUtilTest.java @@ -7,7 +7,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.jenkinsci.plugins.github.webhook.GHWebhookSignature.webhookSignature; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Tests for utility class that deals with crypto/hashing of data. diff --git a/src/test/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheCleanupTest.java b/src/test/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheCleanupTest.java index 7a7b0c7b3..45250e78f 100644 --- a/src/test/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheCleanupTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/internal/GitHubClientCacheCleanupTest.java @@ -21,8 +21,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; import static org.jenkinsci.plugins.github.internal.GitHubClientCacheOps.clearRedundantCaches; import static org.jenkinsci.plugins.github.internal.GitHubClientCacheOps.getBaseCacheDir; import static org.junit.Assume.assumeThat; diff --git a/src/test/java/org/jenkinsci/plugins/github/status/GitHubCommitStatusSetterTest.java b/src/test/java/org/jenkinsci/plugins/github/status/GitHubCommitStatusSetterTest.java index 1b13af21a..ab6434c00 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/GitHubCommitStatusSetterTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/GitHubCommitStatusSetterTest.java @@ -23,16 +23,16 @@ import org.jenkinsci.plugins.github.test.GHMockRule; import org.jenkinsci.plugins.github.test.GHMockRule.FixedGHRepoNameTestContributor; import org.jenkinsci.plugins.github.test.InjectJenkinsMembersRule; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExternalResource; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.TestBuilder; import org.jvnet.hudson.test.TestExtension; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.inject.Inject; import java.util.Collections; @@ -45,7 +45,7 @@ /** * Tests for {@link GitHubSetCommitStatusBuilder}. * - * @author Oleg Nenashev + * @author Oleg Nenashev */ @RunWith(MockitoJUnitRunner.class) public class GitHubCommitStatusSetterTest { @@ -75,15 +75,12 @@ public class GitHubCommitStatusSetterTest { .stubRepo() .stubStatuses(); - @Rule - public ExternalResource prep = new ExternalResource() { - @Override - protected void before() throws Throwable { + @Before + public void before() throws Throwable { when(data.getLastBuiltRevision()).thenReturn(rev); data.lastBuild = new hudson.plugins.git.util.Build(rev, rev, 0, Result.SUCCESS); when(rev.getSha1()).thenReturn(ObjectId.fromString(SOME_SHA)); - } - }; + } @Test diff --git a/src/test/java/org/jenkinsci/plugins/github/status/err/ErrorHandlersTest.java b/src/test/java/org/jenkinsci/plugins/github/status/err/ErrorHandlersTest.java index d225e9660..2bbe64a36 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/err/ErrorHandlersTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/err/ErrorHandlersTest.java @@ -7,10 +7,10 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.verify; /** diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.java index ec46021e7..fea0e24a7 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/BuildRefBackrefSourceTest.java @@ -10,13 +10,10 @@ import org.jvnet.hudson.test.JenkinsRule; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.when; /** * @author pupssman (Kalinin Ivan) diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/ConditionalStatusResultSourceTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/ConditionalStatusResultSourceTest.java index 683d7a037..ab5bd0a24 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/ConditionalStatusResultSourceTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/ConditionalStatusResultSourceTest.java @@ -11,7 +11,7 @@ import org.kohsuke.github.GHCommitState; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Collections; @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.jenkinsci.plugins.github.status.sources.misc.BetterThanOrEqualBuildResult.betterThanOrEqualTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; /** diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredRepositorySourceTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredRepositorySourceTest.java index 7bda2012e..954f9ff48 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredRepositorySourceTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredRepositorySourceTest.java @@ -7,16 +7,16 @@ import org.kohsuke.github.GHRepository; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.PrintStream; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredSourcesTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredSourcesTest.java index b583fd113..791da1f22 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredSourcesTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/ManuallyEnteredSourcesTest.java @@ -6,12 +6,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; /** @@ -34,7 +34,7 @@ public class ManuallyEnteredSourcesTest { @Test public void shouldExpandContext() throws Exception { when(run.getEnvironment(listener)).thenReturn(env); - when(env.expand(Matchers.anyString())).thenReturn(EXPANDED); + when(env.expand(ArgumentMatchers.anyString())).thenReturn(EXPANDED); String context = new ManuallyEnteredCommitContextSource("").context(run, listener); assertThat(context, equalTo(EXPANDED)); @@ -43,7 +43,7 @@ public void shouldExpandContext() throws Exception { @Test public void shouldExpandSha() throws Exception { when(run.getEnvironment(listener)).thenReturn(env); - when(env.expand(Matchers.anyString())).thenReturn(EXPANDED); + when(env.expand(ArgumentMatchers.anyString())).thenReturn(EXPANDED); String context = new ManuallyEnteredShaSource("").get(run, listener); assertThat(context, equalTo(EXPANDED)); @@ -52,7 +52,7 @@ public void shouldExpandSha() throws Exception { @Test public void shouldExpandBackref() throws Exception { when(run.getEnvironment(listener)).thenReturn(env); - when(env.expand(Matchers.anyString())).thenReturn(EXPANDED); + when(env.expand(ArgumentMatchers.anyString())).thenReturn(EXPANDED); String context = new ManuallyEnteredBackrefSource("").get(run, listener); assertThat(context, equalTo(EXPANDED)); diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/AnyBuildResultTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/AnyBuildResultTest.java index 8b904b06a..32437ffb5 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/AnyBuildResultTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/AnyBuildResultTest.java @@ -5,7 +5,7 @@ import org.junit.runner.RunWith; import org.kohsuke.github.GHCommitState; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.verifyNoMoreInteractions; diff --git a/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/BetterThanOrEqualBuildResultTest.java b/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/BetterThanOrEqualBuildResultTest.java index ff5c13f5d..086da733f 100644 --- a/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/BetterThanOrEqualBuildResultTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/status/sources/misc/BetterThanOrEqualBuildResultTest.java @@ -16,7 +16,7 @@ import static org.hamcrest.Matchers.is; import static org.jenkinsci.plugins.github.status.sources.misc.BetterThanOrEqualBuildResult.betterThanOrEqualTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author lanwen (Merkushev Kirill) diff --git a/src/test/java/org/jenkinsci/plugins/github/util/JobInfoHelpersTest.java b/src/test/java/org/jenkinsci/plugins/github/util/JobInfoHelpersTest.java index 04de9b1bb..5f6b08926 100644 --- a/src/test/java/org/jenkinsci/plugins/github/util/JobInfoHelpersTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/util/JobInfoHelpersTest.java @@ -14,7 +14,7 @@ import static org.jenkinsci.plugins.github.util.JobInfoHelpers.isBuildable; import static org.jenkinsci.plugins.github.util.JobInfoHelpers.triggerFrom; import static org.jenkinsci.plugins.github.util.JobInfoHelpers.withTrigger; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author lanwen (Merkushev Kirill) diff --git a/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventHeaderTest.java b/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventHeaderTest.java index d013196d6..954c4eeb6 100644 --- a/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventHeaderTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventHeaderTest.java @@ -5,7 +5,7 @@ import org.kohsuke.github.GHEvent; import org.kohsuke.stapler.StaplerRequest; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; diff --git a/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventPayloadTest.java b/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventPayloadTest.java index f0d0accfb..03a905c48 100644 --- a/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventPayloadTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/webhook/GHEventPayloadTest.java @@ -5,7 +5,7 @@ import org.junit.runner.RunWith; import org.kohsuke.stapler.StaplerRequest; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; diff --git a/src/test/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayloadTest.java b/src/test/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayloadTest.java index 0d9b787cb..872704c00 100644 --- a/src/test/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayloadTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayloadTest.java @@ -10,7 +10,7 @@ import org.kohsuke.stapler.StaplerRequest; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/jenkinsci/plugins/github/webhook/WebhookManagerTest.java b/src/test/java/org/jenkinsci/plugins/github/webhook/WebhookManagerTest.java index f6217fe1a..fcb3462f1 100644 --- a/src/test/java/org/jenkinsci/plugins/github/webhook/WebhookManagerTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/webhook/WebhookManagerTest.java @@ -20,9 +20,11 @@ import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHHook; import org.kohsuke.github.GHRepository; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.net.MalformedURLException; @@ -39,18 +41,18 @@ import static org.hamcrest.Matchers.nullValue; import static org.jenkinsci.plugins.github.test.HookSecretHelper.storeSecretIn; import static org.jenkinsci.plugins.github.webhook.WebhookManager.forHookUrl; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.kohsuke.github.GHEvent.CREATE; import static org.kohsuke.github.GHEvent.PULL_REQUEST; import static org.kohsuke.github.GHEvent.PUSH; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anySetOf; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anySet; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -82,6 +84,8 @@ public class WebhookManagerTest { @Mock private GHRepository repo; + @Captor + ArgumentCaptor> captor; @Test public void shouldDoNothingOnNoAdminRights() throws Exception { @@ -133,7 +137,7 @@ public void shouldMatchAdminAccessWhenFalse() throws Exception { @Test @WithoutJenkins public void shouldMatchWebHook() { - when(repo.hasAdminAccess()).thenReturn(false); + lenient().when(repo.hasAdminAccess()).thenReturn(false); GHHook hook = hook(HOOK_ENDPOINT, PUSH); @@ -143,7 +147,7 @@ public void shouldMatchWebHook() { @Test @WithoutJenkins public void shouldNotMatchOtherUrlWebHook() { - when(repo.hasAdminAccess()).thenReturn(false); + lenient().when(repo.hasAdminAccess()).thenReturn(false); GHHook hook = hook(ANOTHER_HOOK_ENDPOINT, PUSH); @@ -177,7 +181,7 @@ public void shouldNotReplaceAlreadyRegisteredHook() throws IOException { manager.createHookSubscribedTo(copyOf(newArrayList(PUSH))).apply(nonactive); verify(manager, never()).deleteWebhook(); - verify(manager, never()).createWebhook(any(URL.class), anySetOf(GHEvent.class)); + verify(manager, never()).createWebhook(any(URL.class), anySet()); } @Test @@ -191,7 +195,7 @@ public void shouldNotReplaceAlreadyRegisteredHookWithMoreEvents() throws IOExcep manager.createHookSubscribedTo(copyOf(newArrayList(PUSH))).apply(nonactive); verify(manager, never()).deleteWebhook(); - verify(manager, never()).createWebhook(any(URL.class), anySetOf(GHEvent.class)); + verify(manager, never()).createWebhook(any(URL.class), anySet()); } @@ -201,7 +205,7 @@ public void shouldNotAddPushEventByDefaultForProjectWithoutTrigger() throws IOEx project.setScm(GIT_SCM); manager.registerFor((Item)project).run(); - verify(manager, never()).createHookSubscribedTo(anyListOf(GHEvent.class)); + verify(manager, never()).createHookSubscribedTo(anyList()); } @Test @@ -255,10 +259,11 @@ public void shouldSendSecretIfDefined() throws Exception { verify(repo).createHook( anyString(), - (Map) argThat(hasEntry("secret", secretText)), - anySetOf(GHEvent.class), + captor.capture(), + anySet(), anyBoolean() ); + assertThat(captor.getValue(), hasEntry("secret", secretText)); } @@ -266,7 +271,7 @@ private GHHook hook(URL endpoint, GHEvent event, GHEvent... events) { GHHook hook = mock(GHHook.class); when(hook.getName()).thenReturn("web"); when(hook.getConfig()).thenReturn(ImmutableMap.of("url", endpoint.toExternalForm())); - when(hook.getEvents()).thenReturn(EnumSet.copyOf(asList(event, events))); + lenient().when(hook.getEvents()).thenReturn(EnumSet.copyOf(asList(event, events))); return hook; } diff --git a/src/test/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventListenerTest.java b/src/test/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventListenerTest.java index 78851d578..5e0566f84 100644 --- a/src/test/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventListenerTest.java +++ b/src/test/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventListenerTest.java @@ -17,7 +17,7 @@ import static com.cloudbees.jenkins.GitHubWebHookFullTest.classpath; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; From 7b8a3e6d12b2a202ca5ad332a5bbdc818525126f Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Thu, 4 Aug 2022 16:31:32 -0700 Subject: [PATCH 2/2] Fix Javadoc generation --- .../github/admin/GitHubHookRegisterProblemMonitor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitor.java b/src/main/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitor.java index 7505856f8..9872ca73c 100644 --- a/src/main/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitor.java +++ b/src/main/java/org/jenkinsci/plugins/github/admin/GitHubHookRegisterProblemMonitor.java @@ -32,7 +32,7 @@ /** * Administrative monitor to track problems of registering/removing hooks for GH. - * Holds non-savable map of repo->message and persisted list of ignored projects. + * Holds non-savable map of repo->message and persisted list of ignored projects. * Anyone can register new problem with {@link #registerProblem(GitHubRepositoryName, Throwable)} and check * repo for problems with {@link #isProblemWith(GitHubRepositoryName)} * @@ -64,7 +64,7 @@ public GitHubHookRegisterProblemMonitor() { } /** - * @return Immutable copy of map with repo->problem message content + * @return Immutable copy of map with repo->problem message content */ public Map getProblems() { return ImmutableMap.copyOf(problems);