junit 5 ftw (#6253)

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/6255/head
Sally MacFarlane 12 months ago committed by GitHub
parent 4cc2eed4e6
commit b6e73ae080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      consensus/common/build.gradle
  2. 8
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java
  3. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java
  4. 16
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java
  5. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java
  6. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java
  7. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java
  8. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java
  9. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java
  10. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java
  11. 12
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java
  12. 12
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java
  13. 8
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java
  14. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java
  15. 12
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java
  16. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java
  17. 8
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java
  18. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java
  19. 19
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java
  20. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java
  21. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java
  22. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java
  23. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java
  24. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java
  25. 17
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java
  26. 12
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java
  27. 6
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java
  28. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java
  29. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java
  30. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java
  31. 4
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java
  32. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java
  33. 2
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java

@ -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'

@ -35,11 +35,11 @@ import java.util.TreeSet;
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 =

@ -24,7 +24,7 @@ import org.hyperledger.besu.datatypes.Address;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ForksScheduleTest {

@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.common;
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.List;
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<MiningCoordinator> 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 class MigratingMiningCoordinatorTest {
@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);

@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
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 {

@ -42,7 +42,7 @@ import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class BaseBftProtocolScheduleBuilderTest {

@ -30,7 +30,7 @@ import java.util.Optional;
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> {

@ -24,7 +24,7 @@ import java.util.ArrayList;
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;

@ -29,7 +29,7 @@ import org.hyperledger.besu.consensus.common.bft.BftForksScheduleFactory.BftSpec
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 {

@ -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 {

@ -31,17 +31,17 @@ import java.util.concurrent.Future;
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);
}

@ -37,14 +37,14 @@ import java.time.Clock;
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<BftConfigOptions> mockForksSchedule;
@Before
@BeforeEach
@SuppressWarnings("unchecked")
public void initialise() {
bftExecutors = mock(BftExecutors.class);

@ -27,12 +27,12 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
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;

@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
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);

@ -28,20 +28,20 @@ import org.hyperledger.besu.consensus.common.bft.events.RoundExpiry;
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);

@ -16,7 +16,7 @@ package org.hyperledger.besu.consensus.common.bft;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class SizeLimitedMapTest {

@ -31,11 +31,11 @@ import java.util.List;
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);

@ -18,7 +18,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
import org.hyperledger.besu.datatypes.Address;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class VoteTest {
@Test

@ -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.Collections;
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

@ -35,7 +35,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ProposerSelectorTest {

@ -30,7 +30,7 @@ import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class BftCoinbaseValidationRuleTest {

@ -38,7 +38,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class BftCommitSealsValidationRuleTest {

@ -29,7 +29,7 @@ import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class BftValidatorsValidationRuleTest {

@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
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();

@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.common.bft.network;
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.math.BigInteger;
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<PeerConnection> 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 class ValidatorPeersTest {
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;
}

@ -42,13 +42,13 @@ import java.util.stream.Collectors;
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)

@ -30,15 +30,15 @@ import java.util.stream.Collectors;
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);

@ -26,7 +26,7 @@ import java.util.List;
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 {

@ -24,7 +24,7 @@ import java.util.Arrays;
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");

@ -35,7 +35,7 @@ import java.util.Arrays;
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 {

@ -33,7 +33,7 @@ import java.util.List;
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 @@ public class VoteTallyCacheTestBase {
protected final BlockInterface blockInterface = mock(BlockInterface.class);
@Before
@BeforeEach
public void constructThreeBlockChain() {
for (int i = 0; i < 3; i++) {
validators.add(AddressHelpers.ofValue(i));

@ -22,7 +22,7 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorVote;
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 {

@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class VoteTallyUpdaterTest {

Loading…
Cancel
Save