From 2ebf4be39c53f0685744312b7953446ad8125f41 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 14 Dec 2021 15:47:53 +0100 Subject: [PATCH] Replace @MethodSource annotation with @ArgumentsSource --- .../org/bouncycastle/PGPUtilWrapperTest.java | 5 +- .../DecryptAndVerifyMessageTest.java | 5 +- .../DecryptHiddenRecipientMessage.java | 5 +- .../ModificationDetectionTests.java | 30 +++++---- .../RecursionDepthTest.java | 8 ++- .../EncryptDecryptTest.java | 26 ++++---- .../EncryptionStreamClosedTest.java | 5 +- .../encryption_signing/SigningTest.java | 48 +++++++++----- .../key/BouncycastleExportSubkeys.java | 5 +- .../pgpainless/key/ImportExportKeyTest.java | 7 +- .../BrainpoolKeyGenerationTest.java | 7 +- ...rtificationKeyMustBeAbleToCertifyTest.java | 5 +- .../GenerateEllipticCurveKeyTest.java | 5 +- .../GenerateKeyWithAdditionalUserIdTest.java | 5 +- .../GenerateWithEmptyPassphraseTest.java | 5 +- .../key/generation/IllegalKeyFlagsTest.java | 5 +- .../pgpainless/key/info/KeyRingInfoTest.java | 11 ++-- .../key/modification/AddSubKeyTest.java | 5 +- .../key/modification/AddUserIdTest.java | 12 ++-- ...nOnKeyWithDifferentSignatureTypesTest.java | 7 +- .../modification/ChangeExpirationTest.java | 13 ++-- .../ChangeSecretKeyRingPassphraseTest.java | 11 ++-- ...gnatureSubpacketsArePreservedOnNewSig.java | 8 +-- ...WithGenericCertificationSignatureTest.java | 5 +- ...ithoutPreferredAlgorithmsOnPrimaryKey.java | 8 ++- .../key/modification/RevokeSubKeyTest.java | 9 +-- .../SecretKeyRingProtectorTest.java | 8 +-- .../BindingSignatureSubpacketsTest.java | 65 ++++++++++--------- .../signature/CertificateValidatorTest.java | 17 ++--- .../signature/KeyRevocationTest.java | 7 +- .../OnePassSignatureBracketingTest.java | 5 +- ...ultiPassphraseSymmetricEncryptionTest.java | 5 +- .../SymmetricEncryptionTest.java | 7 +- .../org/pgpainless/util/ArmorUtilsTest.java | 4 +- .../TestImplementationFactoryProvider.java | 11 +++- 35 files changed, 225 insertions(+), 169 deletions(-) diff --git a/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java b/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java index 604cdfdf..fd1ec62a 100644 --- a/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java +++ b/pgpainless-core/src/test/java/org/bouncycastle/PGPUtilWrapperTest.java @@ -20,14 +20,15 @@ import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.PGPUtilWrapper; +import org.pgpainless.util.TestImplementationFactoryProvider; public class PGPUtilWrapperTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testGetDecoderStream(ImplementationFactory implementationFactory) throws IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java index 3fa1ec4e..76426582 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java @@ -18,7 +18,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; @@ -26,6 +26,7 @@ import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.TestKeys; import org.pgpainless.key.util.KeyRingUtils; +import org.pgpainless.util.TestImplementationFactoryProvider; public class DecryptAndVerifyMessageTest { @@ -42,7 +43,7 @@ public class DecryptAndVerifyMessageTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void decryptMessageAndVerifySignatureTest(ImplementationFactory implementationFactory) throws Exception { ImplementationFactory.setFactoryImplementation(implementationFactory); String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET; diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java index 3ebe5390..060435ff 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java @@ -17,17 +17,18 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.info.KeyRingInfo; +import org.pgpainless.util.TestImplementationFactoryProvider; public class DecryptHiddenRecipientMessage { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testDecryptionWithWildcardRecipient(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); String secretKeyAscii = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java index 2eb870cb..03f6165e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java @@ -18,15 +18,15 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.exception.MessageNotIntegrityProtectedException; import org.pgpainless.exception.ModificationDetectionException; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class ModificationDetectionTests { @@ -210,7 +210,7 @@ public class ModificationDetectionTests { * @throws PGPException in case of a pgp error */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testMissingMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -231,7 +231,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testTamperedCiphertextThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); @@ -247,7 +247,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testIgnoreTamperedCiphertext(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); @@ -264,7 +264,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testTamperedMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); @@ -280,7 +280,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testIgnoreTamperedMDC(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); @@ -296,7 +296,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testTruncatedMDCThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8)); @@ -311,7 +311,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testMDCWithBadCTBThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); @@ -327,7 +327,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testIgnoreMDCWithBadCTB(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); @@ -344,7 +344,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testMDCWithBadLengthThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); @@ -360,7 +360,7 @@ public class ModificationDetectionTests { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testIgnoreMDCWithBadLength(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); @@ -376,8 +376,10 @@ public class ModificationDetectionTests { decryptionStream.close(); } - @Test - public void decryptMessageWithSEDPacket() throws IOException, PGPException { + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void decryptMessageWithSEDPacket(ImplementationFactory implementationFactory) throws IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); Passphrase passphrase = Passphrase.fromPassword("flowcrypt compatibility tests"); String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n" + "Version: FlowCrypt 6.9.1 Gmail Encryption\r\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java index 5bc1ae61..73ff3f71 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java @@ -15,9 +15,10 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; +import org.pgpainless.util.TestImplementationFactoryProvider; public class RecursionDepthTest { @@ -27,8 +28,9 @@ public class RecursionDepthTest { * @see Sequoia-PGP Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void decryptionAbortsWhenMaximumRecursionDepthReachedTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void decryptionAbortsWhenMaximumRecursionDepthReachedTest(ImplementationFactory implementationFactory) + throws IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "Comment: Bob's OpenPGP Transferable Secret Key\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java index da70e170..09a58695 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java @@ -25,9 +25,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.KeyFlag; @@ -48,6 +47,7 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.policy.Policy; import org.pgpainless.util.ArmoredOutputStreamFactory; +import org.pgpainless.util.TestImplementationFactoryProvider; public class EncryptDecryptTest { @@ -71,7 +71,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void freshKeysRsaToElGamalTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -89,7 +89,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void freshKeysRsaToRsaTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -100,7 +100,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void freshKeysEcToEcTest(ImplementationFactory implementationFactory) throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -111,7 +111,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void freshKeysEcToRsaTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -122,7 +122,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void freshKeysRsaToEcTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -133,7 +133,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void existingRsaKeysTest(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing(); @@ -198,7 +198,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testDetachedSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -244,7 +244,7 @@ public class EncryptDecryptTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testOnePassSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); @@ -274,8 +274,10 @@ public class EncryptDecryptTest { assertFalse(metadata.getVerifiedSignatures().isEmpty()); } - @Test - public void expiredSubkeyBacksigTest() throws IOException { + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void expiredSubkeyBacksigTest(ImplementationFactory implementationFactory) throws IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "\n" + "xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java index c667de31..e3b31967 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java @@ -12,15 +12,16 @@ import java.io.OutputStream; import org.bouncycastle.openpgp.PGPException; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class EncryptionStreamClosedTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testStreamHasToBeClosedBeforeGetResultCanBeCalled(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); OutputStream out = new ByteArrayOutputStream(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java index 6a73152d..27860088 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java @@ -26,9 +26,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.HashAlgorithm; @@ -49,11 +48,12 @@ import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.util.MultiMap; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class SigningTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testEncryptionAndSignatureVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -117,9 +117,11 @@ public class SigningTest { assertFalse(metadata.containsVerifiedSignatureFrom(julietKeys)); } - @Test - public void testSignWithInvalidUserIdFails() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void testSignWithInvalidUserIdFails(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .modernKeyRing("alice", "password123"); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123")); @@ -131,9 +133,11 @@ public class SigningTest { DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); } - @Test - public void testSignWithRevokedUserIdFails() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void testSignWithRevokedUserIdFails(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .modernKeyRing("alice", "password123"); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith( @@ -151,8 +155,10 @@ public class SigningTest { DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); } - @Test - public void signWithHashAlgorithmOverride() throws PGPException, IOException { + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void signWithHashAlgorithmOverride(ImplementationFactory implementationFactory) throws PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); @@ -182,9 +188,11 @@ public class SigningTest { assertEquals(HashAlgorithm.SHA224.getAlgorithmId(), signature.getHashAlgorithm()); } - @Test - public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() .setPrimaryKey(KeySpec.getBuilder( KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) @@ -211,9 +219,11 @@ public class SigningTest { signature.getHashAlgorithm()); } - @Test - public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() .setPrimaryKey( KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) @@ -240,9 +250,11 @@ public class SigningTest { signature.getHashAlgorithm()); } - @Test - public void signingWithNonCapableKeyThrowsKeyCannotSignException() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void signingWithNonCapableKeyThrowsKeyCannotSignException(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER)) .addUserId("Alice") @@ -255,9 +267,11 @@ public class SigningTest { SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT)); } - @Test - public void signWithInvalidUserIdThrowsKeyValidationError() + @ParameterizedTest + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void signWithInvalidUserIdThrowsKeyValidationError(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java index f3e40825..e651eb2d 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java @@ -30,14 +30,15 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.provider.ProviderFactory; +import org.pgpainless.util.TestImplementationFactoryProvider; public class BouncycastleExportSubkeys { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testExportImport(ImplementationFactory implementationFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); KeyPairGenerator generator; diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java index bcb9086e..d12963cd 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java @@ -14,8 +14,9 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.implementation.ImplementationFactory; +import org.pgpainless.util.TestImplementationFactoryProvider; public class ImportExportKeyTest { @@ -24,7 +25,7 @@ public class ImportExportKeyTest { * @throws IOException in case of a IO error */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testExportImportPublicKeyRing(ImplementationFactory implementationFactory) throws IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing(); @@ -36,7 +37,7 @@ public class ImportExportKeyTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testExportImportSecretKeyRing(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java index 8740ff4a..376777a2 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGenerationTest.java @@ -18,7 +18,7 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.PublicKeyAlgorithm; @@ -32,11 +32,12 @@ import org.pgpainless.key.info.KeyInfo; import org.pgpainless.key.util.UserId; import org.pgpainless.util.BCUtil; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class BrainpoolKeyGenerationTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void generateEcKeysTest(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -66,7 +67,7 @@ public class BrainpoolKeyGenerationTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void generateEdDSAKeyTest(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java index 31470715..fecde6c7 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java @@ -7,13 +7,14 @@ package org.pgpainless.key.generation; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.xdh.XDHSpec; +import org.pgpainless.util.TestImplementationFactoryProvider; public class CertificationKeyMustBeAbleToCertifyTest { @@ -23,7 +24,7 @@ public class CertificationKeyMustBeAbleToCertifyTest { * This test therefore verifies that generating such keys fails. */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testCertificationIncapableKeyTypesThrow(ImplementationFactory implementationFactory) { ImplementationFactory.setFactoryImplementation(implementationFactory); KeyType[] typesIncapableOfCreatingVerifications = new KeyType[] { diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java index eef7812b..36a987f9 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java @@ -13,7 +13,7 @@ import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.PublicKeyAlgorithm; @@ -24,11 +24,12 @@ import org.pgpainless.key.generation.type.xdh.XDHSpec; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.key.util.UserId; +import org.pgpainless.util.TestImplementationFactoryProvider; public class GenerateEllipticCurveKeyTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void generateEllipticCurveKeys(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing keyRing = PGPainless.buildKeyRing() diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java index 58b96a1b..4505662a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java @@ -18,7 +18,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.JUtils; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.implementation.ImplementationFactory; @@ -27,11 +27,12 @@ import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.UserId; import org.pgpainless.util.DateUtil; +import org.pgpainless.util.TestImplementationFactoryProvider; public class GenerateKeyWithAdditionalUserIdTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java index 5b9c9a58..6233e59e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphraseTest.java @@ -12,13 +12,14 @@ import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; /** * Reproduce behavior of https://github.com/pgpainless/pgpainless/issues/16 @@ -30,7 +31,7 @@ import org.pgpainless.util.Passphrase; public class GenerateWithEmptyPassphraseTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java index e5c48d5b..3477e189 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java @@ -7,17 +7,18 @@ package org.pgpainless.key.generation; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.xdh.XDHSpec; +import org.pgpainless.util.TestImplementationFactoryProvider; public class IllegalKeyFlagsTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testKeyCannotCarryFlagsTest(ImplementationFactory implementationFactory) { ImplementationFactory.setFactoryImplementation(implementationFactory); assertThrows(IllegalArgumentException.class, () -> KeySpec.getBuilder( diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java index 39e13edd..8f07d33f 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java @@ -32,7 +32,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.JUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.EncryptionPurpose; @@ -53,11 +53,12 @@ import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.UserId; import org.pgpainless.util.DateUtil; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class KeyRingInfoTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testWithEmilsKeys(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -175,8 +176,8 @@ public class KeyRingInfoTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void dummyS2KTest(ImplementationFactory implementationFactory) throws PGPException, IOException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void dummyS2KTest(ImplementationFactory implementationFactory) throws IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); String withDummyS2K = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + @@ -214,7 +215,7 @@ public class KeyRingInfoTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testGetKeysWithFlagsAndExpiry(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java index 0fb9a5ec..1b97cd1a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java @@ -21,7 +21,7 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.implementation.ImplementationFactory; @@ -34,11 +34,12 @@ import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class AddSubKeyTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testAddSubKey(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java index 705e7d48..77c1383b 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java @@ -19,7 +19,7 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; @@ -29,12 +29,14 @@ import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.util.UserId; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class AddUserIdTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void addUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void addUserIdToExistingKeyRing(ImplementationFactory implementationFactory) + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le"); @@ -65,7 +67,7 @@ public class AddUserIdTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void deleteUserId_noSuchElementExceptionForMissingUserId(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -75,7 +77,7 @@ public class AddUserIdTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void deleteExistingAndAddNewUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java index 36c9b8bb..aa8b0589 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationOnKeyWithDifferentSignatureTypesTest.java @@ -11,11 +11,12 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.JUtils; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.util.DateUtil; +import org.pgpainless.util.TestImplementationFactoryProvider; public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest { @@ -136,7 +137,7 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest { "-----END PGP PRIVATE KEY BLOCK-----"; @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void setExpirationDate_keyHasSigClass10(ImplementationFactory implementationFactory) throws PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -146,7 +147,7 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void setExpirationDate_keyHasSigClass12(ImplementationFactory implementationFactory) throws PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java index 562e81a7..b728016a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java @@ -14,7 +14,7 @@ import java.util.Date; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; @@ -22,14 +22,16 @@ import org.pgpainless.key.TestKeys; import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.util.DateUtil; +import org.pgpainless.util.TestImplementationFactoryProvider; public class ChangeExpirationTest { private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B"); @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory) throws PGPException, IOException, InterruptedException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory) + throws PGPException, IOException, InterruptedException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); @@ -61,8 +63,9 @@ public class ChangeExpirationTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void setExpirationDateAndThenUnsetIt_OnSubkey(ImplementationFactory implementationFactory) throws PGPException, IOException, InterruptedException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void setExpirationDateAndThenUnsetIt_OnSubkey(ImplementationFactory implementationFactory) + throws PGPException, IOException, InterruptedException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java index 7f4067ee..283d74cc 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java @@ -21,7 +21,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; @@ -33,6 +33,7 @@ import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class ChangeSecretKeyRingPassphraseTest { @@ -42,7 +43,7 @@ public class ChangeSecretKeyRingPassphraseTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void changePassphraseOfWholeKeyRingTest(ImplementationFactory implementationFactory) throws PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -70,7 +71,7 @@ public class ChangeSecretKeyRingPassphraseTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void changePassphraseOfWholeKeyRingToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) @@ -88,7 +89,7 @@ public class ChangeSecretKeyRingPassphraseTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void changePassphraseOfSingleSubkeyToNewPassphrase(ImplementationFactory implementationFactory) throws PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -125,7 +126,7 @@ public class ChangeSecretKeyRingPassphraseTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void changePassphraseOfSingleSubkeyToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java index a03744a3..b9a00cd6 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java @@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.util.Date; @@ -18,18 +17,19 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.protection.UnprotectedKeysProtector; +import org.pgpainless.util.TestImplementationFactoryProvider; public class OldSignatureSubpacketsArePreservedOnNewSig { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig(ImplementationFactory implementationFactory) - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException, IOException { + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .simpleEcKeyRing("Alice "); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java index 794438da..a9b1f0a8 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java @@ -15,11 +15,12 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.util.ArmoredOutputStreamFactory; +import org.pgpainless.util.TestImplementationFactoryProvider; /** * Test that makes sure that PGPainless can deal with keys that carry a key @@ -64,7 +65,7 @@ public class RevokeKeyWithGenericCertificationSignatureTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void test(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java index a218a6f9..1cce7290 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java @@ -14,7 +14,7 @@ import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.JUtils; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; @@ -23,6 +23,7 @@ import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterfac import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.util.DateUtil; +import org.pgpainless.util.TestImplementationFactoryProvider; public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey { @@ -101,8 +102,9 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey { "-----END PGP PRIVATE KEY BLOCK-----"; @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") - public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) throws IOException, PGPException { + @ArgumentsSource(TestImplementationFactoryProvider.class) + public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) + throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date())); PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java index 421c9ecf..861002f0 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java @@ -25,7 +25,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.SignatureType; @@ -40,11 +40,12 @@ import org.pgpainless.signature.SignatureUtils; import org.pgpainless.signature.subpackets.RevocationSignatureSubpackets; import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class RevokeSubKeyTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void revokeSukeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); @@ -69,7 +70,7 @@ public class RevokeSubKeyTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void detachedRevokeSubkeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); @@ -90,7 +91,7 @@ public class RevokeSubKeyTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testRevocationSignatureTypeCorrect(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java index 037d996d..b641af56 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java @@ -16,7 +16,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; - import javax.annotation.Nullable; import org.bouncycastle.openpgp.PGPException; @@ -25,17 +24,18 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class SecretKeyRingProtectorTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testUnlockAllKeysWithSamePassword(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -70,7 +70,7 @@ public class SecretKeyRingProtectorTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testUnlockSingleKeyWithPassphrase(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java index 85e4299d..f94380cd 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/BindingSignatureSubpacketsTest.java @@ -17,12 +17,13 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.policy.Policy; import org.pgpainless.signature.consumer.CertificateValidator; +import org.pgpainless.util.TestImplementationFactoryProvider; /** * Explores how subpackets on binding sigs are handled. @@ -52,7 +53,7 @@ public class BindingSignatureSubpacketsTest { private Policy policy = PGPainless.getPolicy(); @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void baseCase(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -114,7 +115,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -176,7 +177,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -238,7 +239,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -300,7 +301,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -362,7 +363,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -424,7 +425,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -485,7 +486,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void unknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -547,7 +548,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingUnknownCriticalSubpacket(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -609,7 +610,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -671,7 +672,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingUnknownCriticalSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -733,7 +734,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -796,7 +797,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -859,7 +860,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -922,7 +923,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -985,7 +986,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingBackSigFakeBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1058,7 +1059,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeyBindingFakeBackSigBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1131,7 +1132,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1193,7 +1194,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1255,7 +1256,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1317,7 +1318,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1379,7 +1380,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1441,7 +1442,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1502,7 +1503,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1564,7 +1565,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingCriticalUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1626,7 +1627,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1688,7 +1689,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingCriticalUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1750,7 +1751,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1813,7 +1814,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1876,7 +1877,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -1939,7 +1940,7 @@ public class BindingSignatureSubpacketsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void primaryBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java index 73a7cb85..5eb98aa7 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/CertificateValidatorTest.java @@ -20,7 +20,7 @@ import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.DecryptionStream; @@ -29,6 +29,7 @@ import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.policy.Policy; import org.pgpainless.signature.consumer.CertificateValidator; +import org.pgpainless.util.TestImplementationFactoryProvider; public class CertificateValidatorTest { @@ -38,7 +39,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testPrimaryKeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -190,7 +191,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -343,7 +344,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testSubkeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -496,7 +497,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testPrimaryKeySignsAndIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -654,7 +655,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -808,7 +809,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testPrimaryKeySignsAndIsSoftRevokedRetired(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -962,7 +963,7 @@ public class CertificateValidatorTest { * @see Sequoia Test Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testTemporaryValidity(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java index 73e726bf..95728fb0 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/KeyRevocationTest.java @@ -15,18 +15,19 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.signature.consumer.CertificateValidator; +import org.pgpainless.util.TestImplementationFactoryProvider; public class KeyRevocationTest { private static final String data = "Hello, World"; @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeySignsPrimaryKeyRevokedNoReason(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); @@ -174,7 +175,7 @@ public class KeyRevocationTest { * @see Sequoia Test-Suite */ @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void subkeySignsPrimaryKeyNotRevoked(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java b/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java index a68c7725..20fb598a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/signature/OnePassSignatureBracketingTest.java @@ -34,7 +34,7 @@ import org.bouncycastle.openpgp.PGPUtil; import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.HashAlgorithm; @@ -47,11 +47,12 @@ import org.pgpainless.encryption_signing.SigningOptions; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; +import org.pgpainless.util.TestImplementationFactoryProvider; public class OnePassSignatureBracketingTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void onePassSignaturePacketsAndSignaturesAreBracketedTest(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java index 9b26921f..7ab00868 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java @@ -12,7 +12,7 @@ import java.nio.charset.StandardCharsets; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.DecryptionStream; @@ -21,11 +21,12 @@ import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.ProducerOptions; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; public class MultiPassphraseSymmetricEncryptionTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void encryptDecryptWithMultiplePassphrases(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); String message = "Here we test if during decryption of a message that was encrypted with two passphrases, " + diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java index 68f929af..aa14394c 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java @@ -18,7 +18,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.PGPainless; import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.DecryptionStream; @@ -34,6 +34,7 @@ import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider; import org.pgpainless.util.Passphrase; +import org.pgpainless.util.TestImplementationFactoryProvider; /** * Test parallel symmetric and public key encryption/decryption. @@ -41,7 +42,7 @@ import org.pgpainless.util.Passphrase; public class SymmetricEncryptionTest { @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void encryptWithKeyAndPassphrase_DecryptWithKey(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); byte[] plaintext = "This is a secret message".getBytes(StandardCharsets.UTF_8); @@ -95,7 +96,7 @@ public class SymmetricEncryptionTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void testMismatchPassphraseFails(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java b/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java index 2c360b04..6a8a6a64 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/util/ArmorUtilsTest.java @@ -27,7 +27,7 @@ import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsSource; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; @@ -145,7 +145,7 @@ public class ArmorUtilsTest { } @ParameterizedTest - @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") + @ArgumentsSource(TestImplementationFactoryProvider.class) public void decodeExampleTest(ImplementationFactory implementationFactory) throws IOException, PGPException { ImplementationFactory.setFactoryImplementation(implementationFactory); String armored = "-----BEGIN PGP MESSAGE-----\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java b/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java index 1ace7245..63dc386c 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java +++ b/pgpainless-core/src/test/java/org/pgpainless/util/TestImplementationFactoryProvider.java @@ -4,24 +4,29 @@ package org.pgpainless.util; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; import org.pgpainless.implementation.BcImplementationFactory; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.JceImplementationFactory; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; /** * Utility class used to provide all available implementations of {@link ImplementationFactory} for parametrized tests. */ -public class TestImplementationFactoryProvider { +public class TestImplementationFactoryProvider implements ArgumentsProvider { private static final List IMPLEMENTATIONS = Arrays.asList( new BcImplementationFactory(), new JceImplementationFactory() ); - public static List provideImplementationFactories() { - return IMPLEMENTATIONS; + @Override + public Stream provideArguments(ExtensionContext context) { + return IMPLEMENTATIONS.stream().map(Arguments::of); } }