diff --git a/pom.xml b/pom.xml
index b92f15d..01f039a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,18 +4,18 @@
org.jenkins-ci.plugins
plugin
- 3.19
+ 4.54
- 1.653
- 7
+ 2.379
+ 11
UTF-8
1.11
1.2
1.19
4.12
- 1.10.19
+ 4.11.0
1.7.4
2.6
5.4.1
@@ -54,6 +54,12 @@
junit
${jenkins.plugin.junit.version}
+
+
+ io.jenkins.plugins
+ commons-httpclient3-api
+ 3.1-3
+
org.jenkins-ci.plugins.workflow
@@ -69,7 +75,7 @@
org.mockito
- mockito-all
+ mockito-core
${mockito.version}
test
diff --git a/src/main/java/jenkins/plugins/zulip/DescriptorImpl.java b/src/main/java/jenkins/plugins/zulip/DescriptorImpl.java
index 0837be6..82ef497 100644
--- a/src/main/java/jenkins/plugins/zulip/DescriptorImpl.java
+++ b/src/main/java/jenkins/plugins/zulip/DescriptorImpl.java
@@ -45,7 +45,7 @@ public DescriptorImpl() {
} else {
XStream2 xstream = new XStream2();
xstream.alias("hudson.plugins.humbug.DescriptorImpl", DescriptorImpl.class);
- XmlFile oldConfig = new XmlFile(xstream, new File(Jenkins.getInstance().getRootDir(), OLD_CONFIG_FILE_NAME));
+ XmlFile oldConfig = new XmlFile(xstream, new File(Jenkins.getInstanceOrNull().getRootDir(), OLD_CONFIG_FILE_NAME));
if (oldConfig.exists()) {
try {
oldConfig.unmarshal(this);
@@ -146,7 +146,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
save();
// Cleanup the configuration file from previous plugin id - humbug
- File oldConfig = new File(Jenkins.getInstance().getRootDir(), OLD_CONFIG_FILE_NAME);
+ File oldConfig = new File(Jenkins.getInstanceOrNull().getRootDir(), OLD_CONFIG_FILE_NAME);
if (oldConfig.exists()) {
if (oldConfig.delete()) {
logger.log(Level.INFO, "Old humbug configuration file successfully cleaned up.");
diff --git a/src/main/java/jenkins/plugins/zulip/Zulip.java b/src/main/java/jenkins/plugins/zulip/Zulip.java
index 94b738a..ff65ece 100644
--- a/src/main/java/jenkins/plugins/zulip/Zulip.java
+++ b/src/main/java/jenkins/plugins/zulip/Zulip.java
@@ -50,7 +50,7 @@ public Zulip(String url, String email, Secret apiKey) {
*/
protected void configureProxy(HttpClient httpClient) throws MalformedURLException {
LOGGER.log(Level.FINE, "Setting up HttpClient proxy");
- ProxyConfiguration proxyConfiguration = Jenkins.getInstance().proxy;
+ ProxyConfiguration proxyConfiguration = Jenkins.getInstanceOrNull().proxy;
if (proxyConfiguration != null && ZulipUtil.isValueSet(proxyConfiguration.name)) {
URL urlObj = new URL(url);
Proxy proxy = proxyConfiguration.createProxy(urlObj.getHost());
diff --git a/src/main/java/jenkins/plugins/zulip/ZulipSendStep.java b/src/main/java/jenkins/plugins/zulip/ZulipSendStep.java
index 0ac8b1e..ea6a122 100644
--- a/src/main/java/jenkins/plugins/zulip/ZulipSendStep.java
+++ b/src/main/java/jenkins/plugins/zulip/ZulipSendStep.java
@@ -40,7 +40,7 @@ public ZulipSendStep() {
public void perform(@Nonnull Run, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener)
throws InterruptedException, IOException {
jenkins.plugins.zulip.DescriptorImpl globalConfig =
- Jenkins.getInstance().getDescriptorByType(jenkins.plugins.zulip.DescriptorImpl.class);
+ Jenkins.getInstanceOrNull().getDescriptorByType(jenkins.plugins.zulip.DescriptorImpl.class);
Zulip zulip = new Zulip(globalConfig.getUrl(), globalConfig.getEmail(), globalConfig.getApiKey());
String stream = ZulipUtil.expandVariables(run, listener, ZulipUtil.getDefaultValue(getStream(), globalConfig.getStream()));
String defaultTopic = displayItem(run.getParent(), globalConfig, globalConfig.isFullJobPathAsDefaultTopic(), false);
diff --git a/src/main/java/jenkins/plugins/zulip/ZulipUtil.java b/src/main/java/jenkins/plugins/zulip/ZulipUtil.java
index 756c63a..ed822aa 100644
--- a/src/main/java/jenkins/plugins/zulip/ZulipUtil.java
+++ b/src/main/java/jenkins/plugins/zulip/ZulipUtil.java
@@ -51,7 +51,7 @@ public static String getDefaultValue(String value, String defaultValue) {
* @return The Jenkins instance Url
*/
public static String getJenkinsUrl(DescriptorImpl globalConfig) {
- String jenkinsUrl = getDefaultValue(globalConfig.getJenkinsUrl(), Jenkins.getInstance().getRootUrl());
+ String jenkinsUrl = getDefaultValue(globalConfig.getJenkinsUrl(), Jenkins.getInstanceOrNull().getRootUrl());
if (jenkinsUrl != null && jenkinsUrl.length() > 0 && !jenkinsUrl.endsWith("/")) {
jenkinsUrl = jenkinsUrl + "/";
}
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipNotifierFullJobPathTest.java b/src/test/java/jenkins/plugins/zulip/ZulipNotifierFullJobPathTest.java
index 136e713..0984ca7 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipNotifierFullJobPathTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipNotifierFullJobPathTest.java
@@ -1,25 +1,14 @@
package jenkins.plugins.zulip;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import hudson.EnvVars;
-import hudson.model.AbstractBuild;
-import hudson.model.BuildListener;
-import hudson.model.ItemGroup;
-import hudson.model.Job;
-import hudson.model.Result;
-import hudson.model.Run;
-import hudson.model.User;
+import hudson.Launcher;
+import hudson.model.*;
import hudson.scm.ChangeLogSet;
-import hudson.tasks.test.AbstractTestResultAction;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.jvnet.hudson.test.FakeChangeLogSCM;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
@@ -30,16 +19,13 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import java.util.Arrays;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.verifyNew;
import static org.powermock.api.mockito.PowerMockito.when;
@@ -91,10 +77,10 @@ public class ZulipNotifierFullJobPathTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
- when(Jenkins.getInstance()).thenReturn(jenkins);
+ when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
when(jenkins.getDisplayName()).thenReturn("Jenkins");
PowerMockito.mockStatic(User.class);
- when(User.get(anyString())).thenAnswer(new Answer() {
+ when(User.getOrCreateByIdOrFullName(anyString())).thenAnswer(new Answer() {
@Override
public User answer(InvocationOnMock invocation) throws Throwable {
String arg = (String) invocation.getArguments()[0];
@@ -121,7 +107,7 @@ public User answer(InvocationOnMock invocation) throws Throwable {
when(job.getParent()).thenReturn(folder);
when(folder.getDisplayName()).thenReturn("Folder");
when(folder.getUrl()).thenReturn("job/Folder");
- when(folder.getParent()).thenReturn((ItemGroup)jenkins);
+ when(folder.getParent()).thenReturn((ItemGroup) jenkins);
when(build.getEnvironment(buildListener)).thenReturn(envVars);
when(envVars.expand(anyString())).thenAnswer(new Answer() {
@Override
@@ -136,7 +122,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
@Test
public void testShouldUseDefaults() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verifyNew(Zulip.class).withArguments(eq("zulipUrl"), eq("jenkins-bot@zulip.com"), any(Secret.class));
verify(envVars, times(2)).expand(expandCaptor.capture());
assertThat("Should expand stream, topic and message", expandCaptor.getAllValues(),
@@ -149,7 +135,7 @@ public void testShouldUseDefaults() throws Exception {
reset(zulip);
notifier.setStream("");
notifier.setTopic("");
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use default stream", "defaultStream", streamCaptor.getValue());
assertEquals("Should use default topic", "defaultTopic", topicCaptor.getValue());
@@ -160,7 +146,7 @@ public void testShouldUseProjectConfig() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.setStream("projectStream");
notifier.setTopic("projectTopic");
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use project stream", "projectStream", streamCaptor.getValue());
assertEquals("Should use topic stream", "projectTopic", topicCaptor.getValue());
@@ -172,7 +158,7 @@ public void testShouldUseFullJobPathAsTopic() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getTopic()).thenReturn("");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Topic should be project's full job path", "Folder » TestJob", topicCaptor.getValue());
assertEquals("Message should not contain project name", "**Build: **#1: **SUCCESS** :check_mark:", messageCaptor.getValue());
@@ -189,7 +175,7 @@ public void testJenkinsUrl() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getJenkinsUrl()).thenReturn("JenkinsUrl");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain links to Jenkins",
"**Project: **[Folder](JenkinsUrl/job/Folder) » [TestJob](JenkinsUrl/job/Folder/TestJob) : **Build: **[#1](JenkinsUrl/job/Folder/TestJob/1): **SUCCESS** :check_mark:",
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipNotifierTest.java b/src/test/java/jenkins/plugins/zulip/ZulipNotifierTest.java
index e0b4993..75675e3 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipNotifierTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipNotifierTest.java
@@ -5,6 +5,7 @@
import java.util.List;
import hudson.EnvVars;
+import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Job;
@@ -32,10 +33,10 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -93,9 +94,9 @@ public class ZulipNotifierTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
- when(Jenkins.getInstance()).thenReturn(jenkins);
+ when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
PowerMockito.mockStatic(User.class);
- when(User.get(anyString())).thenAnswer(new Answer() {
+ when(User.getOrCreateByIdOrFullName(anyString())).thenAnswer(new Answer() {
@Override
public User answer(InvocationOnMock invocation) throws Throwable {
String arg = (String) invocation.getArguments()[0];
@@ -131,7 +132,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
@Test
public void testShouldUseDefaults() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verifyNew(Zulip.class).withArguments(eq("zulipUrl"), eq("jenkins-bot@zulip.com"), any(Secret.class));
verify(envVars, times(2)).expand(expandCaptor.capture());
assertThat("Should expand stream, topic and message", expandCaptor.getAllValues(),
@@ -144,7 +145,7 @@ public void testShouldUseDefaults() throws Exception {
reset(zulip);
notifier.setStream("");
notifier.setTopic("");
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use default stream", "defaultStream", streamCaptor.getValue());
assertEquals("Should use default topic", "defaultTopic", topicCaptor.getValue());
@@ -154,7 +155,7 @@ public void testShouldUseDefaults() throws Exception {
public void testFailedBuild() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(build.getResult()).thenReturn(Result.FAILURE);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should be failed build", "**Project: **TestJob : **Build: **#1: **FAILURE** :cross_mark:", messageCaptor.getValue());
}
@@ -164,7 +165,7 @@ public void testUnstableBuild() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(build.getResult()).thenReturn(Result.UNSTABLE);
when(build.getAction(AbstractTestResultAction.class)).thenReturn(new FakeTestResultAction());
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should be unstable build", "**Project: **TestJob : **Build: **#1: **UNSTABLE** :warning: (50 broken tests)",
messageCaptor.getValue());
@@ -175,7 +176,7 @@ public void testShouldUseProjectConfig() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
notifier.setStream("projectStream");
notifier.setTopic("projectTopic");
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Should use project stream", "projectStream", streamCaptor.getValue());
assertEquals("Should use topic stream", "projectTopic", topicCaptor.getValue());
@@ -187,7 +188,7 @@ public void testShouldUseProjectNameAsTopic() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getTopic()).thenReturn("");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Topic should be project display name", "TestJob", topicCaptor.getValue());
assertEquals("Message should not contain project name", "**Build: **#1: **SUCCESS** :check_mark:", messageCaptor.getValue());
@@ -206,7 +207,7 @@ public void testChangeLogSet() throws Exception {
FakeChangeLogSCM.FakeChangeLogSet changeLogSet = new FakeChangeLogSCM.FakeChangeLogSet(build, changes);
when(build.getChangeSet()).thenReturn(changeLogSet);
ZulipNotifier notifier = new ZulipNotifier();
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain change log", "**Project: **TestJob : **Build: **#1: **SUCCESS** :check_mark:\n" +
"\n" +
@@ -222,7 +223,7 @@ public void testJenkinsUrl() throws Exception {
ZulipNotifier notifier = new ZulipNotifier();
when(descMock.getJenkinsUrl()).thenReturn("JenkinsUrl");
Whitebox.setInternalState(ZulipNotifier.class, descMock);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip).sendStreamMessage(streamCaptor.capture(), topicCaptor.capture(), messageCaptor.capture());
assertEquals("Message should contain links to Jenkins",
"**Project: **[TestJob](JenkinsUrl/job/TestJob) : **Build: **[#1](JenkinsUrl/job/TestJob/1): **SUCCESS** :check_mark:",
@@ -243,27 +244,27 @@ public void testSmartNotify() throws Exception {
reset(zulip);
when(build.getPreviousBuild()).thenReturn(null);
when(build.getResult()).thenReturn(Result.SUCCESS);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(2)).sendStreamMessage(anyString(), anyString(), anyString());
// If the previous build was a failure, notification should be sent no matter what
reset(zulip);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(previousBuild.getResult()).thenReturn(Result.FAILURE);
when(build.getResult()).thenReturn(Result.SUCCESS);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(2)).sendStreamMessage(anyString(), anyString(), anyString());
// If the previous build was a success, notification should be sent only for failed builds
reset(zulip);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(previousBuild.getResult()).thenReturn(Result.SUCCESS);
when(build.getResult()).thenReturn(Result.SUCCESS);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
when(build.getResult()).thenReturn(Result.FAILURE);
- notifier.perform(build, null, buildListener);
+ notifier.perform(build, (Launcher) null, buildListener);
verify(zulip, times(1)).sendStreamMessage(anyString(), anyString(), anyString());
} finally {
// Be sure to return global setting back to original setup so other tests dont fail
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipSendStepFullJobPathTest.java b/src/test/java/jenkins/plugins/zulip/ZulipSendStepFullJobPathTest.java
index a2d9872..5019a99 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipSendStepFullJobPathTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipSendStepFullJobPathTest.java
@@ -25,9 +25,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -81,7 +81,7 @@ public class ZulipSendStepFullJobPathTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
- when(Jenkins.getInstance()).thenReturn(jenkins);
+ when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
when(jenkins.getDescriptorByType(DescriptorImpl.class)).thenReturn(descMock);
when(jenkins.getDisplayName()).thenReturn("Jenkins");
when(descMock.getUrl()).thenReturn("zulipUrl");
@@ -95,7 +95,7 @@ public void setUp() throws Exception {
when(job.getParent()).thenReturn(folder);
when(folder.getDisplayName()).thenReturn("Folder");
when(folder.getUrl()).thenReturn("job/Folder");
- when(folder.getParent()).thenReturn((ItemGroup)jenkins);
+ when(folder.getParent()).thenReturn((ItemGroup) jenkins);
when(run.getEnvironment(taskListener)).thenReturn(envVars);
when(envVars.expand(anyString())).thenAnswer(new Answer() {
@Override
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipSendStepTest.java b/src/test/java/jenkins/plugins/zulip/ZulipSendStepTest.java
index d918ce4..e276ed5 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipSendStepTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipSendStepTest.java
@@ -24,9 +24,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -77,7 +77,7 @@ public class ZulipSendStepTest {
public void setUp() throws Exception {
PowerMockito.whenNew(Zulip.class).withAnyArguments().thenReturn(zulip);
PowerMockito.mockStatic(Jenkins.class);
- when(Jenkins.getInstance()).thenReturn(jenkins);
+ when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
when(jenkins.getDescriptorByType(DescriptorImpl.class)).thenReturn(descMock);
when(descMock.getUrl()).thenReturn("zulipUrl");
when(descMock.getEmail()).thenReturn("jenkins-bot@zulip.com");
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipTest.java b/src/test/java/jenkins/plugins/zulip/ZulipTest.java
index e18728c..e554edd 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipTest.java
@@ -19,7 +19,7 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.StringBody.exact;
@@ -50,7 +50,7 @@ public static void stopMockServer() {
@Before
public void setUp() {
PowerMockito.mockStatic(Jenkins.class);
- when(Jenkins.getInstance()).thenReturn(jenkins);
+ when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
PowerMockito.mockStatic(Secret.class);
when(Secret.toString(any(Secret.class))).thenReturn("secret");
}
diff --git a/src/test/java/jenkins/plugins/zulip/ZulipUtilTest.java b/src/test/java/jenkins/plugins/zulip/ZulipUtilTest.java
index 5cc1e83..fa5332b 100644
--- a/src/test/java/jenkins/plugins/zulip/ZulipUtilTest.java
+++ b/src/test/java/jenkins/plugins/zulip/ZulipUtilTest.java
@@ -39,7 +39,7 @@ public class ZulipUtilTest {
public void setUp() {
// Mock Jenkins Instance
PowerMockito.mockStatic(Jenkins.class);
- PowerMockito.when(Jenkins.getInstance()).thenReturn(jenkins);
+ PowerMockito.when(Jenkins.getInstanceOrNull()).thenReturn(jenkins);
PowerMockito.when(jenkins.getRootUrl()).thenReturn("http://JenkinsConfigUrl");
}