Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consensus/common migrate to junit 5 #6253

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@
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;
private BftEventQueue mockQueue;
private Clock mockClock;
private ForksSchedule<BftConfigOptions> mockForksSchedule;

@Before
@BeforeEach
@SuppressWarnings("unchecked")
public void initialise() {
bftExecutors = mock(BftExecutors.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.hyperledger.besu.datatypes.Address;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class VoteTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading
Loading