From 1a3c792d631935467befff34f2d2358b579d16b2 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 1 Jun 2023 17:59:49 +1000 Subject: [PATCH 1/3] junit5 Signed-off-by: Sally MacFarlane --- consensus/qbft/build.gradle | 1 + .../qbft/MutableQbftConfigOptionsTest.java | 2 +- ...ockHeaderValidationRulesetFactoryTest.java | 2 +- .../qbft/QbftExtraDataCodecTest.java | 2 +- .../qbft/QbftProtocolScheduleTest.java | 2 +- .../PkiQbftBlockCreatorTest.java | 6 ++--- .../QbftBlockCreatorFactoryTest.java | 6 ++--- .../QbftValidatorsValidationRuleTest.java | 2 +- .../methods/QbftDiscardValidatorVoteTest.java | 6 ++--- .../methods/QbftGetSignerMetricsTest.java | 6 ++--- .../QbftGetValidatorsByBlockHashTest.java | 12 ++++----- .../QbftGetValidatorsByBlockNumberTest.java | 12 ++++----- .../methods/QbftProposeValidatorVoteTest.java | 6 ++--- .../qbft/messagewrappers/CommitTest.java | 2 +- .../qbft/messagewrappers/PrepareTest.java | 2 +- .../qbft/messagewrappers/ProposalTest.java | 2 +- .../qbft/messagewrappers/RoundChangeTest.java | 2 +- .../qbft/payload/QbftPayloadTest.java | 2 +- .../DefaultKeyStoreWrapperProviderTest.java | 8 +++--- ...lockCreationConfigurationProviderTest.java | 8 +++--- .../qbft/pki/PkiQbftBlockHashingTest.java | 6 ++--- .../qbft/pki/PkiQbftExtraDataCodecTest.java | 2 +- .../protocol/Istanbul100SubProtocolTest.java | 2 +- .../qbft/validation/CommitValidatorTest.java | 2 +- .../qbft/validation/PrepareValidatorTest.java | 2 +- .../ProposalPayloadValidatorTest.java | 12 ++++----- .../validation/ProposalValidatorTest.java | 14 +++++----- .../RoundChangeMessageValidatorTest.java | 12 ++++----- .../RoundChangePayloadValidatorTest.java | 2 +- .../ForkingValidatorProviderTest.java | 26 ++++++++++++------- .../QbftForksSchedulesFactoryTest.java | 2 +- .../TransactionValidatorProviderTest.java | 12 ++++----- .../ValidatorContractControllerTest.java | 6 ++--- .../ValidatorModeTransitionLoggerTest.java | 8 +++--- 34 files changed, 104 insertions(+), 95 deletions(-) diff --git a/consensus/qbft/build.gradle b/consensus/qbft/build.gradle index e2511ef3126..65b0ec41b57 100644 --- a/consensus/qbft/build.gradle +++ b/consensus/qbft/build.gradle @@ -68,6 +68,7 @@ dependencies { 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/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/MutableQbftConfigOptionsTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/MutableQbftConfigOptionsTest.java index 8bf61d96a11..d41996d11db 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/MutableQbftConfigOptionsTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/MutableQbftConfigOptionsTest.java @@ -26,7 +26,7 @@ import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MutableQbftConfigOptionsTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java index 8c310d9700d..8e7b1be6940 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java @@ -36,7 +36,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftBlockHeaderValidationRulesetFactoryTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftExtraDataCodecTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftExtraDataCodecTest.java index 7a7ca5ebee5..018f0f9113d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftExtraDataCodecTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftExtraDataCodecTest.java @@ -40,7 +40,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftExtraDataCodecTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java index e090b0e6501..bb91477f795 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java @@ -44,7 +44,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftProtocolScheduleTest { private final BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/PkiQbftBlockCreatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/PkiQbftBlockCreatorTest.java index a36da3758f1..32d55e7f22e 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/PkiQbftBlockCreatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/PkiQbftBlockCreatorTest.java @@ -42,8 +42,8 @@ import java.util.Collections; 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 PkiQbftBlockCreatorTest { @@ -54,7 +54,7 @@ public class PkiQbftBlockCreatorTest { private PkiQbftBlockCreator pkiQbftBlockCreator; private BlockHeaderTestFixture blockHeaderBuilder; - @Before + @BeforeEach public void before() { blockCreator = mock(BlockCreator.class); cmsCreator = mock(CmsCreator.class); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java index 372b7668a99..e9345606963 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java @@ -37,14 +37,14 @@ import java.util.Optional; 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 QbftBlockCreatorFactoryTest { private final QbftExtraDataCodec extraDataCodec = new QbftExtraDataCodec(); private QbftBlockCreatorFactory qbftBlockCreatorFactory; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void setUp() throws Exception { final MiningParameters miningParams = mock(MiningParameters.class); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java index 105e94af024..b225348f7f6 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java @@ -32,7 +32,7 @@ import java.util.Optional; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftValidatorsValidationRuleTest { private final BftExtraData bftExtraData = mock(BftExtraData.class); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java index c74f4132bfa..4e0c30dea7b 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java @@ -33,8 +33,8 @@ import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class QbftDiscardValidatorVoteTest { private final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); @@ -43,7 +43,7 @@ public class QbftDiscardValidatorVoteTest { private final String JSON_RPC_VERSION = "2.0"; private QbftDiscardValidatorVote method; - @Before + @BeforeEach public void setup() { method = new QbftDiscardValidatorVote(validatorProvider); when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java index 343f4f1adf8..d070ba47cc3 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java @@ -41,8 +41,8 @@ import java.util.Optional; import java.util.stream.LongStream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class QbftGetSignerMetricsTest { @@ -58,7 +58,7 @@ public class QbftGetSignerMetricsTest { private BlockchainQueries blockchainQueries; private BlockInterface blockInterface; - @Before + @BeforeEach public void setup() { validatorProvider = mock(ValidatorProvider.class); blockchainQueries = mock(BlockchainQueries.class); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHashTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHashTest.java index bfc81438871..0eb8eb823a1 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHashTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHashTest.java @@ -31,13 +31,13 @@ import java.util.Optional; import org.assertj.core.api.Assertions; -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 QbftGetValidatorsByBlockHashTest { private static final String ETH_METHOD = "qbft_getValidatorsByBlockHash"; @@ -51,7 +51,7 @@ public class QbftGetValidatorsByBlockHashTest { private QbftGetValidatorsByBlockHash method; - @Before + @BeforeEach public void setUp() { method = new QbftGetValidatorsByBlockHash(blockchain, validatorProvider); } diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java index 46b1697ac60..b2e1c2b3d4d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java @@ -30,13 +30,13 @@ import java.util.List; import java.util.Optional; -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 QbftGetValidatorsByBlockNumberTest { @Mock private BlockchainQueries blockchainQueries; @@ -46,7 +46,7 @@ public class QbftGetValidatorsByBlockNumberTest { private QbftGetValidatorsByBlockNumber method; - @Before + @BeforeEach public void setUp() { method = new QbftGetValidatorsByBlockNumber(blockchainQueries, validatorProvider); } diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java index f9b771584e4..b9f2f9c2660 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java @@ -33,8 +33,8 @@ import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class QbftProposeValidatorVoteTest { private final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); @@ -43,7 +43,7 @@ public class QbftProposeValidatorVoteTest { private final String JSON_RPC_VERSION = "2.0"; private QbftProposeValidatorVote method; - @Before + @BeforeEach public void setup() { method = new QbftProposeValidatorVote(validatorProvider); when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/CommitTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/CommitTest.java index 71fa8eb64dc..87d3a46abe5 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/CommitTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/CommitTest.java @@ -29,7 +29,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CommitTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/PrepareTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/PrepareTest.java index eb84a1ae669..0aed7ed554e 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/PrepareTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/PrepareTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Util; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PrepareTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java index 47f8eb2c120..46a079ef00a 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java @@ -39,7 +39,7 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ProposalTest { private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java index 33c6df8ff58..23de31417c6 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java @@ -38,7 +38,7 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RoundChangeTest { private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/payload/QbftPayloadTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/payload/QbftPayloadTest.java index 65612275b7a..820b0f976f9 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/payload/QbftPayloadTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/payload/QbftPayloadTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftPayloadTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/DefaultKeyStoreWrapperProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/DefaultKeyStoreWrapperProviderTest.java index e0289759970..f5c91305cda 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/DefaultKeyStoreWrapperProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/DefaultKeyStoreWrapperProviderTest.java @@ -28,13 +28,13 @@ import java.nio.file.Path; -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.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DefaultKeyStoreWrapperProviderTest { @Mock private HardwareKeyStoreWrapperProvider hardwareKeyStoreWrapperProvider; diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiBlockCreationConfigurationProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiBlockCreationConfigurationProviderTest.java index c740d2825e0..27ccfe1bcfe 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiBlockCreationConfigurationProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiBlockCreationConfigurationProviderTest.java @@ -28,12 +28,12 @@ import java.nio.file.Path; -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 PkiBlockCreationConfigurationProviderTest { @Mock KeyStoreWrapperProvider keyStoreWrapperProvider; diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftBlockHashingTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftBlockHashingTest.java index 5780ca573d3..45ec1a780df 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftBlockHashingTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftBlockHashingTest.java @@ -32,15 +32,15 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; 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 PkiQbftBlockHashingTest { private PkiQbftExtraDataCodec pkiExtraDataCodec = new PkiQbftExtraDataCodec(); private PkiQbftBlockHashing pkiQbftBlockHashing; - @Before + @BeforeEach public void before() { pkiExtraDataCodec = spy(new PkiQbftExtraDataCodec()); pkiQbftBlockHashing = new PkiQbftBlockHashing(pkiExtraDataCodec); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftExtraDataCodecTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftExtraDataCodecTest.java index e344bdf36cc..32fc034b8e8 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftExtraDataCodecTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftExtraDataCodecTest.java @@ -35,7 +35,7 @@ import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PkiQbftExtraDataCodecTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/protocol/Istanbul100SubProtocolTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/protocol/Istanbul100SubProtocolTest.java index b600cdc4ef0..f3de01b77e9 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/protocol/Istanbul100SubProtocolTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/protocol/Istanbul100SubProtocolTest.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 Istanbul100SubProtocolTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/CommitValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/CommitValidatorTest.java index fb2a1d3095d..02ca653f2a3 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/CommitValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/CommitValidatorTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.datatypes.Hash; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CommitValidatorTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/PrepareValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/PrepareValidatorTest.java index 6a2d49af22a..b6c63b5598b 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/PrepareValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/PrepareValidatorTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare; import org.hyperledger.besu.datatypes.Hash; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PrepareValidatorTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java index 5e117cc6cf3..f2359019bdf 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java @@ -54,13 +54,13 @@ import java.util.Optional; 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 ProposalPayloadValidatorTest { @Mock private BlockValidator blockValidator; @@ -80,7 +80,7 @@ public class ProposalPayloadValidatorTest { ConsensusRoundHelpers.createFrom(targetRound, 1, 0); final QbftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); - @Before + @BeforeEach public void setup() { protocolContext = new ProtocolContext( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java index e173208e7f2..e63b59bb0fe 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java @@ -21,6 +21,7 @@ import static org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparePayloads; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; import org.hyperledger.besu.consensus.common.bft.BftHelpers; @@ -50,13 +51,13 @@ import java.util.Map; import java.util.Optional; -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 ProposalValidatorTest { private enum ROUND_ID { @@ -90,7 +91,7 @@ public RoundSpecificItems( private final Map roundItems = new HashMap<>(); final QbftExtraDataCodec bftExtraDataEncoder = new QbftExtraDataCodec(); - @Before + @BeforeEach public void setup() { protocolContext = new ProtocolContext( @@ -152,6 +153,7 @@ public void validationFailsIfBlockIsInvalid() { final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ZERO); final Proposal proposal = createProposal(roundItem, emptyList(), emptyList()); + reset(blockValidator); when(blockValidator.validateAndProcessBlock( eq(protocolContext), any(), diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java index fe000758a40..2777f24b670 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java @@ -49,13 +49,13 @@ import java.util.Optional; import java.util.stream.Collectors; -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 RoundChangeMessageValidatorTest { @Mock private RoundChangePayloadValidator payloadValidator; @@ -74,7 +74,7 @@ public class RoundChangeMessageValidatorTest { ConsensusRoundHelpers.createFrom(targetRound, 0, -1); private final QbftExtraDataCodec bftExtraDataEncoder = new QbftExtraDataCodec(); - @Before + @BeforeEach public void setup() { protocolContext = new ProtocolContext( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangePayloadValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangePayloadValidatorTest.java index ae403fe0f5f..f4a91024b4a 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangePayloadValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangePayloadValidatorTest.java @@ -27,7 +27,7 @@ import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RoundChangePayloadValidatorTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java index d44af1b6151..023e195e350 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java @@ -43,14 +43,14 @@ import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.SoftAssertions; -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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ForkingValidatorProviderTest { private static final Address CONTRACT_ADDRESS_1 = Address.fromHexString("0x888"); @@ -71,7 +71,7 @@ public class ForkingValidatorProviderTest { private BlockHeader header2; private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); - @Before + @BeforeEach public void setup() { headerBuilder.extraData(Bytes.wrap(new byte[32])); Block genesisBlock = createEmptyBlock(0, Hash.ZERO); @@ -84,10 +84,6 @@ public void setup() { blockChain = createInMemoryBlockchain(genesisBlock); blockChain.appendBlock(block_1, emptyList()); blockChain.appendBlock(block_2, emptyList()); - - when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES); - when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1); - when(contractValidatorProvider.getValidatorsForBlock(header2)).thenReturn(CONTRACT_ADDRESSES_2); } private Block createEmptyBlock(final long blockNumber, final Hash parentHash) { @@ -106,6 +102,7 @@ public void usesInitialValidatorProviderWhenNoForks() { when(blockValidatorProvider.getValidatorsAfterBlock(header2)).thenReturn(BLOCK_ADDRESSES); when(blockValidatorProvider.getValidatorsAfterBlock(header1)).thenReturn(BLOCK_ADDRESSES); + when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES); assertThat(validatorProvider.getValidatorsAtHead()).isEqualTo(BLOCK_ADDRESSES); assertThat(validatorProvider.getValidatorsForBlock(header1)).isEqualTo(BLOCK_ADDRESSES); @@ -114,6 +111,9 @@ public void usesInitialValidatorProviderWhenNoForks() { @Test public void migratesFromBlockToContractValidatorProvider() { + when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES); + when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1); + final ForksSchedule forksSchedule = new ForksSchedule<>( List.of(createBlockForkSpec(0), createContractForkSpec(1L, CONTRACT_ADDRESS_1))); @@ -127,6 +127,8 @@ public void migratesFromBlockToContractValidatorProvider() { @Test public void migratesFromContractToBlockValidatorProvider() { + when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES); + final ForksSchedule forksSchedule = new ForksSchedule<>( List.of(createContractForkSpec(0, CONTRACT_ADDRESS_1), createBlockForkSpec(1))); @@ -145,6 +147,10 @@ public void migratesFromContractToBlockValidatorProvider() { @Test public void migratesFromContractToContractValidatorProvider() { + when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES); + when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1); + when(contractValidatorProvider.getValidatorsForBlock(header2)).thenReturn(CONTRACT_ADDRESSES_2); + final ForksSchedule forksSchedule = new ForksSchedule<>( List.of( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/QbftForksSchedulesFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/QbftForksSchedulesFactoryTest.java index 9b0927bc79a..abb75426d0a 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/QbftForksSchedulesFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/QbftForksSchedulesFactoryTest.java @@ -44,7 +44,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class QbftForksSchedulesFactoryTest extends BaseForksSchedulesFactoryTest { diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java index 8844cd6d90e..516566417f6 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java @@ -39,13 +39,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 TransactionValidatorProviderTest { @Mock private ValidatorContractController validatorContractController; @@ -59,7 +59,7 @@ public class TransactionValidatorProviderTest { private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); private static final Address CONTRACT_ADDRESS = Address.fromHexString("1"); - @Before + @BeforeEach public void setup() { forksSchedule = new ForksSchedule<>(List.of(createContractForkSpec(0L, CONTRACT_ADDRESS))); genesisBlock = createEmptyBlock(0, Hash.ZERO); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java index 4702a4eee84..6f4adf3a286 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java @@ -38,8 +38,8 @@ import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.web3j.abi.FunctionEncoder; import org.web3j.abi.TypeReference; @@ -64,7 +64,7 @@ public class ValidatorContractControllerTest { private final Transaction transaction = Mockito.mock(Transaction.class); private CallParameter callParameter; - @Before + @BeforeEach public void setup() { final Function getValidatorsFunction = new Function( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorModeTransitionLoggerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorModeTransitionLoggerTest.java index c7c854e7b98..d6219c6e754 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorModeTransitionLoggerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorModeTransitionLoggerTest.java @@ -32,13 +32,13 @@ import java.util.Optional; import java.util.function.Consumer; -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.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ValidatorModeTransitionLoggerTest { @Mock private ForksSchedule forksSchedule; From abf64636b8b7d374de756b1b5cad2f9482105c6c Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 1 Jun 2023 18:00:05 +1000 Subject: [PATCH 2/3] lenient mocking Signed-off-by: Sally MacFarlane --- .../QbftBlockHeightManagerTest.java | 15 +++++++++------ .../qbft/statemachine/QbftControllerTest.java | 17 ++++++++++------- .../qbft/statemachine/QbftRoundTest.java | 15 +++++++++------ .../qbft/statemachine/RoundStateTest.java | 12 ++++++------ 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java index daf083c8fbe..da260140bff 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java @@ -78,15 +78,18 @@ import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; -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.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class QbftBlockHeightManagerTest { private final NodeKey nodeKey = NodeKeyUtils.generate(); @@ -126,7 +129,7 @@ private void buildCreatedBlock() { createdBlock = new Block(header, new BlockBody(emptyList(), emptyList())); } - @Before + @BeforeEach public void setup() { for (int i = 0; i < 3; i++) { final NodeKey nodeKey = NodeKeyUtils.generate(); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java index 4ea2dd843a8..3e3a38af824 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java @@ -57,13 +57,16 @@ import java.util.List; import com.google.common.collect.ImmutableList; -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; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class QbftControllerTest { private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec(); @@ -100,7 +103,7 @@ public class QbftControllerTest { @Mock private FutureMessageBuffer futureMessageBuffer; private QbftController qbftController; - @Before + @BeforeEach public void setup() { when(blockChain.getChainHeadHeader()).thenReturn(chainHeadBlockHeader); when(blockChain.getChainHeadBlockNumber()).thenReturn(3L); @@ -111,7 +114,7 @@ public void setup() { when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO); when(blockHeightManager.getParentBlockHeader()).thenReturn(chainHeadBlockHeader); - when(blockHeightManager.getChainHeight()).thenReturn(4L); // one great than blockchain + when(blockHeightManager.getChainHeight()).thenReturn(4L); // one greater than blockchain when(nextBlock.getNumber()).thenReturn(5L); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java index 3459e9110c9..e3f58d5a7b6 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java @@ -69,15 +69,18 @@ import java.util.Optional; 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.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class QbftRoundTest { private final NodeKey nodeKey = NodeKeyUtils.generate(); @@ -107,7 +110,7 @@ public class QbftRoundTest { SignatureAlgorithmFactory.getInstance() .createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 1); - @Before + @BeforeEach public void setup() { protocolContext = new ProtocolContext( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/RoundStateTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/RoundStateTest.java index 26205adf59f..ff76a19b8ad 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/RoundStateTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/RoundStateTest.java @@ -47,13 +47,13 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.Lists; -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 RoundStateTest { private static final Supplier SIGNATURE_ALGORITHM = @@ -70,7 +70,7 @@ public class RoundStateTest { @Mock private Block block; - @Before + @BeforeEach public void setup() { for (int i = 0; i < 3; i++) { final NodeKey newNodeKey = NodeKeyUtils.generate(); From 6c7060ee5534cda935e8ca570a20d14fc61f2982 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 1 Jun 2023 18:09:11 +1000 Subject: [PATCH 3/3] remove junit4 Signed-off-by: Sally MacFarlane --- consensus/qbft/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/consensus/qbft/build.gradle b/consensus/qbft/build.gradle index 65b0ec41b57..90e9a45deed 100644 --- a/consensus/qbft/build.gradle +++ b/consensus/qbft/build.gradle @@ -63,7 +63,6 @@ dependencies { testImplementation project(':metrics:core') testImplementation project(':testutil') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter'