diff --git a/enclave/build.gradle b/enclave/build.gradle index 235962cda7..302b2f246a 100644 --- a/enclave/build.gradle +++ b/enclave/build.gradle @@ -17,8 +17,6 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - // integration test dependencies. integrationTestImplementation project(':testutil') integrationTestImplementation 'org.assertj:assertj-core' @@ -27,6 +25,4 @@ dependencies { integrationTestImplementation 'org.junit.jupiter:junit-jupiter-api' integrationTestImplementation 'org.mockito:mockito-core' integrationTestImplementation 'org.testcontainers:testcontainers' - - integrationTestRuntimeOnly 'org.junit.jupiter:junit-jupiter' } diff --git a/gradle/check-licenses.gradle b/gradle/check-licenses.gradle index 9bea3e148c..3939c19116 100644 --- a/gradle/check-licenses.gradle +++ b/gradle/check-licenses.gradle @@ -126,7 +126,8 @@ downloadLicenses { ], (epl2) : [ 'Eclipse Public License - v 2.0', - 'Eclipse Public License version 2.0' + 'Eclipse Public License version 2.0', + 'Eclipse Public License v2.0' ], (mit) : [ 'MIT', diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index 310a1588e8..295cdada97 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -70,8 +70,6 @@ dependencies { testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' - testSupportImplementation 'org.mockito:mockito-core' annotationProcessor 'com.google.dagger:dagger-compiler' diff --git a/plugins/rocksdb/build.gradle b/plugins/rocksdb/build.gradle index dc5438f86c..fa4b0e9f0e 100644 --- a/plugins/rocksdb/build.gradle +++ b/plugins/rocksdb/build.gradle @@ -55,6 +55,7 @@ dependencies { 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/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest.java index 2a2ec01ca4..2c9fc86df1 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest.java @@ -25,6 +25,8 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import org.apache.tuweni.bytes.Bytes; + public class OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest extends RocksDBColumnarKeyValueStorageTest { @@ -32,7 +34,9 @@ public class OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest protected SegmentedKeyValueStorage createSegmentedStore() throws Exception { return new OptimisticRocksDBColumnarKeyValueStorage( - new RocksDBConfigurationBuilder().databaseDir(folder.newFolder().toPath()).build(), + new RocksDBConfigurationBuilder() + .databaseDir(folder.resolve(Bytes.random(9).toString())) + .build(), Arrays.asList(TestSegment.FOO, TestSegment.BAR), List.of(), new NoOpMetricsSystem(), diff --git a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java index d58da12ce2..98eaf03496 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java @@ -35,13 +35,12 @@ import java.util.Set; import java.util.function.Consumer; import org.apache.commons.lang3.tuple.Pair; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValueStorageTest { - @Rule public final TemporaryFolder folder = new TemporaryFolder(); + @TempDir public Path folder; @Test public void assertClear() throws Exception { @@ -178,8 +177,8 @@ public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValu } @Test - public void dbShouldIgnoreExperimentalSegmentsIfNotExisted() throws Exception { - final Path testPath = folder.newFolder().toPath(); + public void dbShouldIgnoreExperimentalSegmentsIfNotExisted(@TempDir final Path testPath) + throws Exception { // Create new db should ignore experimental column family SegmentedKeyValueStorage store = createSegmentedStore( @@ -195,8 +194,8 @@ public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValu } @Test - public void dbShouldNotIgnoreExperimentalSegmentsIfExisted() throws Exception { - final Path testPath = folder.newFolder().toPath(); + public void dbShouldNotIgnoreExperimentalSegmentsIfExisted(@TempDir final Path testPath) + throws Exception { // Create new db with experimental column family SegmentedKeyValueStorage store = createSegmentedStore( @@ -225,8 +224,8 @@ public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValu } @Test - public void dbWillBeBackwardIncompatibleAfterExperimentalSegmentsAreAdded() throws Exception { - final Path testPath = folder.newFolder().toPath(); + public void dbWillBeBackwardIncompatibleAfterExperimentalSegmentsAreAdded( + @TempDir final Path testPath) throws Exception { // Create new db should ignore experimental column family SegmentedKeyValueStorage store = createSegmentedStore( diff --git a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBKeyValueStorageTest.java index d9e7aec9de..78968873ec 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBKeyValueStorageTest.java @@ -35,24 +35,24 @@ import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksD import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder; import org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage; +import java.nio.file.Path; import java.util.function.LongSupplier; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class RocksDBKeyValueStorageTest extends AbstractKeyValueStorageTest { @Mock private ObservableMetricsSystem metricsSystemMock; @Mock private LabelledMetric labelledMetricOperationTimerMock; @Mock private LabelledMetric labelledMetricCounterMock; @Mock private OperationTimer operationTimerMock; - @Rule public final TemporaryFolder folder = new TemporaryFolder(); + @TempDir static Path folder; @Override protected KeyValueStorage createStore() throws Exception { @@ -131,6 +131,6 @@ public class RocksDBKeyValueStorageTest extends AbstractKeyValueStorageTest { } private RocksDBConfiguration config() throws Exception { - return new RocksDBConfigurationBuilder().databaseDir(folder.newFolder().toPath()).build(); + return new RocksDBConfigurationBuilder().databaseDir(getTempSubFolder(folder)).build(); } } diff --git a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/TransactionDBRocksDBColumnarKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/TransactionDBRocksDBColumnarKeyValueStorageTest.java index 3542855c17..d7d4e12da7 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/TransactionDBRocksDBColumnarKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/TransactionDBRocksDBColumnarKeyValueStorageTest.java @@ -32,7 +32,7 @@ public class TransactionDBRocksDBColumnarKeyValueStorageTest protected SegmentedKeyValueStorage createSegmentedStore() throws Exception { return new TransactionDBRocksDBColumnarKeyValueStorage( - new RocksDBConfigurationBuilder().databaseDir(folder.newFolder().toPath()).build(), + new RocksDBConfigurationBuilder().databaseDir(getTempSubFolder(folder)).build(), Arrays.asList(TestSegment.FOO, TestSegment.BAR), List.of(), new NoOpMetricsSystem(), diff --git a/services/kvstore/build.gradle b/services/kvstore/build.gradle index 99c26a5ecf..0415f6702b 100644 --- a/services/kvstore/build.gradle +++ b/services/kvstore/build.gradle @@ -33,8 +33,6 @@ dependencies { implementation 'com.google.guava:guava' testImplementation project(':testutil') - testImplementation 'junit:junit' + testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.assertj:assertj-core' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/services/kvstore/src/test/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorageTest.java b/services/kvstore/src/test/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorageTest.java index a416c86542..affcec0715 100644 --- a/services/kvstore/src/test/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorageTest.java +++ b/services/kvstore/src/test/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorageTest.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LimitedInMemoryKeyValueStorageTest extends AbstractKeyValueStorageTest { diff --git a/services/pipeline/build.gradle b/services/pipeline/build.gradle index 0df845f76d..b86edbf344 100644 --- a/services/pipeline/build.gradle +++ b/services/pipeline/build.gradle @@ -37,11 +37,9 @@ dependencies { implementation 'io.opentelemetry:opentelemetry-api' implementation 'com.google.guava:guava' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + testImplementation 'org.mockito:mockito-junit-jupiter' } diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/AsyncOperationProcessorTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/AsyncOperationProcessorTest.java index c15c615e9a..1b9f820243 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/AsyncOperationProcessorTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/AsyncOperationProcessorTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.when; import java.util.concurrent.CompletableFuture; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AsyncOperationProcessorTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/BatchingReadPipeTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/BatchingReadPipeTest.java index e2f7195f67..fb90128fbb 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/BatchingReadPipeTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/BatchingReadPipeTest.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.plugin.services.metrics.Counter; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BatchingReadPipeTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/CompleterStageTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/CompleterStageTest.java index 90c1b3c1e8..ef3e29afeb 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/CompleterStageTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/CompleterStageTest.java @@ -20,7 +20,7 @@ import static org.hyperledger.besu.metrics.noop.NoOpMetricsSystem.NO_OP_COUNTER; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CompleterStageTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/FlatMapProcessorTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/FlatMapProcessorTest.java index a6a68aa797..1012d3b012 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/FlatMapProcessorTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/FlatMapProcessorTest.java @@ -24,7 +24,7 @@ import static org.mockito.Mockito.when; import java.util.function.Function; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FlatMapProcessorTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/IteratorSourceStageTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/IteratorSourceStageTest.java index 6c7f077dcb..02052615b7 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/IteratorSourceStageTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/IteratorSourceStageTest.java @@ -18,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.metrics.noop.NoOpMetricsSystem.NO_OP_COUNTER; import com.google.common.collect.Iterators; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class IteratorSourceStageTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/MapProcessorTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/MapProcessorTest.java index 8e5ff6bbde..0d7a913c3e 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/MapProcessorTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/MapProcessorTest.java @@ -23,7 +23,7 @@ import static org.mockito.Mockito.when; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MapProcessorTest { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipeTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipeTest.java index 7ce16dfbef..c838bc887a 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipeTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipeTest.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.plugin.services.metrics.Counter; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PipeTest { private final Counter inputCounter = mock(Counter.class); diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipelineBuilderTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipelineBuilderTest.java index 9b33ba2470..1ec64ab65f 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipelineBuilderTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/PipelineBuilderTest.java @@ -51,8 +51,8 @@ import java.util.function.Function; import java.util.stream.Stream; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public class PipelineBuilderTest { @@ -66,7 +66,7 @@ public class PipelineBuilderTest { private final ExecutorService executorService = Executors.newCachedThreadPool(THREAD_FACTORY); - @After + @AfterEach public void afterClass() throws Exception { executorService.shutdownNow(); if (!executorService.awaitTermination(10, SECONDS)) { diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/ProcessingStageTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/ProcessingStageTest.java index ad02ca03c7..efbe16da66 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/ProcessingStageTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/ProcessingStageTest.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.services.pipeline; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.metrics.noop.NoOpMetricsSystem.NO_OP_COUNTER; -import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -24,13 +24,13 @@ import static org.mockito.Mockito.when; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +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 ProcessingStageTest { private final Pipe inputPipe = @@ -40,10 +40,11 @@ public class ProcessingStageTest { @Mock private Processor singleStep; private ProcessingStage stage; - @Before + @BeforeEach public void setUp() { stage = new ProcessingStage<>("name", inputPipe, outputPipe, singleStep); - doAnswer( + lenient() + .doAnswer( invocation -> { outputPipe.put(inputPipe.get().toLowerCase(Locale.UK)); return 1; diff --git a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/SharedWritePipeTest.java b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/SharedWritePipeTest.java index 77d0a0e731..5d99c1c037 100644 --- a/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/SharedWritePipeTest.java +++ b/services/pipeline/src/test/java/org/hyperledger/besu/services/pipeline/SharedWritePipeTest.java @@ -18,7 +18,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SharedWritePipeTest { diff --git a/services/tasks/build.gradle b/services/tasks/build.gradle index f398248c73..66784412dc 100644 --- a/services/tasks/build.gradle +++ b/services/tasks/build.gradle @@ -40,9 +40,6 @@ dependencies { implementation 'io.vertx:vertx-core' implementation 'org.apache.tuweni:tuweni-bytes' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/AbstractTaskQueueTest.java b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/AbstractTaskQueueTest.java index ec7f02d802..d4c6e30fc6 100644 --- a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/AbstractTaskQueueTest.java +++ b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/AbstractTaskQueueTest.java @@ -23,7 +23,7 @@ import java.util.concurrent.CountDownLatch; import java.util.function.Function; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; abstract class AbstractTaskQueueTest> { diff --git a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/CachingTaskCollectionTest.java b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/CachingTaskCollectionTest.java index 12fe88acc7..c88e994ceb 100644 --- a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/CachingTaskCollectionTest.java +++ b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/CachingTaskCollectionTest.java @@ -23,13 +23,13 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class CachingTaskCollectionTest { private TaskCollection wrappedTaskCollection; - @Before + @BeforeEach public void setup() { wrappedTaskCollection = new InMemoryTaskQueue<>(); } diff --git a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/InMemoryTasksPriorityQueuesTest.java b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/InMemoryTasksPriorityQueuesTest.java index 6219b77098..4817160d30 100644 --- a/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/InMemoryTasksPriorityQueuesTest.java +++ b/services/tasks/src/test/java/org/hyperledger/besu/services/tasks/InMemoryTasksPriorityQueuesTest.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InMemoryTasksPriorityQueuesTest { diff --git a/testutil/build.gradle b/testutil/build.gradle index 193569c72c..f235bb054f 100644 --- a/testutil/build.gradle +++ b/testutil/build.gradle @@ -36,7 +36,7 @@ dependencies { implementation 'com.google.guava:guava' implementation 'com.squareup.okhttp3:okhttp' implementation 'io.vertx:vertx-core' - implementation 'junit:junit' + implementation 'org.junit.jupiter:junit-jupiter' implementation 'org.apache.tuweni:tuweni-bytes' implementation 'org.apache.tuweni:tuweni-io' implementation 'org.apache.tuweni:tuweni-toml' diff --git a/testutil/src/main/java/org/hyperledger/besu/kvstore/AbstractKeyValueStorageTest.java b/testutil/src/main/java/org/hyperledger/besu/kvstore/AbstractKeyValueStorageTest.java index c24198c026..60a6633676 100644 --- a/testutil/src/main/java/org/hyperledger/besu/kvstore/AbstractKeyValueStorageTest.java +++ b/testutil/src/main/java/org/hyperledger/besu/kvstore/AbstractKeyValueStorageTest.java @@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -32,11 +33,12 @@ import java.util.stream.Stream; import org.apache.commons.lang3.tuple.Pair; import org.apache.tuweni.bytes.Bytes; -import org.junit.Ignore; -import org.junit.Test; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** The Abstract key value storage test. */ -@Ignore +@Disabled public abstract class AbstractKeyValueStorageTest { /** @@ -352,12 +354,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionPutAfterCommit() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.commit(); - tx.put(bytesOf(1), bytesOf(1)); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.commit(); + tx.put(bytesOf(1), bytesOf(1)); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -365,12 +371,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionRemoveAfterCommit() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.commit(); - tx.remove(bytesOf(1)); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.commit(); + tx.remove(bytesOf(1)); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -378,12 +388,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionPutAfterRollback() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.rollback(); - tx.put(bytesOf(1), bytesOf(1)); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.rollback(); + tx.put(bytesOf(1), bytesOf(1)); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -391,12 +405,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionRemoveAfterRollback() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.rollback(); - tx.remove(bytesOf(1)); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.rollback(); + tx.remove(bytesOf(1)); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -404,12 +422,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionCommitAfterRollback() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.rollback(); - tx.commit(); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.rollback(); + tx.commit(); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -417,12 +439,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionCommitTwice() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.commit(); - tx.commit(); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.commit(); + tx.commit(); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -430,12 +456,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionRollbackAfterCommit() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.commit(); - tx.rollback(); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.commit(); + tx.rollback(); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -443,12 +473,16 @@ public abstract class AbstractKeyValueStorageTest { * * @throws Exception the exception */ - @Test(expected = IllegalStateException.class) + @Test public void transactionRollbackTwice() throws Exception { - final KeyValueStorage store = createStore(); - final KeyValueStorageTransaction tx = store.startTransaction(); - tx.rollback(); - tx.rollback(); + Assertions.assertThatThrownBy( + () -> { + final KeyValueStorage store = createStore(); + final KeyValueStorageTransaction tx = store.startTransaction(); + tx.rollback(); + tx.rollback(); + }) + .isInstanceOf(IllegalStateException.class); } /** @@ -547,4 +581,15 @@ public abstract class AbstractKeyValueStorageTest { protected byte[] bytesOf(final int... bytes) { return Bytes.of(bytes).toArrayUnsafe(); } + + /** + * Create a sub folder from the given path, that will not conflict with other folders. + * + * @param folder the folder in which to create the sub folder + * @return the path representing the sub folder + * @throws Exception if the folder cannot be created + */ + protected Path getTempSubFolder(final Path folder) throws Exception { + return java.nio.file.Files.createTempDirectory(folder, null); + } }