diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 2648306ed..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,62 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -name: "CodeQL" - -on: - push: - branches: [master] - pull_request: - # The branches below must be a subset of the branches above - branches: [master] - schedule: - - cron: '0 9 * * 0' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['java'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v4.2.2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 diff --git a/Jenkinsfile b/Jenkinsfile index 359793b27..ca2f7231c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,5 +7,4 @@ buildPlugin( [platform: 'linux', jdk: 21], [platform: 'windows', jdk: 21], [platform: 'linux', jdk: 17], - [platform: 'linux', jdk: 11], ]) diff --git a/pom.xml b/pom.xml index 0963d8d71..9f23e361d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 4.88 + 5.3 @@ -20,7 +20,7 @@ 999999-SNAPSHOT jenkinsci/prometheus-plugin - 2.387.3 + 2.479 0.16.0 2.0.16 diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java b/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java index c7222f2f8..7e2adb7d6 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java @@ -17,7 +17,13 @@ import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.Files; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummary.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummary.java index 18f1679e6..f4c44caf2 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummary.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummary.java @@ -13,7 +13,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.List; import static org.jenkinsci.plugins.prometheus.util.FlowNodes.getSortedStageNodes; diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java index c26a5c7cd..d247c4428 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskCollectorFactory.java @@ -11,7 +11,9 @@ import java.nio.file.FileStore; import java.util.Objects; -import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.*; +import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.DISK_USAGE_BYTES_GAUGE; +import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.DISK_USAGE_FILE_COUNT_GAUGE; +import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.JOB_USAGE_BYTES_GAUGE; public class DiskCollectorFactory extends BaseCollectorFactory { diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java b/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java index f00f46131..6303d4925 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java @@ -1,5 +1,6 @@ package org.jenkinsci.plugins.prometheus.config; +import edu.umd.cs.findbugs.annotations.CheckForNull; import hudson.Extension; import hudson.util.FormValidation; import jenkins.YesNoMaybe; @@ -10,11 +11,10 @@ import org.jenkinsci.plugins.prometheus.config.disabledmetrics.DisabledMetricConfig; import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import edu.umd.cs.findbugs.annotations.CheckForNull; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -80,7 +80,7 @@ public static PrometheusConfiguration get() { } @Override - public boolean configure(StaplerRequest req, JSONObject json) { + public boolean configure(StaplerRequest2 req, JSONObject json) { disabledMetricConfig = null; req.bindJSON(this, json); save(); diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/rest/PrometheusAction.java b/src/main/java/org/jenkinsci/plugins/prometheus/rest/PrometheusAction.java index a0ea00bda..f44ece243 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/rest/PrometheusAction.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/rest/PrometheusAction.java @@ -10,8 +10,10 @@ import org.jenkinsci.plugins.prometheus.service.DefaultPrometheusMetrics; import org.jenkinsci.plugins.prometheus.service.PrometheusMetrics; import org.kohsuke.stapler.HttpResponse; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; + +import java.io.IOException; @Extension public class PrometheusAction implements UnprotectedRootAction { @@ -33,7 +35,7 @@ public String getUrlName() { return PrometheusConfiguration.get().getUrlName(); } - public HttpResponse doDynamic(StaplerRequest request) { + public HttpResponse doDynamic(StaplerRequest2 request) { if (request.getRestOfPath().equals(PrometheusConfiguration.get().getAdditionalPath())) { if (hasAccess()) { return prometheusResponse(); @@ -50,12 +52,16 @@ private boolean hasAccess() { return true; } + private HttpResponse prometheusResponse() { - return (request, response, node) -> { - response.setStatus(StaplerResponse.SC_OK); - response.setContentType(TextFormat.CONTENT_TYPE_004); - response.addHeader("Cache-Control", "must-revalidate,no-cache,no-store"); - response.getWriter().write(prometheusMetrics.getMetrics()); + return new HttpResponse() { + @Override + public void generateResponse(StaplerRequest2 request, StaplerResponse2 response, Object node) throws IOException { + response.setStatus(StaplerResponse2.SC_OK); + response.setContentType(TextFormat.CONTENT_TYPE_004); + response.addHeader("Cache-Control", "must-revalidate,no-cache,no-store"); + response.getWriter().write(prometheusMetrics.getMetrics()); + } }; } } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/CodeCoverageCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/CodeCoverageCollectorTest.java index 041d7fed9..70780649c 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/CodeCoverageCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/CodeCoverageCollectorTest.java @@ -17,7 +17,9 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java index 6a55fc521..c3eb4f30f 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java @@ -30,9 +30,16 @@ import static java.util.Objects.requireNonNull; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; @ExtendWith(MockitoExtension.class) public class DiskUsageCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java index 949f05fb3..0205fad41 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java @@ -11,7 +11,9 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) public class JenkinsStatusCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java index 34546149a..8d727fc90 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java @@ -9,7 +9,9 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; public class TestBasedMetricCollectorTest extends MockedRunCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java index fbef6d78c..1fc2a9c57 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLikelyStuckGaugeTest.java @@ -5,7 +5,6 @@ import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLogFileSizeGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLogFileSizeGaugeTest.java index a60627836..2ae5a0c2e 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLogFileSizeGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildLogFileSizeGaugeTest.java @@ -3,7 +3,6 @@ import hudson.console.AnnotatedLargeText; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; @@ -11,7 +10,7 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java index 669a07d56..04c2a191d 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/CounterManagerTest.java @@ -9,7 +9,9 @@ import java.util.Arrays; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; public class CounterManagerTest extends MockedRunCollectorTest { private final CounterManager manager; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/FailedTestsGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/FailedTestsGaugeTest.java index 28468141e..4d80f46ad 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/FailedTestsGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/FailedTestsGaugeTest.java @@ -10,7 +10,9 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @SuppressWarnings("rawtypes") public class FailedTestsGaugeTest extends MockedRunCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/SkippedTestsGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/SkippedTestsGaugeTest.java index 0fa2f592e..26478a5d8 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/SkippedTestsGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/SkippedTestsGaugeTest.java @@ -10,7 +10,9 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @SuppressWarnings("rawtypes") public class SkippedTestsGaugeTest extends MockedRunCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/TotalTestsGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/TotalTestsGaugeTest.java index 50531059b..38769f079 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/TotalTestsGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/TotalTestsGaugeTest.java @@ -10,7 +10,9 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @SuppressWarnings("rawtypes") public class TotalTestsGaugeTest extends MockedRunCollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskUsageBytesGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskUsageBytesGaugeTest.java index b2362433d..fe2b8b08e 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskUsageBytesGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/DiskUsageBytesGaugeTest.java @@ -10,7 +10,6 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/JobUsageBytesGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/JobUsageBytesGaugeTest.java index 08b994e43..1dd39839a 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/JobUsageBytesGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/disk/JobUsageBytesGaugeTest.java @@ -1,6 +1,5 @@ package org.jenkinsci.plugins.prometheus.collectors.disk; -import com.cloudbees.simplediskusage.DiskItem; import com.cloudbees.simplediskusage.JobDiskItem; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.CollectorTest; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java index aa5048050..931bbf2f0 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java @@ -6,15 +6,19 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.mockito.Mockito; import java.util.Arrays; import java.util.List; import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; @SuppressWarnings("rawtypes") public class PrometheusConfigurationTest { @@ -34,7 +38,7 @@ private static List wrongMetricCollectorPeriodsProvider() { @MethodSource("wrongMetricCollectorPeriodsProvider") public void shouldGetErrorWhenNotPositiveNumber(String metricCollectorPeriod) throws Descriptor.FormException { //given - Mockito.when(configuration.configure(any(), any())).thenCallRealMethod(); + Mockito.when(configuration.configure(any(StaplerRequest2.class), any())).thenCallRealMethod(); Mockito.when(configuration.doCheckCollectingMetricsPeriodInSeconds(any())).thenCallRealMethod(); JSONObject config = getDefaultConfig(); config.accumulate("collectingMetricsPeriodInSeconds", metricCollectorPeriod); @@ -55,9 +59,10 @@ private static List correctMetricCollectorPeriodsProvider() { @MethodSource("correctMetricCollectorPeriodsProvider") public void shouldReturnOk(String metricCollectorPeriod) throws Descriptor.FormException { //given - Mockito.when(configuration.configure(any(), any())).thenCallRealMethod(); + Mockito.when(configuration.configure(any(StaplerRequest2.class), any())).thenCallRealMethod(); + Mockito.when(configuration.doCheckCollectingMetricsPeriodInSeconds(any())).thenCallRealMethod(); JSONObject config = getDefaultConfig(); - StaplerRequest request = Mockito.mock(StaplerRequest.class); + StaplerRequest2 request = Mockito.mock(StaplerRequest2.class); Mockito.doNothing().when(request).bindJSON(any(Object.class), any(JSONObject.class)); config.accumulate("collectingMetricsPeriodInSeconds", metricCollectorPeriod); diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/MetricStatusCheckerTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/MetricStatusCheckerTest.java index bc10896bb..23e144838 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/MetricStatusCheckerTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/MetricStatusCheckerTest.java @@ -11,7 +11,9 @@ import java.util.List; import java.util.Set; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; public class MetricStatusCheckerTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java index c50ce75e9..bea1c15d6 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java @@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.kohsuke.stapler.HttpResponse; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; @@ -55,10 +55,10 @@ public void tearDown() { } @Test - public void shouldThrowExceptionWhenDoesNotMatchPath() throws IOException, ServletException { + public void shouldThrowExceptionWhenDoesNotMatchPath() throws IOException, ServletException, jakarta.servlet.ServletException { // given PrometheusAction action = new PrometheusAction(); - StaplerRequest request = mock(StaplerRequest.class); + StaplerRequest2 request = mock(StaplerRequest2.class); String url = ""; when(request.getRestOfPath()).thenReturn(url); @@ -72,10 +72,10 @@ public void shouldThrowExceptionWhenDoesNotMatchPath() throws IOException, Servl } @Test - public void shouldThrowExceptionWhenAuthenticationEnabledAndInsufficientPermission() throws IOException, ServletException { + public void shouldThrowExceptionWhenAuthenticationEnabledAndInsufficientPermission() throws IOException, ServletException, jakarta.servlet.ServletException { // given PrometheusAction action = new PrometheusAction(); - StaplerRequest request = mock(StaplerRequest.class); + StaplerRequest2 request = mock(StaplerRequest2.class); String url = "prometheus"; when(request.getRestOfPath()).thenReturn(url); when(configuration.isUseAuthenticatedEndpoint()).thenReturn(true); @@ -91,7 +91,7 @@ public void shouldThrowExceptionWhenAuthenticationEnabledAndInsufficientPermissi } @Test - public void shouldReturnMetrics() throws IOException, ServletException { + public void shouldReturnMetrics() throws IOException, jakarta.servlet.ServletException { // given DefaultPrometheusMetrics prometheusMetrics = mock(DefaultPrometheusMetrics.class); String responseBody = "testMetric"; @@ -99,7 +99,7 @@ public void shouldReturnMetrics() throws IOException, ServletException { try (MockedStatic defaultPrometheusMetricsMockedStatic = mockStatic(DefaultPrometheusMetrics.class)) { defaultPrometheusMetricsMockedStatic.when(DefaultPrometheusMetrics::get).thenReturn(prometheusMetrics); PrometheusAction action = new PrometheusAction(); - StaplerRequest request = mock(StaplerRequest.class); + StaplerRequest2 request = mock(StaplerRequest2.class); String url = "prometheus"; when(request.getRestOfPath()).thenReturn(url); @@ -117,14 +117,14 @@ public void shouldReturnMetrics() throws IOException, ServletException { } private static class AssertStaplerResponse { - private final StaplerResponse response; + private final StaplerResponse2 response; private final HttpResponse httpResponse; private final StringWriter stringWriter; private AssertStaplerResponse(HttpResponse httpResponse) throws IOException { this.httpResponse = httpResponse; - this.response = mock(StaplerResponse.class); + this.response = mock(StaplerResponse2.class); stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); @@ -155,7 +155,7 @@ private AssertStaplerResponse assertBody(String payload) { return this; } - private AssertStaplerResponse call() throws IOException, ServletException { + private AssertStaplerResponse call() throws IOException, jakarta.servlet.ServletException { httpResponse.generateResponse(null, response, null); return this; } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java index 009d56896..5a37121fa 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java @@ -8,7 +8,9 @@ import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; public class ConfigurationUtilsTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java index 57266914c..1a025d9b8 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java @@ -9,7 +9,9 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @SuppressWarnings("rawtypes") public class JobsTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/RunsTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/RunsTest.java index 481a4b830..aedb09936 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/RunsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/RunsTest.java @@ -18,8 +18,12 @@ import java.util.Map; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) public class RunsTest {