From 9aaaf79c594480d0acc8d26de4558cb1cc3fc705 Mon Sep 17 00:00:00 2001 From: delehef Date: Wed, 6 Dec 2023 13:06:17 +0100 Subject: [PATCH 1/5] fix: double calls to trace{Start,End}Transaction (#6247) Signed-off-by: delehef --- .../hyperledger/besu/services/TraceServiceImpl.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java index 98c233197f3..02fff10d2fb 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java @@ -212,7 +212,6 @@ private List trace( .orElse(BlobGas.ZERO)); final WorldUpdater worldUpdater = chainUpdater.getNextUpdater(); - tracer.traceStartTransaction(worldUpdater, transaction); final TransactionProcessingResult result = transactionProcessor.processTransaction( blockchain, @@ -225,16 +224,6 @@ private List trace( false, blobGasPrice); - long transactionGasUsed = transaction.getGasLimit() - result.getGasRemaining(); - tracer.traceEndTransaction( - worldUpdater, - transaction, - result.isSuccessful(), - result.getOutput(), - result.getLogs(), - transactionGasUsed, - 0); - results.add(result); }); From c4fce130208cf413bab8811b91289d921019acda Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 07:43:22 +1000 Subject: [PATCH 2/5] migrate to junit5 (#6234) Signed-off-by: Sally MacFarlane --- crypto/algorithms/build.gradle | 1 - .../org/hyperledger/besu/crypto/ECPointUtilTest.java | 2 +- .../java/org/hyperledger/besu/crypto/HashTest.java | 2 +- .../java/org/hyperledger/besu/crypto/KeyPairTest.java | 6 +++--- .../org/hyperledger/besu/crypto/KeyPairUtilTest.java | 2 +- .../org/hyperledger/besu/crypto/SECP256K1Test.java | 10 +++++----- .../org/hyperledger/besu/crypto/SECP256R1Test.java | 10 +++++----- .../hyperledger/besu/crypto/SECPPrivateKeyTest.java | 6 +++--- .../org/hyperledger/besu/crypto/SECPPublicKeyTest.java | 6 +++--- .../org/hyperledger/besu/crypto/SECPSignatureTest.java | 6 +++--- .../besu/crypto/SignatureAlgorithmFactoryTest.java | 6 +++--- .../besu/crypto/SignatureAlgorithmTypeTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq12PairerTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq12PointTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq2PointTest.java | 2 +- .../besu/crypto/altbn128/AltBn128PointTest.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/Fq12Test.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/Fq2Test.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/FqTest.java | 2 +- 19 files changed, 36 insertions(+), 37 deletions(-) diff --git a/crypto/algorithms/build.gradle b/crypto/algorithms/build.gradle index dcddb83be34..190ecae4a21 100644 --- a/crypto/algorithms/build.gradle +++ b/crypto/algorithms/build.gradle @@ -40,7 +40,6 @@ dependencies { implementation 'org.hyperledger.besu:blake2bf' implementation 'com.google.guava:guava' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java index ac95635ef1e..ff802516575 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java @@ -20,7 +20,7 @@ import java.security.spec.ECPoint; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ECPointUtilTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java index a2d8318e120..bc71c0c1530 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java @@ -19,7 +19,7 @@ import org.apache.tuweni.bytes.Bytes; import org.bouncycastle.util.encoders.Hex; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HashTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java index a8c1ac7e8f0..4155d2c5a4d 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java @@ -28,8 +28,8 @@ import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class KeyPairTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -39,7 +39,7 @@ public class KeyPairTest { public static KeyPairGenerator keyPairGenerator; public static ECDomainParameters curve; - @BeforeClass + @BeforeAll public static void setUp() { Security.addProvider(new BouncyCastleProvider()); diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java index 13c78d52bdc..cc2bcb0f460 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java @@ -19,7 +19,7 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class KeyPairUtilTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java index 060bdad844b..28fb0fb4f1c 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java @@ -28,9 +28,9 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256K1Test { @@ -39,7 +39,7 @@ public class SECP256K1Test { protected static String suiteStartTime = null; protected static String suiteName = null; - @BeforeClass + @BeforeAll public static void setTestSuiteStartTime() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) @@ -47,7 +47,7 @@ public static void setTestSuiteStartTime() { suiteName(SECP256K1Test.class); } - @Before + @BeforeEach public void setUp() { secp256K1 = new SECP256K1(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java index bd791ef9be3..26e03e5bd3c 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java @@ -29,9 +29,9 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256R1Test { @@ -103,7 +103,7 @@ public class SECP256R1Test { protected static String suiteStartTime = null; protected static String suiteName = null; - @BeforeClass + @BeforeAll public static void setTestSuiteStartTime() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) @@ -113,7 +113,7 @@ public static void setTestSuiteStartTime() { SignatureAlgorithmFactory.setInstance(SignatureAlgorithmType.create("secp256r1")); } - @Before + @BeforeEach public void setUp() { secp256R1 = new SECP256R1(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java index d99d4940915..24fbdb05288 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java @@ -29,8 +29,8 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class SECPPrivateKeyTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -40,7 +40,7 @@ public class SECPPrivateKeyTest { protected static String suiteName = null; public static ECDomainParameters curve; - @BeforeClass + @BeforeAll public static void setUp() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java index e5e9e6bb3a0..fe6e08404d5 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java @@ -24,8 +24,8 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECPPublicKeyTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -33,7 +33,7 @@ public class SECPPublicKeyTest { public ECDomainParameters curve; - @Before + @BeforeEach public void setUp() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java index a737a93f0b1..4298f662067 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java @@ -22,15 +22,15 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class SECPSignatureTest { public static final String CURVE_NAME = "secp256k1"; public static BigInteger curveOrder; - @BeforeClass + @BeforeAll public static void setUp() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); final ECDomainParameters curve = diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java index 38c71c99db8..cabdaa7668a 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java @@ -17,12 +17,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SignatureAlgorithmFactoryTest { - @Before + @BeforeEach public void setUp() { SignatureAlgorithmFactory.resetInstance(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java index faa0b5eeda7..13b37a05612 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SignatureAlgorithmTypeTest { @Test diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java index 18da8a44fcb..d88c54269fe 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java index 75f153e814a..0a57b76ff0f 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java index 56c925a5647..5d0871505f4 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java index 5794753c4a7..9f0a783a583 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java index fb806866afe..081bcadf207 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java index 6f3bc862ba9..9164657387e 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java index 8eab290be31..8752cb14d1a 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: From 017f9aa2243ffdf1ee1635674ef3f4ea981c8233 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Wed, 6 Dec 2023 15:39:20 -0800 Subject: [PATCH 3/5] fixes for problems discovered in main (#6248) Signed-off-by: garyschulte --- besu/src/test/java/org/hyperledger/besu/PrivacyTest.java | 2 +- docker/openjdk-17-debug/Dockerfile | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index c71d44284fb..038dcdedd1f 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -68,7 +68,7 @@ public class PrivacyTest { private final Vertx vertx = Vertx.vertx(); - @TempDir private static Path dataDir; + @TempDir private Path dataDir; @AfterEach public void cleanUp() { diff --git a/docker/openjdk-17-debug/Dockerfile b/docker/openjdk-17-debug/Dockerfile index a8e2276209b..c08f1ea4b9f 100644 --- a/docker/openjdk-17-debug/Dockerfile +++ b/docker/openjdk-17-debug/Dockerfile @@ -35,11 +35,9 @@ ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 ENV BESU_METRICS_HOST 0.0.0.0 ENV BESU_JMX_HOST 0.0.0.0 ENV BESU_PID_PATH "/tmp/pid" -ENV BESU_HOST_ALLOWLIST "*" #debug options for maximum observability ENV BESU_LOGGING "INFO" -ENV BESU_RPC_HTTP_API "ETH,NET,TRACE,DEBUG,ADMIN,TXPOOL" ENV JDWP_OPTS "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" ENV JAVA_OPTS "${JDWP_OPTS} " From 4cc2eed4e6783f94b21cdf7790d915e1377168d4 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 12:05:45 +1000 Subject: [PATCH 4/5] Pki - migrate to junit 5 (#6235) * migrate to junit5 Signed-off-by: Sally MacFarlane * fix: double calls to trace{Start,End}Transaction (#6247) Signed-off-by: Franklin Delehelle * migrate to junit5 (#6234) Signed-off-by: Sally MacFarlane * fixes for problems discovered in main (#6248) Signed-off-by: garyschulte * fixed test comparing size of collection Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Signed-off-by: Franklin Delehelle Signed-off-by: garyschulte Co-authored-by: delehef Co-authored-by: garyschulte --- pki/build.gradle | 3 +- .../pki/cms/CmsCreationAndValidationTest.java | 26 ++- .../keystore/BaseKeyStoreFileWrapperTest.java | 166 +++++++++++------- .../HardwareKeyStoreFileWrapperTest.java | 48 +++-- .../keystore/HardwareKeyStoreWrapperTest.java | 23 +-- .../SoftwareKeyStoreFileWrapperTest.java | 22 +-- .../keystore/SoftwareKeyStoreWrapperTest.java | 39 ++-- 7 files changed, 172 insertions(+), 155 deletions(-) diff --git a/pki/build.gradle b/pki/build.gradle index c9021b3a83e..8e2f52a4735 100644 --- a/pki/build.gradle +++ b/pki/build.gradle @@ -34,10 +34,9 @@ dependencies { implementation 'io.tmio:tuweni-bytes' implementation 'org.bouncycastle:bcpkix-jdk18on' - testImplementation 'junit:junit' - testImplementation 'org.assertj:assertj-core' 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/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java b/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java index ceb30e1e00f..2daf9b576be 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java @@ -15,9 +15,10 @@ package org.hyperledger.besu.pki.cms; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm.EC; import static org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm.RSA; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm; @@ -56,8 +57,7 @@ private CmsTestKeystores getCmsTestKeystores(final Algorithm algorithm) { public void cmsValidationWithEmptyCmsMessage(final Algorithm algorithm) { final Bytes data = Bytes.random(32); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(Bytes.EMPTY, data)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(Bytes.EMPTY, data)); } @ParameterizedTest @@ -69,7 +69,7 @@ public void cmsValidationWithTrustedSelfSignedCertificate(final Algorithm algori final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isTrue(); + assertTrue(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -81,7 +81,7 @@ public void cmsValidationWithUntrustedSelfSignedCertificate(final Algorithm algo final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -93,7 +93,7 @@ public void cmsValidationWithTrustedChain(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isTrue(); + assertTrue(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -105,7 +105,7 @@ public void cmsValidationWithUntrustedChain(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -117,7 +117,7 @@ public void cmsValidationWithExpiredCertificate(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -129,7 +129,7 @@ public void cmsValidationWithRevokedCertificate(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -144,7 +144,7 @@ public void cmsValidationWithoutCRLConfigDisablesCRLCheck(final Algorithm algori CmsValidator cmsValidator = getCmsTestKeystores(algorithm).getCmsValidatorWithoutCrl(); // Because we don't have a CRL CertStore, revocation is not checked - assertThat(cmsValidator.validate(cms, data)).isTrue(); + assertTrue(cmsValidator.validate(cms, data)); } @ParameterizedTest @@ -156,8 +156,7 @@ public void cmsValidationWithWrongSignedData(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(otherData); final Bytes expectedData = Bytes.random(32); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, expectedData)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, expectedData)); } @ParameterizedTest @@ -198,7 +197,6 @@ public void cmsValidationWithInvalidSignature(final Algorithm algorithm) throws final CMSSignedData cmsSignedData = cmsGenerator.generate(cmsData, true); final Bytes cmsBytes = Bytes.wrap(cmsSignedData.getEncoded()); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cmsBytes, expectedData)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cmsBytes, expectedData)); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java index 254e8bf23c7..3cbeff8985a 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java @@ -14,113 +14,143 @@ */ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.nio.file.Path; import java.security.cert.Certificate; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public abstract class BaseKeyStoreFileWrapperTest { protected static final String KEYSTORE_VALID_KEY_ALIAS = "partner1client1"; protected static final String KEYSTORE_INVALID_KEY_ALIAS = "partner1clientinvalid"; protected static final String TRUSTSTORE_VALID_CERTIFICATE_ALIAS = "interca"; protected static final String TRUSTSTORE_INVALID_CERTIFICATE_ALIAS = "interca-invalid"; - @Parameterized.Parameter public String keyStoreWrapperDescription; - - @Parameterized.Parameter(1) - public boolean keystoreWrapperConfiguredWithTruststore; - - @Parameterized.Parameter(2) - public KeyStoreWrapper keyStoreWrapper; - protected static Path toPath(final String path) throws Exception { return null == path ? null : Path.of(BaseKeyStoreFileWrapperTest.class.getResource(path).toURI()); } - @Test - public void getPublicKey_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPublicKey(KEYSTORE_VALID_KEY_ALIAS)) - .as("Public key is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getPublicKey_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPublicKey(KEYSTORE_VALID_KEY_ALIAS)); } - @Test - public void getPublicKey_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPublicKey(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Public key is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getPublicKey_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPublicKey(KEYSTORE_INVALID_KEY_ALIAS)); } - @Test - public void getPrivateKey_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(KEYSTORE_VALID_KEY_ALIAS)) - .as("Private key is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getPrivateKey_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey(KEYSTORE_VALID_KEY_ALIAS), + "Private key is not null"); } - @Test - public void getPrivateKey_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Private key is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getPrivateKey_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey(KEYSTORE_INVALID_KEY_ALIAS), + "Private key is null"); } - @Test - public void getCertificate_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificate(KEYSTORE_VALID_KEY_ALIAS)) - .as("Certificate is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate(KEYSTORE_VALID_KEY_ALIAS), + "Certificate is not null"); } - @Test - public void getCertificate_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificate(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate(KEYSTORE_INVALID_KEY_ALIAS), + "Certificate is null"); } - @Test - public void getCertificateChain_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificateChain(KEYSTORE_VALID_KEY_ALIAS)) - .as("Certificate chain is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificateChain_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificateChain(KEYSTORE_VALID_KEY_ALIAS), + "Certificate chain is not null"); } - @Test - public void getCertificateChain_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificateChain(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificateChain_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificateChain( + KEYSTORE_INVALID_KEY_ALIAS), + "Certificate is null"); } - @Test - public void getCertificate_FromTruststore_WithValidAlias_ReturnsExpectedValue() { + @ParameterizedTest + @MethodSource("data") + public void getCertificate_FromTruststore_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { final Certificate certificate = - keyStoreWrapper.getCertificate(TRUSTSTORE_VALID_CERTIFICATE_ALIAS); - if (keystoreWrapperConfiguredWithTruststore) { - assertThat(certificate).as("Certificate is not null").isNotNull(); + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate( + TRUSTSTORE_VALID_CERTIFICATE_ALIAS); + if (keyStoreWrapperTestParameter.keystoreWrapperConfiguredWithTruststore) { + assertNotNull(certificate, "Certificate is not null"); } else { - assertThat(certificate).as("Certificate is null").isNull(); + assertNull(certificate, "Certificate is null"); } } - @Test - public void getCertificate_FromTruststore_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(TRUSTSTORE_INVALID_CERTIFICATE_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_FromTruststore_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey( + TRUSTSTORE_INVALID_CERTIFICATE_ALIAS), + "Certificate is null"); } - @Test - public void getCRLS_Check() { - assertThat(keyStoreWrapper.getCRLs()).as("CRLs is not null").isNotNull(); - assertThat(keyStoreWrapper.getCRLs().size()).as("CRLs size matches").isEqualTo(2); + @ParameterizedTest + @MethodSource("data") + public void getCRLS_Check(final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull(keyStoreWrapperTestParameter.keyStoreWrapper.getCRLs(), "CRLs is not null"); + assertEquals( + keyStoreWrapperTestParameter.keyStoreWrapper.getCRLs().size(), 2, "CRLs size matches"); + } + + public static class KeyStoreWrapperTestParameter { + public String keyStoreWrapperDescription; + public boolean keystoreWrapperConfiguredWithTruststore; + public KeyStoreWrapper keyStoreWrapper; + + public KeyStoreWrapperTestParameter( + final String keyStoreWrapperDescription, + final boolean keystoreWrapperConfiguredWithTruststore, + final KeyStoreWrapper keyStoreWrapper) { + this.keyStoreWrapperDescription = keyStoreWrapperDescription; + this.keystoreWrapperConfiguredWithTruststore = keystoreWrapperConfiguredWithTruststore; + this.keyStoreWrapper = keyStoreWrapper; + } } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java index 99208e01c5b..0dde591cf50 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java @@ -14,7 +14,8 @@ */ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hyperledger.besu.pki.PkiException; @@ -26,11 +27,9 @@ import java.util.Optional; import java.util.stream.Stream; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.OS; -import org.junit.runners.Parameterized; public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest { @@ -39,16 +38,12 @@ public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest private static final String configName = "NSScrypto-partner1client1"; private static final String validKeystorePassword = "test123"; - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() { + public static Collection data() { return Arrays.asList( - new Object[][] { - { + new KeyStoreWrapperTestParameter( "HardwareKeyStoreWrapper[PKCS11 keystore/truststore]", true, - CryptoTestUtil.isNSSLibInstalled() ? getHardwareKeyStoreWrapper(configName) : null - } - }); + CryptoTestUtil.isNSSLibInstalled() ? getHardwareKeyStoreWrapper(configName) : null)); } private static KeyStoreWrapper getHardwareKeyStoreWrapper(final String cfgName) { @@ -66,26 +61,26 @@ private static KeyStoreWrapper getHardwareKeyStoreWrapper(final String cfgName) if (OS.MAC.isCurrentOs()) { // nss3 is difficult to setup on mac correctly, don't let it break unit tests for dev // machines. - Assume.assumeNoException("Failed to initialize hardware keystore", e); + System.out.println("Failed to initialize hardware keystore " + e.getLocalizedMessage()); } // Not a mac, probably a production build. Full failure. throw new PkiException("Failed to initialize hardware keystore", e); } } - @Before + @BeforeEach public void beforeMethod() { - Assume.assumeTrue( - "Test ignored due to NSS library not being installed/detected.", - CryptoTestUtil.isNSSLibInstalled()); + assumeTrue( + CryptoTestUtil.isNSSLibInstalled(), + "Test ignored due to NSS library not being installed/detected."); } @Test public void getPkcs11Provider() throws Exception { final HardwareKeyStoreWrapper sut = (HardwareKeyStoreWrapper) getHardwareKeyStoreWrapper(configName); - assertThatThrownBy(() -> sut.getPkcs11ProviderForConfig("no-library")) - .isInstanceOf(IllegalArgumentException.class); + assertThrows( + IllegalArgumentException.class, () -> sut.getPkcs11ProviderForConfig("no-library")); } @Test @@ -96,21 +91,22 @@ public void init_keystorePassword_config() throws Exception { @Test public void init_keystorePassword_config_invalid() throws Exception { final String config = "invalid"; - assertThatThrownBy( - () -> new HardwareKeyStoreWrapper(validKeystorePassword, toPath(config), toPath(crl))) - .isInstanceOf(NullPointerException.class); + assertThrows( + NullPointerException.class, + () -> new HardwareKeyStoreWrapper(validKeystorePassword, toPath(config), toPath(crl))); } @Test public void init_keystorePassword_config_missing_pw() throws Exception { - assertThatThrownBy(() -> new HardwareKeyStoreWrapper(null, toPath(config), toPath(crl))) - .isInstanceOf(PkiException.class); + assertThrows( + PkiException.class, () -> new HardwareKeyStoreWrapper(null, toPath(config), toPath(crl))); } @Test public void init_keystorePassword_provider_missing_pw() throws Exception { final Provider p = null; - assertThatThrownBy(() -> new HardwareKeyStoreWrapper(validKeystorePassword, p, toPath(crl))) - .isInstanceOf(PkiException.class); + assertThrows( + PkiException.class, + () -> new HardwareKeyStoreWrapper(validKeystorePassword, p, toPath(crl))); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java index bbbe68f8232..1d72a0537f4 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java @@ -15,7 +15,8 @@ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; import java.security.KeyStore; @@ -23,13 +24,13 @@ import java.security.PublicKey; import java.security.cert.Certificate; -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 HardwareKeyStoreWrapperTest { private static final String KEY_ALIAS = "keyalias"; @@ -43,7 +44,7 @@ public class HardwareKeyStoreWrapperTest { private HardwareKeyStoreWrapper keyStoreWrapper; - @Before + @BeforeEach public void before() { keyStoreWrapper = new HardwareKeyStoreWrapper(null, keyStore, new String(PASSWORD)); } @@ -52,7 +53,7 @@ public void before() { public void getPrivateKey() throws Exception { when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); } @Test @@ -61,14 +62,14 @@ public void getPublicKey() throws Exception { when(keyStore.getCertificate(KEY_ALIAS)).thenReturn(certificate); when(certificate.getPublicKey()).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); } @Test public void getCertificate() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); } @Test @@ -76,6 +77,6 @@ public void getCertificateChain() throws Exception { when(keyStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java index a194d8ec690..2550d070f72 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java @@ -20,8 +20,6 @@ import java.util.Arrays; import java.util.Collection; -import org.junit.runners.Parameterized; - public class SoftwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest { private static final String p12KeyStore = "/keystore/partner1client1/keys.p12"; @@ -30,26 +28,20 @@ public class SoftwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest private static final String crl = "/keystore/partner1client1/crl.pem"; private static final String validKeystorePassword = "test123"; - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() { + public static Collection data() { return Arrays.asList( - new Object[][] { - { + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[PKCS12 keystore only]", false, - getPKCS12SoftwareKeyStoreWrapper() - }, - { + getPKCS12SoftwareKeyStoreWrapper()), + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[JKS keystore only]", false, - getJKSSoftwareKeyStoreWrapper(false) - }, - { + getJKSSoftwareKeyStoreWrapper(false)), + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[JKS keystore/truststore]", true, - getJKSSoftwareKeyStoreWrapper(true) - } - }); + getJKSSoftwareKeyStoreWrapper(true))); } private static KeyStoreWrapper getPKCS12SoftwareKeyStoreWrapper() { diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java index e198084ac44..8f7f8164bc8 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java @@ -15,8 +15,9 @@ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.pki.keystore.KeyStoreWrapper.KEYSTORE_TYPE_PKCS12; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -28,13 +29,13 @@ import java.security.PublicKey; import java.security.cert.Certificate; -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 SoftwareKeyStoreWrapperTest { private static final String KEY_ALIAS = "keyalias"; @@ -49,7 +50,7 @@ public class SoftwareKeyStoreWrapperTest { @Mock private PublicKey publicKey; @Mock private Certificate certificate; - @Before + @BeforeEach public void before() { keyStoreWrapper = new SoftwareKeyStoreWrapper(keyStore, new String(PASSWORD), null, ""); } @@ -59,7 +60,7 @@ public void getPrivateKey() throws Exception { when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); } @Test @@ -83,7 +84,7 @@ public void getPrivateKeyFallbackToTrustStore() throws Exception { when(trustStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(trustStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); verify(trustStore).getKey(eq(KEY_ALIAS), eq(PASSWORD)); } @@ -93,7 +94,7 @@ public void getPublicKey() throws Exception { when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); } @Test @@ -117,7 +118,7 @@ public void getPublicKeyFallbackToTrustStore() throws Exception { when(trustStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(trustStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); verify(trustStore).getKey(eq(KEY_ALIAS), eq(PASSWORD)); } @@ -126,7 +127,7 @@ public void getPublicKeyFallbackToTrustStore() throws Exception { public void getCertificate() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); } @Test @@ -148,7 +149,7 @@ public void getCertificateFallbackToTrustStore() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(null); when(trustStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); verify(trustStore).getCertificate(eq(CERTIFICATE_ALIAS)); } @@ -158,7 +159,7 @@ public void getCertificateChain() throws Exception { when(keyStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); } @Test @@ -171,7 +172,7 @@ public void getCertificateChainFallbackToTrustStore() throws Exception { when(trustStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); verify(trustStore).getCertificateChain(eq(CERTIFICATE_ALIAS)); } @@ -188,10 +189,10 @@ public void loadKeyStoreFromFile() { "validator", null); - assertThat(loadedKeyStore.getPublicKey("validator")).isNotNull(); - assertThat(loadedKeyStore.getPrivateKey("validator")).isNotNull(); - assertThat(loadedKeyStore.getCertificate("validator")).isNotNull(); + assertNotNull(loadedKeyStore.getPublicKey("validator")); + assertNotNull(loadedKeyStore.getPrivateKey("validator")); + assertNotNull(loadedKeyStore.getCertificate("validator")); // CA -> INTERCA -> PARTNERACA -> VALIDATOR - assertThat(loadedKeyStore.getCertificateChain("validator")).hasSize(4); + assertEquals(loadedKeyStore.getCertificateChain("validator").length, 4); } } From b6e73ae0804096839cd44d800b4d392d74910cbb Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 12:57:06 +1000 Subject: [PATCH 5/5] junit 5 ftw (#6253) Signed-off-by: Sally MacFarlane --- consensus/common/build.gradle | 2 +- .../CombinedProtocolScheduleFactoryTest.java | 8 ++++---- .../consensus/common/ForksScheduleTest.java | 2 +- .../MigratingMiningCoordinatorTest.java | 16 ++++++++-------- .../common/MigratingProtocolContextTest.java | 2 +- .../BaseBftProtocolScheduleBuilderTest.java | 2 +- .../bft/BaseForksSchedulesFactoryTest.java | 2 +- .../common/bft/BftEventQueueTest.java | 2 +- .../bft/BftForksScheduleFactoryTest.java | 2 +- .../consensus/common/bft/BftHelpersTest.java | 2 +- .../common/bft/BftProcessorTest.java | 12 ++++++------ .../consensus/common/bft/BlockTimerTest.java | 12 ++++++------ .../bft/EthSynchronizerUpdaterTest.java | 8 ++++---- .../common/bft/MessageTrackerTest.java | 2 +- .../consensus/common/bft/RoundTimerTest.java | 12 ++++++------ .../common/bft/SizeLimitedMapTest.java | 2 +- .../bft/UniqueMessageMulticasterTest.java | 8 ++++---- .../besu/consensus/common/bft/VoteTest.java | 2 +- .../BftMiningCoordinatorTest.java | 19 ++++++++++--------- .../blockcreation/ProposerSelectorTest.java | 2 +- .../BftCoinbaseValidationRuleTest.java | 2 +- .../BftCommitSealsValidationRuleTest.java | 2 +- .../BftValidatorsValidationRuleTest.java | 2 +- .../BftVanityDataValidationRuleTest.java | 2 +- .../bft/network/ValidatorPeersTest.java | 17 +++++++++-------- .../bft/queries/BftQueryServiceImplTest.java | 12 ++++++------ .../statemachine/FutureMessageBufferTest.java | 6 +++--- .../blockbased/ForkingVoteTallyCacheTest.java | 2 +- .../blockbased/VoteProposerTest.java | 2 +- .../blockbased/VoteTallyCacheTest.java | 2 +- .../blockbased/VoteTallyCacheTestBase.java | 4 ++-- .../validator/blockbased/VoteTallyTest.java | 2 +- .../blockbased/VoteTallyUpdaterTest.java | 2 +- 33 files changed, 89 insertions(+), 87 deletions(-) diff --git a/consensus/common/build.gradle b/consensus/common/build.gradle index 49c73e7d176..04132ab6d00 100644 --- a/consensus/common/build.gradle +++ b/consensus/common/build.gradle @@ -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' diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 29b197b9ece..9c1e8005a80 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -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 = diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java index bf6d32f4694..053037e933c 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java index 31eabf22aaf..df301f44a17 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java @@ -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; @@ -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; @@ -58,7 +59,7 @@ public class MigratingMiningCoordinatorTest { private ForksSchedule 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 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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index 21ba7638c40..c675219c352 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java index d704cddce85..b2b2a9fe3af 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java index 5102276f8e8..ba65dffbff7 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java @@ -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> { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java index 28e444e0e42..db5587b9d28 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java @@ -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; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java index dbfc16da29e..72b15b58bcf 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java index 6daadc0fd41..67e7cc283b9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java index da62a8f5cc5..5ff31b538bc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java @@ -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); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java index ec0783f6a3e..23026148114 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java @@ -37,14 +37,14 @@ 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 mockForksSchedule; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void initialise() { bftExecutors = mock(BftExecutors.class); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java index 7d01ebe059e..62465a183d5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java @@ -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; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java index 72eb918c74a..68fce007271 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java @@ -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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java index 693074bdfb0..f8a061471db 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java @@ -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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java index b6eb9a057fd..e363920078d 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.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 SizeLimitedMapTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java index 70c18c52303..cbc731317e9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java @@ -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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java index cb96b9d4f71..b01a3a97c6f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Address; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTest { @Test diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java index 5b1d7a3cf64..dda38b45af1 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java @@ -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.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 diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java index 80737668027..ebe74b16988 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java index fcbea4954d8..e8d7ee79e98 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java index 453b28a601c..facc4ee2e3a 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java index 00b994295ca..690dc26f155 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java @@ -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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java index cd148f8787a..5b9252df567 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java @@ -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(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java index 38ad26c658b..3f8c9f24153 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java @@ -16,6 +16,7 @@ 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.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 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 void setup() { 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; } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java index ab161c2c401..cc99cf805fc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java @@ -42,13 +42,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 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) diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java index 1267d5794b6..b584c9a16b5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java @@ -30,15 +30,15 @@ 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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java index f1692201cec..d877223a8fd 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java @@ -26,7 +26,7 @@ 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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java index d486a41979a..6263bc960cc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java @@ -24,7 +24,7 @@ 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"); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java index c69f2bb7697..514e5b8ab37 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java @@ -35,7 +35,7 @@ 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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java index 1a3dba12b1d..00e22532e2f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java @@ -33,7 +33,7 @@ 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 @@ protected Block createEmptyBlock(final long blockNumber, final Hash parentHash) protected final BlockInterface blockInterface = mock(BlockInterface.class); - @Before + @BeforeEach public void constructThreeBlockChain() { for (int i = 0; i < 3; i++) { validators.add(AddressHelpers.ofValue(i)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java index 96671716cae..9c8d1033cba 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java @@ -22,7 +22,7 @@ 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 { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java index 6d7590edf9a..21039c84d85 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java @@ -37,7 +37,7 @@ import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTallyUpdaterTest {