Skip to content

Commit

Permalink
Update Tests to Junit5 Framework and removed some unnecessary test de…
Browse files Browse the repository at this point in the history
…pendencies
  • Loading branch information
waschndolos committed Nov 21, 2023
1 parent 3dc4362 commit 3647cf6
Show file tree
Hide file tree
Showing 55 changed files with 179 additions and 210 deletions.
18 changes: 4 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -140,20 +141,15 @@
<artifactId>pipeline-rest-api</artifactId>
</dependency>

<!-- mockito must precede assertj until assertj supports Java 21 -->
<!-- mockito provides a Java 21 capable version of bytebuddy -->
<!-- TODO: restore ordering once assertj supports Java 21 -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<!-- assertj must follow mockito until assertj supports Java 21 -->
<!-- assertj does not provide a Java 21 capable version of bytebuddy -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -168,11 +164,5 @@
<version>${system-lambda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-testlib</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -123,7 +122,7 @@ private static Matcher<MetricFamilySamples> gauges(String name, Matcher<? super
requireNonNull(name);
requireNonNull(samples);

return new TypeSafeDiagnosingMatcher<MetricFamilySamples>(MetricFamilySamples.class) {
return new TypeSafeDiagnosingMatcher<>(MetricFamilySamples.class) {
@Override
public void describeTo(Description description) {
description.appendText("gauges named ")
Expand Down Expand Up @@ -158,7 +157,7 @@ protected boolean matchesSafely(MetricFamilySamples item, Description mismatchDe
private static Matcher<MetricFamilySamples.Sample> sample(Map<String, String> labels, Matcher<Double> value) {
requireNonNull(labels);

return new TypeSafeDiagnosingMatcher<MetricFamilySamples.Sample>(MetricFamilySamples.Sample.class) {
return new TypeSafeDiagnosingMatcher<>(MetricFamilySamples.Sample.class) {
@Override
public void describeTo(Description description) {
description.appendText("sample labeled ")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

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;


public class StageSummaryTest extends MockedRunCollectorTest {

@Mock
WorkflowRun mockedWorkflowRun;

@Test
public void testNothingCalculatedWhenJobIsBuilding() {
Mockito.when(mock.isBuilding()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 3647cf6

Please sign in to comment.