Skip to content

Commit

Permalink
change junit 4 to 5 in others files
Browse files Browse the repository at this point in the history
Signed-off-by: 0xBlockPay <0xblockpay@gmail.com>
  • Loading branch information
0xBlockPay committed Jul 17, 2023
1 parent 391ec5c commit 5fe0372
Show file tree
Hide file tree
Showing 40 changed files with 807 additions and 750 deletions.
4 changes: 3 additions & 1 deletion besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ dependencies {
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'
implementation 'tech.pegasys:jc-kzg-4844'
testImplementation 'org.testng:testng:7.1.0'
testImplementation 'org.testng:testng:7.1.0'

runtimeOnly 'org.apache.logging.log4j:log4j-jul'
runtimeOnly 'org.apache.logging.log4j:log4j-jul'
runtimeOnly 'com.splunk.logging:splunk-library-javalogging'
runtimeOnly 'org.fusesource.jansi:jansi' // for color logging in windows

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

//TODO find something for Enclosed
@RunWith(Enclosed.class)
public class ForkIdsNetworkConfigTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,25 @@
import java.nio.file.Path;
import java.util.Optional;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeAll;
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 BlockExporter}. */
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class RlpBlockExporterTest {

@ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
@TempDir public static Path folder;
private static Blockchain blockchain;
private static long chainHead;
private static ProtocolSchedule protocolSchedule;

@BeforeClass
@BeforeAll
public static void setupBlockchain() throws IOException {
final BesuController controller = createController();
final Path blocks = folder.newFile("1000.blocks").toPath();
final Path blocks = folder.resolve("1000.blocks");
BlockTestUtil.write1000Blocks(blocks);
blockchain = importBlocks(controller, blocks);
chainHead = blockchain.getChainHeadBlockNumber();
Expand All @@ -84,7 +83,7 @@ private static Blockchain importBlocks(final BesuController controller, final Pa
}

private static BesuController createController() throws IOException {
final Path dataDir = folder.newFolder().toPath();
final Path dataDir = folder;
return new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet(), SyncMode.FAST)
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
Expand All @@ -106,7 +105,7 @@ private static BesuController createController() throws IOException {

@Test
public void exportBlocks_noBounds() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);
exporter.exportBlocks(outputPath, Optional.empty(), Optional.empty());

Expand All @@ -126,7 +125,7 @@ public void exportBlocks_noBounds() throws IOException {

@Test
public void exportBlocks_withLowerBound() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = 990;
Expand All @@ -148,7 +147,7 @@ public void exportBlocks_withLowerBound() throws IOException {

@Test
public void exportBlocks_withUpperBound() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long upperBound = 10;
Expand All @@ -170,7 +169,7 @@ public void exportBlocks_withUpperBound() throws IOException {

@Test
public void exportBlocks_withUpperAndLowerBounds() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = 5;
Expand All @@ -193,7 +192,7 @@ public void exportBlocks_withUpperAndLowerBounds() throws IOException {

@Test
public void exportBlocks_withRangeBeyondChainHead() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = chainHead - 10;
Expand All @@ -216,7 +215,7 @@ public void exportBlocks_withRangeBeyondChainHead() throws IOException {

@Test
public void exportBlocks_negativeStartNumber() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(-1L), Optional.empty()))
Expand All @@ -226,7 +225,7 @@ public void exportBlocks_negativeStartNumber() throws IOException {

@Test
public void exportBlocks_negativeEndNumber() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.empty(), Optional.of(-1L)))
Expand All @@ -236,7 +235,7 @@ public void exportBlocks_negativeEndNumber() throws IOException {

@Test
public void exportBlocks_outOfOrderBounds() throws IOException {
final File outputPath = folder.newFile();
final File outputPath = folder.toFile();
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(10L), Optional.of(2L)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.io.Resources;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public abstract class JsonBlockImporterTest {

@Rule public final TemporaryFolder folder = new TemporaryFolder();
@TempDir
Path dataDir;
private final RlpBlockImporter rlpBlockImporter = new RlpBlockImporter();

protected final String consensusEngine;
protected final GenesisConfigFile genesisConfigFile;
Expand Down Expand Up @@ -96,14 +95,14 @@ public void importChain_unsupportedConsensusAlgorithm() throws IOException {
}
}

@RunWith(Parameterized.class)
public static class ParameterizedTests extends JsonBlockImporterTest {

public ParameterizedTests(final String consensusEngine) throws IOException {
super(consensusEngine);
}

@Parameters(name = "Name: {0}")
@ParameterizedTest
@ValueSource(strings = {"Name: {0}"})
public static Collection<Object[]> getParameters() {
final Object[][] params = {{"ethash"}, {"clique"}};
return Arrays.asList(params);
Expand Down Expand Up @@ -413,7 +412,6 @@ protected BesuController createController() throws IOException {

protected BesuController createController(final GenesisConfigFile genesisConfigFile)
throws IOException {
final Path dataDir = folder.newFolder().toPath();
return new BesuController.Builder()
.fromGenesisConfig(genesisConfigFile, SyncMode.FAST)
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
Expand Down
43 changes: 21 additions & 22 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.toml.Toml;
import org.apache.tuweni.toml.TomlParseResult;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class BesuCommandTest extends CommandTestAbstract {

private static final String ENCLAVE_URI = "http://1.2.3.4:5555";
Expand Down Expand Up @@ -211,12 +211,12 @@ public class BesuCommandTest extends CommandTestAbstract {
DEFAULT_METRICS_CONFIGURATION = MetricsConfiguration.builder().build();
}

@Before
@BeforeEach
public void setup() {
MergeConfigOptions.setMergeEnabled(false);
}

@After
@AfterEach
public void tearDown() {
MergeConfigOptions.setMergeEnabled(false);
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public void callingWithConfigOptionButInvalidValueTomlFileShouldDisplayHelp() th
public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException {
final URL configFile = this.getClass().getResource("/complete_config.toml");
final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON);
final File dataFolder = temp.newFolder();
final File dataFolder = temp.toFile();
final String updatedConfig =
Resources.toString(configFile, UTF_8)
.replace("/opt/besu/genesis.json", escapeTomlString(genesisFile.toString()))
Expand Down Expand Up @@ -3916,7 +3916,7 @@ public void colorCanBeEnabledOrDisabledExplicitly() {
});
}

@Ignore
@Disabled("")
public void pruningIsEnabledIfSyncModeIsFast() {
parseCommand("--sync-mode", "FAST");

Expand All @@ -3927,7 +3927,7 @@ public void pruningIsEnabledIfSyncModeIsFast() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Ignore
@Disabled("")
public void pruningIsDisabledIfSyncModeIsFull() {
parseCommand("--sync-mode", "FULL");

Expand All @@ -3949,7 +3949,7 @@ public void pruningEnabledExplicitly() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Ignore
@Disabled("")
public void pruningDisabledExplicitly() {
parseCommand("--pruning-enabled=false", "--sync-mode=FAST");

Expand Down Expand Up @@ -4568,13 +4568,13 @@ public void privacyWithGoQuorumModeMustError() throws IOException {
.contains("GoQuorum privacy is no longer supported in Besu");
}

@Rule public TemporaryFolder testFolder = new TemporaryFolder();
@TempDir public Path testFolder;

@Test
public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException {
final File staticNodesFile = testFolder.newFile("static-nodes.json");
final File staticNodesFile = testFolder.resolve("static-nodes.json").toFile();
staticNodesFile.deleteOnExit();
final File permissioningConfig = testFolder.newFile("permissioning");
final File permissioningConfig = testFolder.resolve("permissioning").toFile();
permissioningConfig.deleteOnExit();

final EnodeURL staticNodeURI =
Expand All @@ -4601,7 +4601,7 @@ public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException {
("nodes-allowlist=[\"" + allowedNode.toString() + "\"]").getBytes(UTF_8));

parseCommand(
"--data-path=" + testFolder.getRoot().getPath(),
"--data-path=" + testFolder.getRoot(),
"--bootnodes",
"--permissions-nodes-config-file-enabled=true",
"--permissions-nodes-config-file=" + permissioningConfig.getPath());
Expand Down Expand Up @@ -5442,12 +5442,11 @@ public void pkiBlockCreationPasswordFileRequired() {
"File containing password to unlock keystore is required when PKI Block Creation is enabled");
}

@Rule public TemporaryFolder pkiTempFolder = new TemporaryFolder();

@TempDir public Path pkiTempFolder;
@Test
public void pkiBlockCreationFullConfig() throws Exception {
// Create temp file with password
final File pwdFile = pkiTempFolder.newFile("pwd");
final File pwdFile = pkiTempFolder.resolve("pwd").toFile();
FileUtils.writeStringToFile(pwdFile, "foo", UTF_8);

parseCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
import java.util.List;
import java.util.Map;

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.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.RunLast;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class CommandLineUtilsTest {
@SuppressWarnings("PrivateStaticFinalLoggers") // @Mocks are inited by JUnit
@Mock
Expand Down
Loading

0 comments on commit 5fe0372

Please sign in to comment.