From c48d725ae7f59a8b23f66602016324f954062c39 Mon Sep 17 00:00:00 2001 From: Waschndolos Date: Tue, 21 Nov 2023 20:34:49 +0100 Subject: [PATCH] Update Tests to Junit5 Framework and removed some unnecessary test dependencies (#589) --- pom.xml | 18 +---- .../prometheus/DiskUsageCollectorTest.java | 15 ++-- .../JenkinsStatusCollectorTest.java | 13 ++-- .../TestBasedMetricCollectorTest.java | 2 +- .../builds/BuildDurationGaugeTest.java | 2 +- .../BuildDurationSummaryTestJobTest.java | 9 +-- .../builds/BuildFailedCounterTest.java | 3 +- .../builds/BuildResultGaugeTest.java | 2 +- .../builds/BuildResultOrdinalGaugeTest.java | 2 +- .../builds/BuildStartGaugeTest.java | 2 +- .../builds/BuildSuccessfulCounterTest.java | 3 +- .../builds/FailedTestsGaugeTest.java | 8 +- .../builds/SkippedTestsGaugeTest.java | 8 +- .../collectors/builds/StageSummaryTest.java | 7 +- .../builds/TotalTestsGaugeTest.java | 8 +- .../CoverageBranchCoveredGaugeTest.java | 2 +- .../CoverageBranchMissedGaugeTest.java | 2 +- .../CoverageBranchTotalGaugeTest.java | 2 +- .../CoverageClassCoveredGaugeTest.java | 2 +- .../CoverageClassMissedGaugeTest.java | 2 +- .../coverage/CoverageClassTotalGaugeTest.java | 2 +- .../CoverageFileCoveredGaugeTest.java | 2 +- .../coverage/CoverageFileMissedGaugeTest.java | 2 +- .../coverage/CoverageFileTotalGaugeTest.java | 2 +- .../CoverageInstructionCoveredGaugeTest.java | 2 +- .../CoverageInstructionMissedGaugeTest.java | 2 +- .../CoverageInstructionTotalGaugeTest.java | 2 +- .../ExecutorsAvailableGaugeTest.java | 2 +- .../executors/ExecutorsBusyGaugeTest.java | 2 +- .../ExecutorsConnectingGaugeTest.java | 2 +- .../executors/ExecutorsDefinedGaugeTest.java | 2 +- .../executors/ExecutorsIdleGaugeTest.java | 2 +- .../executors/ExecutorsOnlineGaugeTest.java | 2 +- .../ExecutorsQueueLengthGaugeTest.java | 2 +- .../jenkins/JenkinsUpGaugeTest.java | 2 +- .../jenkins/JenkinsUptimeGaugeTest.java | 2 +- .../jenkins/JenkinsVersionInfoTest.java | 8 +- .../jenkins/NodesOnlineGaugeTest.java | 10 +-- .../jobs/BuildDiscardGaugeTest.java | 7 +- .../jobs/CurrentRunDurationGaugeTest.java | 5 +- .../collectors/jobs/HealthScoreGaugeTest.java | 4 +- .../collectors/jobs/JobCollectorTest.java | 10 +-- .../collectors/jobs/NbBuildsGaugeTest.java | 2 +- .../testutils/MockedJenkinsTest.java | 6 +- .../MockedLoadStatisticSnapshotTest.java | 6 +- .../testutils/MockedRunCollectorTest.java | 8 +- .../config/PrometheusConfigurationTest.java | 77 +++++++++---------- .../NamedDisabledMetricTest.java | 2 - .../RegexDisabledMetricTest.java | 2 - .../prometheus/rest/PrometheusActionTest.java | 26 ++++--- .../service/PrometheusAsyncWorkerTest.java | 8 +- .../prometheus/util/ArrayUtilsTest.java | 2 +- .../util/ConfigurationUtilsTest.java | 23 +++--- .../JenkinsNodeBuildsSampleBuilderTest.java | 30 ++++---- .../plugins/prometheus/util/JobsTest.java | 9 +-- 55 files changed, 179 insertions(+), 210 deletions(-) diff --git a/pom.xml b/pom.xml index 5864bafc9..b9b03401d 100644 --- a/pom.xml +++ b/pom.xml @@ -130,6 +130,7 @@ org.jenkins-ci.plugins junit + compile org.jenkins-ci.plugins @@ -140,20 +141,15 @@ pipeline-rest-api - - - org.mockito mockito-core test - - - org.assertj - assertj-core - ${assertj-core.version} + org.mockito + mockito-junit-jupiter + 5.3.1 test @@ -168,11 +164,5 @@ ${system-lambda.version} test - - com.google.inject.extensions - guice-testlib - 7.0.0 - test - diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java index cb1b583a2..83bf53efa 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/DiskUsageCollectorTest.java @@ -13,12 +13,11 @@ import org.hamcrest.TypeSafeDiagnosingMatcher; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; import org.jenkinsci.plugins.prometheus.util.ConfigurationUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; import java.nio.file.FileStore; @@ -35,7 +34,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DiskUsageCollectorTest { @Mock @@ -114,7 +113,7 @@ public void shouldProduceMetrics() throws IOException { } } - private static final void mockFileStore(DiskItem item, FileStore store) throws IOException { + private static void mockFileStore(DiskItem item, FileStore store) throws IOException { final Path path = item.getPath().toPath().toRealPath(); when(path.getFileSystem().provider().getFileStore(path)).thenReturn(store); } @@ -123,7 +122,7 @@ private static Matcher gauges(String name, Matcher(MetricFamilySamples.class) { + return new TypeSafeDiagnosingMatcher<>(MetricFamilySamples.class) { @Override public void describeTo(Description description) { description.appendText("gauges named ") @@ -158,7 +157,7 @@ protected boolean matchesSafely(MetricFamilySamples item, Description mismatchDe private static Matcher sample(Map labels, Matcher value) { requireNonNull(labels); - return new TypeSafeDiagnosingMatcher(MetricFamilySamples.Sample.class) { + return new TypeSafeDiagnosingMatcher<>(MetricFamilySamples.Sample.class) { @Override public void describeTo(Description description) { description.appendText("sample labeled ") diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java index 47cd1cf8e..6a5698033 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/JenkinsStatusCollectorTest.java @@ -1,22 +1,19 @@ package org.jenkinsci.plugins.prometheus; -import hudson.model.Computer; -import hudson.model.Node; import io.prometheus.client.Collector.MetricFamilySamples; import jenkins.model.Jenkins; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JenkinsStatusCollectorTest { @Test 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 56a8eac78..34546149a 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/TestBasedMetricCollectorTest.java @@ -5,8 +5,8 @@ import io.prometheus.client.SimpleCollector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationGaugeTest.java index 8b8e6ac18..ae154b5ca 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationGaugeTest.java @@ -2,8 +2,8 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; 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/BuildDurationSummaryTestJobTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationSummaryTestJobTest.java index 199f64595..727338434 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationSummaryTestJobTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildDurationSummaryTestJobTest.java @@ -1,18 +1,17 @@ package org.jenkinsci.plugins.prometheus.collectors.builds; import io.prometheus.client.Collector; -import org.jenkinsci.plugins.prometheus.collectors.builds.BuildDurationSummary; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; import org.junit.jupiter.api.Assertions; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BuildDurationSummaryTestJobTest extends MockedRunCollectorTest { @Test diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildFailedCounterTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildFailedCounterTest.java index 95eb90ac8..653d0d5f3 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildFailedCounterTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildFailedCounterTest.java @@ -2,10 +2,9 @@ import hudson.model.Result; import io.prometheus.client.Collector; -import org.jenkinsci.plugins.prometheus.collectors.builds.BuildFailedCounter; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultGaugeTest.java index 848c8cc33..d884cdf53 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultGaugeTest.java @@ -3,8 +3,8 @@ import hudson.model.Result; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; 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/BuildResultOrdinalGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultOrdinalGaugeTest.java index d0ca21635..4e1ad4fd6 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultOrdinalGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultOrdinalGaugeTest.java @@ -3,8 +3,8 @@ import hudson.model.Result; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; 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/BuildStartGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildStartGaugeTest.java index fc17cf1db..791c55e6f 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildStartGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildStartGaugeTest.java @@ -2,8 +2,8 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; 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/BuildSuccessfulCounterTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildSuccessfulCounterTest.java index fc2f29093..797313b1b 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildSuccessfulCounterTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildSuccessfulCounterTest.java @@ -2,10 +2,9 @@ import hudson.model.Result; import io.prometheus.client.Collector; -import org.jenkinsci.plugins.prometheus.collectors.builds.BuildSuccessfulCounter; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; 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 1229ce49f..28468141e 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 @@ -4,15 +4,15 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +@SuppressWarnings("rawtypes") public class FailedTestsGaugeTest extends MockedRunCollectorTest { @Test @@ -50,7 +50,7 @@ public void testCollectFails() { assertEquals(1, collect.size()); assertEquals(100.0, collect.get(0).samples.get(0).value, 0.0); - Assertions.assertEquals("default_jenkins_builds_build_tests_failing", collect.get(0).samples.get(0).name); + assertEquals("default_jenkins_builds_build_tests_failing", collect.get(0).samples.get(0).name); } } } \ No newline at end of file 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 e4e85c203..0fa2f592e 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 @@ -4,15 +4,15 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +@SuppressWarnings("rawtypes") public class SkippedTestsGaugeTest extends MockedRunCollectorTest { @Test @@ -50,7 +50,7 @@ public void testCollectSkipped() { assertEquals(1, collect.size()); assertEquals(100.0, collect.get(0).samples.get(0).value, 0.0); - Assertions.assertEquals("default_jenkins_builds_last_build_tests_skipped", collect.get(0).samples.get(0).name); + assertEquals("default_jenkins_builds_last_build_tests_skipped", collect.get(0).samples.get(0).name); } } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummaryTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummaryTest.java index 38c172448..553ac311f 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummaryTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/builds/StageSummaryTest.java @@ -2,10 +2,8 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; -import org.jenkinsci.plugins.workflow.job.WorkflowRun; -import org.junit.Test; import org.junit.jupiter.api.Assertions; -import org.mockito.Mock; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.List; @@ -13,9 +11,6 @@ public class StageSummaryTest extends MockedRunCollectorTest { - @Mock - WorkflowRun mockedWorkflowRun; - @Test public void testNothingCalculatedWhenJobIsBuilding() { Mockito.when(mock.isBuilding()).thenReturn(true); 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 af4e7524c..50531059b 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 @@ -4,15 +4,15 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +@SuppressWarnings("rawtypes") public class TotalTestsGaugeTest extends MockedRunCollectorTest { @Test @@ -50,7 +50,7 @@ public void testCollectTotal() { assertEquals(1, collect.size()); assertEquals(100.0, collect.get(0).samples.get(0).value, 0.0); - Assertions.assertEquals("default_jenkins_builds_build_tests_total", collect.get(0).samples.get(0).name); + assertEquals("default_jenkins_builds_build_tests_total", collect.get(0).samples.get(0).name); } } } \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchCoveredGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchCoveredGaugeTest.java index 2047ffdda..aa6d09629 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchCoveredGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchCoveredGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchMissedGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchMissedGaugeTest.java index b0eec30ae..508e0b905 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchMissedGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchMissedGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchTotalGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchTotalGaugeTest.java index 848bce785..c69601648 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchTotalGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchTotalGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassCoveredGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassCoveredGaugeTest.java index 1913451fd..634fa91b1 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassCoveredGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassCoveredGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassMissedGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassMissedGaugeTest.java index 9785fe218..e0ce4b063 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassMissedGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassMissedGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassTotalGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassTotalGaugeTest.java index 87abafa95..f59dcd969 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassTotalGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassTotalGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileCoveredGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileCoveredGaugeTest.java index 16670222d..b2bde4e07 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileCoveredGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileCoveredGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileMissedGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileMissedGaugeTest.java index e363ba734..ad8230ce9 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileMissedGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileMissedGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileTotalGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileTotalGaugeTest.java index 46ff61486..49d751bb1 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileTotalGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFileTotalGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionCoveredGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionCoveredGaugeTest.java index 521bb4a34..13386ccc5 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionCoveredGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionCoveredGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionMissedGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionMissedGaugeTest.java index 0793a4830..f78cbaa95 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionMissedGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionMissedGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionTotalGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionTotalGaugeTest.java index 4d520a347..f3ccbe981 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionTotalGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionTotalGaugeTest.java @@ -3,8 +3,8 @@ import edu.hm.hafner.coverage.Metric; import io.jenkins.plugins.coverage.metrics.model.Baseline; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsAvailableGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsAvailableGaugeTest.java index 82f196b44..a819b2247 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsAvailableGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsAvailableGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsBusyGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsBusyGaugeTest.java index 961a1a465..66838f06d 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsBusyGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsBusyGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsConnectingGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsConnectingGaugeTest.java index 7abda1760..3491f4891 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsConnectingGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsConnectingGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsDefinedGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsDefinedGaugeTest.java index 8687ce98a..3149a001f 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsDefinedGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsDefinedGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsIdleGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsIdleGaugeTest.java index 684da921d..c6328e8c9 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsIdleGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsIdleGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsOnlineGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsOnlineGaugeTest.java index 5e06593f7..82b0a65cc 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsOnlineGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsOnlineGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsQueueLengthGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsQueueLengthGaugeTest.java index c1f8dcfb3..5dc7a9dd0 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsQueueLengthGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/executors/ExecutorsQueueLengthGaugeTest.java @@ -2,7 +2,7 @@ import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedLoadStatisticSnapshotTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUpGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUpGaugeTest.java index 7d8fd4736..433e94fdf 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUpGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUpGaugeTest.java @@ -3,7 +3,7 @@ import hudson.init.InitMilestone; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedJenkinsTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUptimeGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUptimeGaugeTest.java index 9fb2a5317..529c1978a 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUptimeGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsUptimeGaugeTest.java @@ -3,7 +3,7 @@ import hudson.model.Computer; import io.prometheus.client.Collector; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedJenkinsTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsVersionInfoTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsVersionInfoTest.java index 14e964dac..638001a64 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsVersionInfoTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/JenkinsVersionInfoTest.java @@ -3,8 +3,8 @@ import io.prometheus.client.Collector; import jenkins.model.Jenkins; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedJenkinsTest; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -16,7 +16,7 @@ public class JenkinsVersionInfoTest extends MockedJenkinsTest { public void testCollectResult() throws Exception { - setFinalStatic(Jenkins.class.getDeclaredField("VERSION"), "123"); + setFinalStaticTo123(Jenkins.class.getDeclaredField("VERSION")); JenkinsVersionInfo sut = new JenkinsVersionInfo(new String[]{}, getNamespace(), getSubSystem()); @@ -40,12 +40,12 @@ public void testCollectResult() throws Exception { } - static void setFinalStatic(Field field, Object newValue) throws Exception { + static void setFinalStaticTo123(Field field) throws Exception { field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); + field.set(null, "123"); } } \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/NodesOnlineGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/NodesOnlineGaugeTest.java index cc2e5a895..7449d4559 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/NodesOnlineGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jenkins/NodesOnlineGaugeTest.java @@ -5,7 +5,7 @@ import io.prometheus.client.Collector; import jenkins.model.Jenkins; import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedJenkinsTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -22,7 +22,7 @@ public class NodesOnlineGaugeTest extends MockedJenkinsTest { public void testCollectResult() throws Exception { - setFinalStatic(Jenkins.class.getDeclaredField("VERSION"), "123"); + setFinalStaticTo123(Jenkins.class.getDeclaredField("VERSION")); List nodes = new ArrayList<>(); nodes.add(mockNode("node1", true)); @@ -63,16 +63,16 @@ private Node mockNode(String nodeName, boolean isOnline) { Computer computerMock = mock(Computer.class); when(computerMock.isOnline()).thenReturn(isOnline); when(nodeMock.toComputer()).thenReturn(computerMock); + when(nodeMock.getNodeName()).thenReturn(nodeName); } - when(nodeMock.getNodeName()).thenReturn(nodeName); return nodeMock; } - static void setFinalStatic(Field field, Object newValue) throws Exception { + static void setFinalStaticTo123(Field field) throws Exception { field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); + field.set(null, "123"); } } \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/BuildDiscardGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/BuildDiscardGaugeTest.java index 464d62abf..8372c78fe 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/BuildDiscardGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/BuildDiscardGaugeTest.java @@ -2,7 +2,7 @@ import hudson.tasks.LogRotator; import io.prometheus.client.Collector; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; @@ -10,8 +10,9 @@ public class BuildDiscardGaugeTest extends JobCollectorTest { - @Override - void testCollectResult() { + + @Test + public void testCollectResult() { when(job.getBuildDiscarder()).thenReturn(null); BuildDiscardGauge sut = new BuildDiscardGauge(new String[]{"jenkins_job", "repo"}, "default", "jenkins"); diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/CurrentRunDurationGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/CurrentRunDurationGaugeTest.java index e9f066f5f..63c589737 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/CurrentRunDurationGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/CurrentRunDurationGaugeTest.java @@ -2,8 +2,8 @@ import hudson.model.Run; import io.prometheus.client.Collector; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -17,9 +17,10 @@ public class CurrentRunDurationGaugeTest extends JobCollectorTest { @Mock + @SuppressWarnings("rawtypes") Run currentRun; - @Override + @Test public void testCollectResult() { when(currentRun.isBuilding()).thenReturn(true); diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/HealthScoreGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/HealthScoreGaugeTest.java index 2793a27df..77bcd252e 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/HealthScoreGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/HealthScoreGaugeTest.java @@ -2,7 +2,7 @@ import hudson.model.HealthReport; import io.prometheus.client.Collector; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; @@ -10,7 +10,7 @@ public class HealthScoreGaugeTest extends JobCollectorTest { - @Override + @Test public void testCollectResult() { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorTest.java index e9f729adc..2df8719f1 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/JobCollectorTest.java @@ -3,18 +3,16 @@ import hudson.model.Job; import org.jenkinsci.plugins.prometheus.collectors.testutils.CollectorTest; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class JobCollectorTest extends CollectorTest { @Mock + @SuppressWarnings("rawtypes") protected Job job; - abstract void testCollectResult(); - - } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/NbBuildsGaugeTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/NbBuildsGaugeTest.java index ea598e25e..05ed87f5e 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/NbBuildsGaugeTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/jobs/NbBuildsGaugeTest.java @@ -3,7 +3,7 @@ import hudson.model.RunMap; import io.prometheus.client.Collector; import org.jenkinsci.plugins.workflow.job.WorkflowRun; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import java.util.List; diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedJenkinsTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedJenkinsTest.java index 96645d75f..fc67e1bb1 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedJenkinsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedJenkinsTest.java @@ -1,11 +1,11 @@ package org.jenkinsci.plugins.prometheus.collectors.testutils; import jenkins.model.Jenkins; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class MockedJenkinsTest extends CollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedLoadStatisticSnapshotTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedLoadStatisticSnapshotTest.java index cab2a5c00..45c926837 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedLoadStatisticSnapshotTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedLoadStatisticSnapshotTest.java @@ -1,11 +1,11 @@ package org.jenkinsci.plugins.prometheus.collectors.testutils; import hudson.model.LoadStatistics; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class MockedLoadStatisticSnapshotTest extends CollectorTest { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedRunCollectorTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedRunCollectorTest.java index a85ffe588..eea6508d0 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedRunCollectorTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/collectors/testutils/MockedRunCollectorTest.java @@ -1,15 +1,15 @@ package org.jenkinsci.plugins.prometheus.collectors.testutils; import hudson.model.Run; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class MockedRunCollectorTest extends CollectorTest { @Mock - protected Run mock; + protected Run mock; } 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 854841513..8b9ad18be 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfigurationTest.java @@ -2,12 +2,10 @@ import hudson.model.Descriptor; import hudson.util.FormValidation; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import net.sf.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.mockito.Mockito; @@ -15,26 +13,25 @@ import java.util.List; import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; -@RunWith(JUnitParamsRunner.class) +@SuppressWarnings("rawtypes") public class PrometheusConfigurationTest { - private PrometheusConfiguration configuration; + private final PrometheusConfiguration configuration; - @Before - public void setup() { - configuration = Mockito.mock(PrometheusConfiguration.class); + public PrometheusConfigurationTest() { + this.configuration = Mockito.mock(PrometheusConfiguration.class); Mockito.doNothing().when((Descriptor) configuration).load(); } - private List wrongMetricCollectorPeriodsProvider() { + private static List wrongMetricCollectorPeriodsProvider() { return Arrays.asList("0", "-1", "test", null, "100L"); } - @Test - @Parameters(method = "wrongMetricCollectorPeriodsProvider") + @ParameterizedTest + @MethodSource("wrongMetricCollectorPeriodsProvider") public void shouldGetErrorWhenNotPositiveNumber(String metricCollectorPeriod) throws Descriptor.FormException { //given Mockito.when(configuration.configure(any(), any())).thenCallRealMethod(); @@ -46,16 +43,16 @@ public void shouldGetErrorWhenNotPositiveNumber(String metricCollectorPeriod) th FormValidation formValidation = configuration.doCheckCollectingMetricsPeriodInSeconds(metricCollectorPeriod); - assertThat(formValidation.kind).isEqualTo(FormValidation.Kind.ERROR); - assertThat(formValidation.getMessage()).isEqualTo("CollectingMetricsPeriodInSeconds must be a positive value"); + assertEquals(formValidation.kind, FormValidation.Kind.ERROR); + assertEquals(formValidation.getMessage(), "CollectingMetricsPeriodInSeconds must be a positive value"); } - private List correctMetricCollectorPeriodsProvider() { + private static List correctMetricCollectorPeriodsProvider() { return Arrays.asList("1", "100", "5.7", String.valueOf(Integer.MAX_VALUE)); } - @Test - @Parameters(method = "correctMetricCollectorPeriodsProvider") + @ParameterizedTest + @MethodSource("correctMetricCollectorPeriodsProvider") public void shouldReturnOk(String metricCollectorPeriod) throws Descriptor.FormException { //given Mockito.when(configuration.configure(any(), any())).thenCallRealMethod(); @@ -68,7 +65,7 @@ public void shouldReturnOk(String metricCollectorPeriod) throws Descriptor.FormE boolean actual = configuration.configure(request, config); // then - assertThat(actual).isTrue(); + assertTrue(actual); } @Test @@ -83,7 +80,7 @@ public void shouldSetDefaultValue() { long actual = configuration.getCollectingMetricsPeriodInSeconds(); // then - assertThat(actual).isEqualTo(PrometheusConfiguration.DEFAULT_COLLECTING_METRICS_PERIOD_IN_SECONDS); + assertEquals(actual, PrometheusConfiguration.DEFAULT_COLLECTING_METRICS_PERIOD_IN_SECONDS); } @Test @@ -99,12 +96,12 @@ public void shouldSetValueFromEnvForCollectingMetricsPeriodInSeconds() throws Ex long actual = configuration.getCollectingMetricsPeriodInSeconds(); // then - assertThat(actual).isEqualTo(1000); + assertEquals(actual, 1000); } - @Test - @Parameters(method = "wrongMetricCollectorPeriodsProvider") - public void shouldSetDefaultValueWhenEnvCannotBeConvertedToLongORNegativeValue(String wrongValue) throws Exception { + @ParameterizedTest + @MethodSource("wrongMetricCollectorPeriodsProvider") + public void shouldSetDefaultValueWhenEnvCannotBeConvertedToLongOrNegativeValue(String wrongValue) throws Exception { // given Mockito.doCallRealMethod().when(configuration).setCollectingMetricsPeriodInSeconds(anyLong()); Mockito.when(configuration.getCollectingMetricsPeriodInSeconds()).thenCallRealMethod(); @@ -116,7 +113,7 @@ public void shouldSetDefaultValueWhenEnvCannotBeConvertedToLongORNegativeValue(S long actual = configuration.getCollectingMetricsPeriodInSeconds(); // then - assertThat(actual).isEqualTo(PrometheusConfiguration.DEFAULT_COLLECTING_METRICS_PERIOD_IN_SECONDS); + assertEquals(actual, PrometheusConfiguration.DEFAULT_COLLECTING_METRICS_PERIOD_IN_SECONDS); } @Test @@ -128,7 +125,7 @@ public void shouldTakeDefaultValueWhenNothingConfigured() { configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - assertThat(configuration.getCollectDiskUsage()).isFalse(); + assertFalse(configuration.getCollectDiskUsage()); } @Test @@ -136,13 +133,11 @@ public void shouldTakeEnvironmentVariableWhenNothingConfigured() throws Exceptio Mockito.doCallRealMethod().when(configuration).setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); Mockito.doCallRealMethod().when(configuration).getCollectDiskUsage(); + // simulate constructor call withEnvironmentVariable(PrometheusConfiguration.COLLECT_DISK_USAGE, "false") - .execute(() -> { - // simulate constructor call - configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - }); + .execute(configuration::setCollectDiskUsageBasedOnEnvironmentVariableIfDefined); - assertThat(configuration.getCollectDiskUsage()).isFalse(); + assertFalse(configuration.getCollectDiskUsage()); } @Test @@ -150,13 +145,11 @@ public void shouldTakeDefaultIfEnvironmentVariableIsFaulty() throws Exception { Mockito.doCallRealMethod().when(configuration).setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); Mockito.doCallRealMethod().when(configuration).getCollectDiskUsage(); + // simulate constructor call withEnvironmentVariable(PrometheusConfiguration.COLLECT_DISK_USAGE, "not_true_not_false") - .execute(() -> { - // simulate constructor call - configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - }); + .execute(configuration::setCollectDiskUsageBasedOnEnvironmentVariableIfDefined); - assertThat(configuration.getCollectDiskUsage()).isFalse(); + assertFalse(configuration.getCollectDiskUsage()); } @Test @@ -175,7 +168,7 @@ public void shouldTakeConfiguredValueIfEnvironmentVariableIsFaulty() throws Exce configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); }); - assertThat(configuration.getCollectDiskUsage()).isTrue(); + assertTrue(configuration.getCollectDiskUsage()); } @Test @@ -185,19 +178,19 @@ public void shouldTakeConfiguredValueIfItIsConfigured() { // simulate someone configured it over the UI configuration.setCollectDiskUsage(false); - assertThat(configuration.getCollectDiskUsage()).isFalse(); + assertFalse(configuration.getCollectDiskUsage()); // simulate constructor call configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - assertThat(configuration.getCollectDiskUsage()).isFalse(); + assertFalse(configuration.getCollectDiskUsage()); // simulate someone configured it over the UI configuration.setCollectDiskUsage(true); - assertThat(configuration.getCollectDiskUsage()).isTrue(); + assertTrue(configuration.getCollectDiskUsage()); // simulate constructor call configuration.setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - assertThat(configuration.getCollectDiskUsage()).isTrue(); + assertTrue(configuration.getCollectDiskUsage()); } private JSONObject getDefaultConfig() { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/NamedDisabledMetricTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/NamedDisabledMetricTest.java index affe080ab..44001a03d 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/NamedDisabledMetricTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/NamedDisabledMetricTest.java @@ -4,8 +4,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; - public class NamedDisabledMetricTest { @Test diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/RegexDisabledMetricTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/RegexDisabledMetricTest.java index 0ea1175ac..e20766402 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/RegexDisabledMetricTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/config/disabledmetrics/RegexDisabledMetricTest.java @@ -3,8 +3,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; - public class RegexDisabledMetricTest { @Test 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 acb440aac..58bc253e0 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/rest/PrometheusActionTest.java @@ -5,16 +5,17 @@ import jenkins.model.Jenkins; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; import org.jenkinsci.plugins.prometheus.service.PrometheusMetrics; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +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.mockito.Mock; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import javax.servlet.ServletException; import java.io.IOException; @@ -22,10 +23,9 @@ import java.io.StringWriter; import static java.net.HttpURLConnection.*; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PrometheusActionTest { @Mock @@ -35,15 +35,15 @@ public class PrometheusActionTest { private MockedStatic jenkinsStatic; - @Before + @BeforeEach public void setUp() { jenkinsStatic = mockStatic(Jenkins.class); - jenkinsStatic.when(() -> Jenkins.get()).thenReturn(jenkins); + jenkinsStatic.when(Jenkins::get).thenReturn(jenkins); when(jenkins.getDescriptor(PrometheusConfiguration.class)).thenReturn(configuration); when(configuration.getAdditionalPath()).thenReturn("prometheus"); } - @After + @AfterEach public void tearDown() { jenkinsStatic.close(); } @@ -113,12 +113,14 @@ private static class AssertStaplerResponse { private final HttpResponse httpResponse; private final StringWriter stringWriter; + private AssertStaplerResponse(HttpResponse httpResponse) throws IOException { this.httpResponse = httpResponse; this.response = mock(StaplerResponse.class); stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); - when(response.getWriter()).thenReturn(writer); + + lenient().when(response.getWriter()).thenReturn(writer); } static AssertStaplerResponse from(HttpResponse actual) throws IOException { @@ -141,7 +143,7 @@ private AssertStaplerResponse assertHttpHeader(String name, String value) { } private AssertStaplerResponse assertBody(String payload) { - assertThat(stringWriter).hasToString(payload); + Assertions.assertEquals(stringWriter.toString(), payload); return this; } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/service/PrometheusAsyncWorkerTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/service/PrometheusAsyncWorkerTest.java index 0ca930be4..57065871a 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/service/PrometheusAsyncWorkerTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/service/PrometheusAsyncWorkerTest.java @@ -1,11 +1,12 @@ package org.jenkinsci.plugins.prometheus.service; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class PrometheusAsyncWorkerTest { @@ -21,7 +22,8 @@ public void shouldCollectMetrics() { // then String actual = metrics.getMetrics(); - assertThat(actual).isEqualTo("1"); + assertEquals("1", actual); + } private static class TestPrometheusMetrics implements PrometheusMetrics { diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/ArrayUtilsTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/ArrayUtilsTest.java index 8e8ecc5ef..a30b0981e 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/ArrayUtilsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/ArrayUtilsTest.java @@ -1,7 +1,7 @@ package org.jenkinsci.plugins.prometheus.util; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ArrayUtilsTest { 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 17d89fe49..009d56896 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/ConfigurationUtilsTest.java @@ -1,17 +1,16 @@ package org.jenkinsci.plugins.prometheus.util; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.MockedStatic; import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; -@RunWith(JUnitParamsRunner.class) + public class ConfigurationUtilsTest { @Test @@ -19,27 +18,27 @@ public void verifyGetNamespaceWhenEnvIsNonEmpty() throws Exception { String namespace = "foobar"; withEnvironmentVariable("PROMETHEUS_NAMESPACE", namespace).execute(() -> { String result = ConfigurationUtils.getNamespace(); - assertThat(result).isEqualTo(namespace); + assertEquals(namespace, result); }); } - @Test - @Parameters({"true", "false"}) + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void verifyGetNamespaceWhenEnvIsNotSetOrEmpty(boolean notSetOrEmpty) throws Exception { PrometheusConfiguration config = mock(PrometheusConfiguration.class); String namespace = "default-namespace"; when(config.getDefaultNamespace()).thenReturn(namespace); try (MockedStatic configStatic = mockStatic(PrometheusConfiguration.class)) { - configStatic.when(() -> PrometheusConfiguration.get()).thenReturn(config); + configStatic.when(PrometheusConfiguration::get).thenReturn(config); withEnvironmentVariable("PROMETHEUS_NAMESPACE", notSetOrEmpty ? null : "").execute(() -> { String result = ConfigurationUtils.getNamespace(); - assertThat(result).isEqualTo(namespace); + assertEquals(namespace, result); }); } } @Test public void verifyGetSubSystem() { - assertThat(ConfigurationUtils.getSubSystem()).isEqualTo("jenkins"); + assertEquals("jenkins", ConfigurationUtils.getSubSystem()); } } diff --git a/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java b/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java index 5301f21a0..e38a830c0 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/JenkinsNodeBuildsSampleBuilderTest.java @@ -1,15 +1,17 @@ package org.jenkinsci.plugins.prometheus.util; import io.prometheus.client.Collector; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class JenkinsNodeBuildsSampleBuilderTest { @Test public void master_node_count_format() { - Assert.assertEquals( + assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds_count", Arrays.asList("node", "quantile"), @@ -19,8 +21,8 @@ public void master_node_count_format() { new JenkinsNodeBuildsSampleBuilder().createSample( "jenkins.node.builds", "_count", - Arrays.asList("quantile"), - Arrays.asList("0.5"), + List.of("quantile"), + List.of("0.5"), 0.091670452 ) ); @@ -28,7 +30,7 @@ public void master_node_count_format() { @Test public void master_node_histogram_format() { - Assert.assertEquals( + assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds", Arrays.asList("node", "quantile"), @@ -38,8 +40,8 @@ public void master_node_histogram_format() { new JenkinsNodeBuildsSampleBuilder().createSample( "jenkins.node.builds", "", - Arrays.asList("quantile"), - Arrays.asList("0.999"), + List.of("quantile"), + List.of("0.999"), 0.091670452 ) ); @@ -47,7 +49,7 @@ public void master_node_histogram_format() { @Test public void named_node_count_format() { - Assert.assertEquals( + assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds_count", Arrays.asList("node", "quantile"), @@ -57,8 +59,8 @@ public void named_node_count_format() { new JenkinsNodeBuildsSampleBuilder().createSample( "jenkins.node.evil node_name.com.builds", "_count", - Arrays.asList("quantile"), - Arrays.asList("0.5"), + List.of("quantile"), + List.of("0.5"), 0.091670452 ) ); @@ -66,7 +68,7 @@ public void named_node_count_format() { @Test public void named_node_histogram_format() { - Assert.assertEquals( + assertEquals( new Collector.MetricFamilySamples.Sample( "jenkins_node_builds", Arrays.asList("node", "quantile"), @@ -76,8 +78,8 @@ public void named_node_histogram_format() { new JenkinsNodeBuildsSampleBuilder().createSample( "jenkins.node.evil node_name.com.builds", "", - Arrays.asList("quantile"), - Arrays.asList("0.999"), + List.of("quantile"), + List.of("0.999"), 0.091670452 ) ); 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 925cc748c..57266914c 100644 --- a/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java +++ b/src/test/java/org/jenkinsci/plugins/prometheus/util/JobsTest.java @@ -2,7 +2,6 @@ import hudson.model.Job; import jenkins.model.Jenkins; -import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; @@ -10,10 +9,9 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.mockStatic; +@SuppressWarnings("rawtypes") public class JobsTest { @Test @@ -26,9 +24,7 @@ void testEachJob() { List names = new ArrayList<>(); - Jobs.forEachJob(job -> { - names.add(job.getName()); - }); + Jobs.forEachJob(job -> names.add(job.getName())); Assertions.assertEquals(2, names.size()); Assertions.assertTrue(names.contains("name1")); @@ -36,6 +32,7 @@ void testEachJob() { } } + private static Job mockJob(String name) { Job mock = mock(Job.class); when(mock.getName()).thenReturn(name);