From ad156febc91e2c1d51da3c98d88bb8a7b5031acd Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 12:18:46 +1000 Subject: [PATCH] junit 5 ftw Signed-off-by: Sally MacFarlane --- consensus/common/build.gradle | 2 +- .../CombinedProtocolScheduleFactoryTest.java | 8 ++++---- .../consensus/common/ForksScheduleTest.java | 2 +- .../MigratingMiningCoordinatorTest.java | 16 ++++++++-------- .../common/MigratingProtocolContextTest.java | 2 +- .../BaseBftProtocolScheduleBuilderTest.java | 2 +- .../bft/BaseForksSchedulesFactoryTest.java | 2 +- .../common/bft/BftEventQueueTest.java | 2 +- .../bft/BftForksScheduleFactoryTest.java | 2 +- .../consensus/common/bft/BftHelpersTest.java | 2 +- .../common/bft/BftProcessorTest.java | 12 ++++++------ .../consensus/common/bft/BlockTimerTest.java | 12 ++++++------ .../bft/EthSynchronizerUpdaterTest.java | 8 ++++---- .../common/bft/MessageTrackerTest.java | 2 +- .../consensus/common/bft/RoundTimerTest.java | 12 ++++++------ .../common/bft/SizeLimitedMapTest.java | 2 +- .../bft/UniqueMessageMulticasterTest.java | 8 ++++---- .../besu/consensus/common/bft/VoteTest.java | 2 +- .../BftMiningCoordinatorTest.java | 19 ++++++++++--------- .../blockcreation/ProposerSelectorTest.java | 2 +- .../BftCoinbaseValidationRuleTest.java | 2 +- .../BftCommitSealsValidationRuleTest.java | 2 +- .../BftValidatorsValidationRuleTest.java | 2 +- .../BftVanityDataValidationRuleTest.java | 2 +- .../bft/network/ValidatorPeersTest.java | 17 +++++++++-------- .../bft/queries/BftQueryServiceImplTest.java | 12 ++++++------ .../statemachine/FutureMessageBufferTest.java | 6 +++--- .../blockbased/ForkingVoteTallyCacheTest.java | 2 +- .../blockbased/VoteProposerTest.java | 2 +- .../blockbased/VoteTallyCacheTest.java | 2 +- .../blockbased/VoteTallyCacheTestBase.java | 4 ++-- .../validator/blockbased/VoteTallyTest.java | 2 +- .../blockbased/VoteTallyUpdaterTest.java | 2 +- 33 files changed, 89 insertions(+), 87 deletions(-) diff --git a/consensus/common/build.gradle b/consensus/common/build.gradle index 49c73e7d176..04132ab6d00 100644 --- a/consensus/common/build.gradle +++ b/consensus/common/build.gradle @@ -53,11 +53,11 @@ dependencies { testImplementation project( path: ':crypto:services', configuration: 'testSupportArtifacts') testImplementation project(':metrics:core') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' 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/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 29b197b9ece..9c1e8005a80 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -35,11 +35,11 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CombinedProtocolScheduleFactoryTest { private final CombinedProtocolScheduleFactory combinedProtocolScheduleFactory = diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java index bf6d32f4694..053037e933c 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ForksScheduleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java index 31eabf22aaf..df301f44a17 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java @@ -16,6 +16,7 @@ import static java.util.Collections.emptyList; import static org.hyperledger.besu.ethereum.core.BlockHeader.GENESIS_BLOCK_NUMBER; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -40,13 +41,13 @@ import java.util.function.Consumer; import org.apache.tuweni.bytes.Bytes; -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 MigratingMiningCoordinatorTest { @Mock private BftMiningCoordinator coordinator1; @@ -58,7 +59,7 @@ public class MigratingMiningCoordinatorTest { private ForksSchedule coordinatorSchedule; private static final long MIGRATION_BLOCK_NUMBER = 5L; - @Before + @BeforeEach public void setup() { coordinatorSchedule = createCoordinatorSchedule(coordinator1, coordinator2); final Block block = new Block(blockHeader, blockBody); @@ -87,13 +88,12 @@ public void startShouldRegisterThisCoordinatorAsObserver() { @Test public void startShouldUnregisterDelegateCoordinatorAsObserver() { final BftMiningCoordinator delegateCoordinator = createDelegateCoordinator(); - when(blockchain.observeBlockAdded(delegateCoordinator)).thenReturn(1L); + lenient().when(blockchain.observeBlockAdded(delegateCoordinator)).thenReturn(1L); final MigratingMiningCoordinator coordinator = new MigratingMiningCoordinator( createCoordinatorSchedule(delegateCoordinator, coordinator2), blockchain); coordinator.start(); - verify(blockchain).observeBlockAdded(coordinator); verify(blockchain).observeBlockAdded(delegateCoordinator); verify(blockchain).removeObserver(1L); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index 21ba7638c40..c675219c352 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class MigratingProtocolContextTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java index d704cddce85..b2b2a9fe3af 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java @@ -42,7 +42,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BaseBftProtocolScheduleBuilderTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java index 5102276f8e8..ba65dffbff7 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java @@ -30,7 +30,7 @@ import java.util.function.Consumer; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class BaseForksSchedulesFactoryTest< C extends BftConfigOptions, M extends MutableBftConfigOptions> { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java index 28e444e0e42..db5587b9d28 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftEventQueueTest { private static final int MAX_QUEUE_SIZE = 1000; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java index dbfc16da29e..72b15b58bcf 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class BftForksScheduleFactoryTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java index 6daadc0fd41..67e7cc283b9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.consensus.common.bft; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftHelpersTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java index da62a8f5cc5..5ff31b538bc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java @@ -31,17 +31,17 @@ import java.util.concurrent.TimeUnit; import org.awaitility.Awaitility; -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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class BftProcessorTest { private EventMultiplexer mockeEventMultiplexer; - @Before + @BeforeEach public void initialise() { mockeEventMultiplexer = mock(EventMultiplexer.class); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java index ec0783f6a3e..23026148114 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java @@ -37,14 +37,14 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -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.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class BlockTimerTest { private BftExecutors bftExecutors; @@ -52,7 +52,7 @@ public class BlockTimerTest { private Clock mockClock; private ForksSchedule mockForksSchedule; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void initialise() { bftExecutors = mock(BftExecutors.class); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java index 7d01ebe059e..62465a183d5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java @@ -27,12 +27,12 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; -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 EthSynchronizerUpdaterTest { @Mock private EthPeers ethPeers; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java index 72eb918c74a..68fce007271 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MessageTrackerTest { private final MessageTracker messageTracker = new MessageTracker(5); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java index 693074bdfb0..f8a061471db 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java @@ -28,20 +28,20 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -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.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class RoundTimerTest { private BftExecutors bftExecutors; private BftEventQueue queue; private RoundTimer timer; - @Before + @BeforeEach public void initialise() { bftExecutors = mock(BftExecutors.class); queue = new BftEventQueue(1000); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java index b6eb9a057fd..e363920078d 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SizeLimitedMapTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java index 70c18c52303..cbc731317e9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java @@ -31,11 +31,11 @@ import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class UniqueMessageMulticasterTest { private final MessageTracker messageTracker = mock(MessageTracker.class); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java index cb96b9d4f71..b01a3a97c6f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Address; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTest { @Test diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java index 5b1d7a3cf64..dda38b45af1 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.consensus.common.bft.blockcreation; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,13 +36,13 @@ import java.util.concurrent.TimeUnit; import org.apache.tuweni.bytes.Bytes; -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 BftMiningCoordinatorTest { @Mock private BftEventHandler controller; @Mock private BftExecutors bftExecutors; @@ -54,14 +55,14 @@ public class BftMiningCoordinatorTest { private final BftEventQueue eventQueue = new BftEventQueue(1000); private BftMiningCoordinator bftMiningCoordinator; - @Before + @BeforeEach public void setup() { bftMiningCoordinator = new BftMiningCoordinator( bftExecutors, controller, bftProcessor, bftBlockCreatorFactory, blockChain, eventQueue); - when(block.getBody()).thenReturn(blockBody); - when(block.getHeader()).thenReturn(blockHeader); - when(blockBody.getTransactions()).thenReturn(Collections.emptyList()); + lenient().when(block.getBody()).thenReturn(blockBody); + lenient().when(block.getHeader()).thenReturn(blockHeader); + lenient().when(blockBody.getTransactions()).thenReturn(Collections.emptyList()); } @Test diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java index 80737668027..ebe74b16988 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ProposerSelectorTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java index fcbea4954d8..e8d7ee79e98 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java @@ -30,7 +30,7 @@ import java.util.Optional; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftCoinbaseValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java index 453b28a601c..facc4ee2e3a 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java @@ -38,7 +38,7 @@ import java.util.stream.IntStream; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftCommitSealsValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java index 00b994295ca..690dc26f155 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java @@ -29,7 +29,7 @@ import java.util.Optional; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftValidatorsValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java index cd148f8787a..5b9252df567 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java @@ -27,7 +27,7 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftVanityDataValidationRuleTest { private final BftVanityDataValidationRule validationRule = new BftVanityDataValidationRule(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java index 38ad26c658b..3f8c9f24153 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java @@ -16,6 +16,7 @@ import static com.google.common.collect.Lists.newArrayList; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -37,13 +38,13 @@ import java.util.List; import org.apache.tuweni.bytes.Bytes; -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 ValidatorPeersTest { public static final String PROTOCOL_NAME = "BFT"; @@ -53,7 +54,7 @@ public class ValidatorPeersTest { private final List peerConnections = newArrayList(); @Mock ValidatorProvider validatorProvider; - @Before + @BeforeEach public void setup() { for (int i = 0; i < 4; i++) { final SECPPublicKey pubKey = @@ -71,8 +72,8 @@ public void setup() { private PeerConnection mockPeerConnection(final Address address) { final PeerInfo peerInfo = mock(PeerInfo.class); final PeerConnection peerConnection = mock(PeerConnection.class); - when(peerConnection.getPeerInfo()).thenReturn(peerInfo); - when(peerInfo.getAddress()).thenReturn(address); + lenient().when(peerConnection.getPeerInfo()).thenReturn(peerInfo); + lenient().when(peerInfo.getAddress()).thenReturn(address); return peerConnection; } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java index ab161c2c401..cc99cf805fc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java @@ -42,13 +42,13 @@ import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -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 BftQueryServiceImplTest { @Mock private Blockchain blockchain; @@ -66,7 +66,7 @@ public class BftQueryServiceImplTest { private BlockHeader blockHeader; - @Before + @BeforeEach public void setup() { final BlockHeaderTestFixture blockHeaderTestFixture = new BlockHeaderTestFixture(); blockHeaderTestFixture.number(1); // can't be genesis block (due to extradata serialisation) diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java index 1267d5794b6..b584c9a16b5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java @@ -30,15 +30,15 @@ import java.util.stream.IntStream; 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 FutureMessageBufferTest { private Message message; private FutureMessageBuffer futureMsgBuffer; private final PeerConnection peerConnection = MockPeerFactory.create(AddressHelpers.ofValue(9)); - @Before + @BeforeEach public void setup() { message = createMessage(10); futureMsgBuffer = new FutureMessageBuffer(5, 5, 0); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java index f1692201cec..d877223a8fd 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java @@ -26,7 +26,7 @@ import java.util.Map; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ForkingVoteTallyCacheTest extends VoteTallyCacheTestBase { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java index d486a41979a..6263bc960cc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java @@ -24,7 +24,7 @@ import java.util.Collections; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteProposerTest { private final Address localAddress = Address.fromHexString("0"); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java index c69f2bb7697..514e5b8ab37 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java @@ -35,7 +35,7 @@ import java.util.Optional; import com.google.common.util.concurrent.UncheckedExecutionException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class VoteTallyCacheTest extends VoteTallyCacheTestBase { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java index 1a3dba12b1d..00e22532e2f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java @@ -33,7 +33,7 @@ import org.apache.tuweni.bytes.Bytes; import org.assertj.core.util.Lists; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class VoteTallyCacheTestBase { @@ -55,7 +55,7 @@ protected Block createEmptyBlock(final long blockNumber, final Hash parentHash) protected final BlockInterface blockInterface = mock(BlockInterface.class); - @Before + @BeforeEach public void constructThreeBlockChain() { for (int i = 0; i < 3; i++) { validators.add(AddressHelpers.ofValue(i)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java index 96671716cae..9c8d1033cba 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.consensus.common.validator.VoteType; import org.hyperledger.besu.datatypes.Address; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTallyTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java index 6d7590edf9a..21039c84d85 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java @@ -37,7 +37,7 @@ import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTallyUpdaterTest {