[MINOR] junit5 (#5356)

* migrate to junit5

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5374/head
Sally MacFarlane 2 years ago committed by GitHub
parent f8a7d87ea3
commit 681f4a5116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      besu/src/test/java/org/hyperledger/besu/BesuInfoTest.java
  2. 54
      besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
  3. 28
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java

@ -18,11 +18,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Optional;
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 final class BesuInfoTest {
/**

@ -72,6 +72,7 @@ import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Collections;
import io.vertx.core.Vertx;
@ -79,18 +80,17 @@ import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;
import org.ethereum.beacon.discovery.schema.NodeRecord;
import org.ethereum.beacon.discovery.schema.NodeRecordFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
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.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class RunnerBuilderTest {
@Rule public TemporaryFolder dataDir = new TemporaryFolder();
@TempDir private Path dataDir;
@Mock BesuController besuController;
@Mock ProtocolSchedule protocolSchedule;
@ -99,7 +99,7 @@ public final class RunnerBuilderTest {
@Mock Vertx vertx;
private NodeKey nodeKey;
@Before
@BeforeEach
public void setup() {
final SubProtocolConfiguration subProtocolConfiguration = mock(SubProtocolConfiguration.class);
final EthProtocolManager ethProtocolManager = mock(EthProtocolManager.class);
@ -118,11 +118,7 @@ public final class RunnerBuilderTest {
when(ethProtocolManager.ethContext()).thenReturn(ethContext);
when(subProtocolConfiguration.getSubProtocols())
.thenReturn(Collections.singletonList(new IbftSubProtocol()));
final DefaultBlockchain blockchain = mock(DefaultBlockchain.class);
when(protocolContext.getBlockchain()).thenReturn(blockchain);
final Block block = mock(Block.class);
when(blockchain.getGenesisBlock()).thenReturn(block);
when(block.getHash()).thenReturn(Hash.ZERO);
when(protocolContext.getWorldStateArchive()).thenReturn(worldstateArchive);
when(besuController.getProtocolManager()).thenReturn(ethProtocolManager);
when(besuController.getSubProtocolConfiguration()).thenReturn(subProtocolConfiguration);
@ -144,6 +140,8 @@ public final class RunnerBuilderTest {
@Test
public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() {
setupBlockchainAndBlock();
final String p2pAdvertisedHost = "172.0.0.1";
final int p2pListenPort = 30302;
@ -164,7 +162,7 @@ public final class RunnerBuilderTest {
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(vertx)
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class))
.rpcEndpointService(new RpcEndpointServiceImpl())
.build();
@ -208,7 +206,7 @@ public final class RunnerBuilderTest {
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(storageProvider)
.rpcEndpointService(new RpcEndpointServiceImpl())
.build();
@ -236,6 +234,8 @@ public final class RunnerBuilderTest {
@Test
public void whenEngineApiAddedListensOnDefaultPort() {
setupBlockchainAndBlock();
final JsonRpcConfiguration jrpc = JsonRpcConfiguration.createDefault();
jrpc.setEnabled(true);
final JsonRpcConfiguration engine = JsonRpcConfiguration.createEngineDefault();
@ -264,7 +264,7 @@ public final class RunnerBuilderTest {
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
@ -276,6 +276,8 @@ public final class RunnerBuilderTest {
@Test
public void whenEngineApiAddedWebSocketReadyOnSamePort() {
setupBlockchainAndBlock();
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault();
wsRpc.setEnabled(true);
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
@ -304,7 +306,7 @@ public final class RunnerBuilderTest {
.graphQLConfiguration(mock(GraphQLConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
@ -315,6 +317,8 @@ public final class RunnerBuilderTest {
@Test
public void whenEngineApiAddedEthSubscribeAvailable() {
setupBlockchainAndBlock();
final WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault();
wsRpc.setEnabled(true);
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
@ -343,7 +347,7 @@ public final class RunnerBuilderTest {
.graphQLConfiguration(mock(GraphQLConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
@ -357,6 +361,8 @@ public final class RunnerBuilderTest {
@Test
public void noEngineApiNoServiceForMethods() {
setupBlockchainAndBlock();
final JsonRpcConfiguration defaultRpcConfig = JsonRpcConfiguration.createDefault();
defaultRpcConfig.setEnabled(true);
final WebSocketConfiguration defaultWebSockConfig = WebSocketConfiguration.createDefault();
@ -383,7 +389,7 @@ public final class RunnerBuilderTest {
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
@ -393,4 +399,12 @@ public final class RunnerBuilderTest {
assertThat(runner.getJsonRpcPort()).isPresent();
assertThat(runner.getEngineJsonRpcPort()).isEmpty();
}
private void setupBlockchainAndBlock() {
final DefaultBlockchain blockchain = mock(DefaultBlockchain.class);
when(protocolContext.getBlockchain()).thenReturn(blockchain);
final Block block = mock(Block.class);
when(blockchain.getGenesisBlock()).thenReturn(block);
when(block.getHash()).thenReturn(Hash.ZERO);
}
}

@ -73,6 +73,7 @@ import org.hyperledger.besu.testutil.TestClock;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
@ -96,32 +97,31 @@ import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.tuweni.units.bigints.UInt256;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.junit.jupiter.MockitoExtension;
/** Tests for {@link Runner}. */
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class RunnerTest {
public static final BigInteger NETWORK_ID = BigInteger.valueOf(2929);
private Vertx vertx;
@Before
@BeforeEach
public void initVertx() {
vertx = Vertx.vertx();
}
@After
@AfterEach
public void stopVertx() {
vertx.close();
}
@Rule public final TemporaryFolder temp = new TemporaryFolder();
@TempDir private static Path temp;
@Test
public void getFixedNodes() {
@ -159,7 +159,7 @@ public final class RunnerTest {
private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesisConfig)
throws Exception {
final Path dataDirAhead = temp.newFolder().toPath();
final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead");
final Path dbAhead = dataDirAhead.resolve("database");
final int blockCount = 500;
final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dbAhead));
@ -181,7 +181,7 @@ public final class RunnerTest {
blockCount, controllerAhead.getProtocolSchedule(), controllerAhead.getProtocolContext());
final String listenHost = InetAddress.getLoopbackAddress().getHostAddress();
final Path pidPath = temp.getRoot().toPath().resolve("pid");
final Path pidPath = dataDirAhead.resolve("pid");
final RunnerBuilder runnerBuilder =
new RunnerBuilder()
.vertx(vertx)
@ -220,7 +220,7 @@ public final class RunnerTest {
.fastSyncPivotDistance(5)
.fastSyncMinimumPeerCount(1)
.build();
final Path dataDirBehind = temp.newFolder().toPath();
final Path dataDirBehind = Files.createTempDirectory(temp, "db-behind");
// Setup runner with no block data
final BesuController controllerBehind =

Loading…
Cancel
Save