From 857c9ac0b8d14c945ac24665d740c70174df1349 Mon Sep 17 00:00:00 2001 From: Nischal Sharma Date: Thu, 15 Jun 2023 05:13:12 +0530 Subject: [PATCH] junit4 to junit5 (#5600) Signed-off-by: Nischal Sharma Co-authored-by: Sally MacFarlane --- metrics/core/build.gradle | 2 +- .../besu/metrics/RunnableTimedCounterTest.java | 8 ++++---- .../besu/metrics/noop/NoOpMetricsSystemTest.java | 2 +- .../OpenTelemetryMetricsSystemTest.java | 12 ++++++------ .../metrics/prometheus/MetricsHttpServiceTest.java | 14 +++++--------- .../prometheus/PrometheusMetricsSystemTest.java | 6 +++--- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index 5dc48ef5147..310a1588e8d 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -65,10 +65,10 @@ dependencies { testImplementation project(':util') testImplementation 'com.squareup.okhttp3:okhttp' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testImplementation 'org.mockito:mockito-junit-jupiter' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/RunnableTimedCounterTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/RunnableTimedCounterTest.java index 18c61a7c462..a6b79eca32c 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/RunnableTimedCounterTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/RunnableTimedCounterTest.java @@ -22,12 +22,12 @@ import java.util.concurrent.TimeUnit; -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.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class RunnableTimedCounterTest { @Mock Counter backedCounter; diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystemTest.java index 807bc495706..c68080f5216 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystemTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NoOpMetricsSystemTest { diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java index b1b640112ea..f1bff33e555 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java @@ -43,9 +43,9 @@ import com.google.common.collect.ImmutableSet; import io.opentelemetry.api.GlobalOpenTelemetry; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class OpenTelemetryMetricsSystemTest { @@ -54,7 +54,7 @@ public class OpenTelemetryMetricsSystemTest { .thenComparing(Observation::getMetricName) .thenComparing((o1, o2) -> o1.getLabels().equals(o2.getLabels()) ? 0 : 1); - @Before + @BeforeEach public void resetGlobalOpenTelemetry() { GlobalOpenTelemetry.resetForTest(); } @@ -74,12 +74,12 @@ private List getObservation(final ObservableMetricsSystem metricsSy return null; } - @Before + @BeforeEach public void setUp() { metricsSystem = new OpenTelemetrySystem(DEFAULT_METRIC_CATEGORIES, true, "job", false); } - @After + @AfterEach public void tearDown() { metricsSystem.shutdown(); } diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java index c867bfb647d..064dabfe331 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java @@ -29,23 +29,19 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class MetricsHttpServiceTest { - @ClassRule public static final TemporaryFolder folder = new TemporaryFolder(); - private static final Vertx vertx = Vertx.vertx(); private static MetricsHttpService service; private static OkHttpClient client; private static String baseUrl; - @BeforeClass + @BeforeAll public static void initServerAndClient() { service = createMetricsHttpService(); service.start().join(); @@ -76,7 +72,7 @@ private static MetricsConfiguration.Builder createMetricsConfigBuilder() { } /** Tears down the HTTP server. */ - @AfterClass + @AfterAll public static void shutdownServer() { service.stop().join(); vertx.close(); diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java index a1913b6574b..7c62f1f0b6c 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -42,8 +42,8 @@ import com.google.common.collect.ImmutableSet; import io.opentelemetry.api.GlobalOpenTelemetry; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class PrometheusMetricsSystemTest { @@ -52,7 +52,7 @@ public class PrometheusMetricsSystemTest { .thenComparing(Observation::getMetricName) .thenComparing((o1, o2) -> o1.getLabels().equals(o2.getLabels()) ? 0 : 1); - @Before + @BeforeEach public void resetGlobalOpenTelemetry() { GlobalOpenTelemetry.resetForTest(); }