Skip to content

Commit bc5f6ed

Browse files
committed
Remove junit from samples
DEVSIX-8701
1 parent ac1a7e2 commit bc5f6ed

File tree

8 files changed

+53
-75
lines changed

8 files changed

+53
-75
lines changed

aws-kms/src/test/java/com/itextpdf/signingexamples/aws/kms/SimpleAwsConnectivity.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.itextpdf.signingexamples.aws.kms;
22

3-
import static org.junit.jupiter.api.Assertions.*;
4-
53
import java.io.File;
64
import java.io.IOException;
75
import java.io.OutputStream;
@@ -87,7 +85,7 @@ void testListAliases() {
8785
try ( KmsClient kmsClient = KmsClient.create() ) {
8886
List<AliasListEntry> aliases = kmsClient.listAliases().aliases();
8987
aliases.forEach(System.out::println);
90-
assertTrue(() -> aliases.stream().anyMatch(alias -> alias.aliasName().equals("alias/SigningExamples-ECC_NIST_P256")));
88+
assert aliases.stream().anyMatch(alias -> alias.aliasName().equals("alias/SigningExamples-ECC_NIST_P256"));
9189
}
9290
}
9391

@@ -102,11 +100,11 @@ void testSignSimple() {
102100
.message(SdkBytes.fromUtf8String("Test"))
103101
.build();
104102
SignResponse signResponse = kmsClient.sign(signRequest);
105-
assertNotNull(signResponse, "SignResponse");
103+
assert signResponse!= null;
106104
SdkBytes signatureSdkBytes = signResponse.signature();
107-
assertNotNull(signatureSdkBytes, "signature SdkBytes");
105+
assert signatureSdkBytes!= null;
108106
byte[] signatureBytes = signatureSdkBytes.asByteArray();
109-
assertNotNull(signatureBytes, "signature Bytes");
107+
assert signatureBytes != null;
110108

111109
VerifyRequest verifyRequest = VerifyRequest.builder()
112110
.signingAlgorithm("ECDSA_SHA_256")
@@ -116,10 +114,10 @@ void testSignSimple() {
116114
.signature(SdkBytes.fromByteArray(signatureBytes))
117115
.build();
118116
VerifyResponse verifyResponse = kmsClient.verify(verifyRequest);
119-
assertNotNull(verifyResponse, "VerifyResponse");
117+
assert verifyResponse != null;
120118
Boolean signatureValid = verifyResponse.signatureValid();
121-
assertNotNull(signatureValid, "signatureValid Boolean");
122-
assertTrue(signatureValid, "signatureValid");
119+
assert signatureValid != null;
120+
assert signatureValid;
123121
}
124122
}
125123

@@ -132,20 +130,20 @@ void testPublicKey() throws PEMException {
132130
.keyId("alias/SigningExamples-ECC_NIST_P256")
133131
.build();
134132
GetPublicKeyResponse getPublicKeyResponse = kmsClient.getPublicKey(getPublicKeyRequest);
135-
assertNotNull(getPublicKeyResponse, "Response");
133+
assert getPublicKeyResponse != null;
136134
SdkBytes spkiSdkBytes = getPublicKeyResponse.publicKey();
137-
assertNotNull(spkiSdkBytes, "public key info SdkBytes");
135+
assert spkiSdkBytes != null;
138136
byte[] spkiBytes = spkiSdkBytes.asByteArray();
139-
assertNotNull(spkiBytes, "public key info Bytes");
137+
assert spkiBytes != null;
140138
SubjectPublicKeyInfo spki = SubjectPublicKeyInfo.getInstance(spkiBytes);
141-
assertNotNull(spki, "public key info");
139+
assert spki != null;
142140
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
143141
PublicKey publicKey = converter.getPublicKey(spki);
144-
assertNotNull(publicKey, "public key");
142+
assert publicKey!= null;
145143
List<SigningAlgorithmSpec> signingAlgorithms = getPublicKeyResponse.signingAlgorithms();
146-
assertNotNull(signingAlgorithms, "signing algorithms");
147-
assertFalse(signingAlgorithms.isEmpty(), "signing algorithms empty");
148-
assertEquals(Collections.singletonList(SigningAlgorithmSpec.ECDSA_SHA_256), signingAlgorithms);
144+
assert signingAlgorithms!= null;
145+
assert !signingAlgorithms.isEmpty();
146+
assert Collections.singletonList(SigningAlgorithmSpec.ECDSA_SHA_256).equals( signingAlgorithms);
149147
}
150148
}
151149

@@ -180,7 +178,7 @@ public static X509Certificate selfSign(String keyId, String subjectDN, String si
180178
try ( KmsClient kmsClient = KmsClient.create() ) {
181179
GetPublicKeyResponse response = kmsClient.getPublicKey(GetPublicKeyRequest.builder().keyId(keyId).build());
182180
SubjectPublicKeyInfo spki = SubjectPublicKeyInfo.getInstance(response.publicKey().asByteArray());
183-
assertNotNull(spki, "public key info");
181+
assert spki != null;
184182
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
185183
publicKey = converter.getPublicKey(spki);
186184
}
@@ -240,9 +238,9 @@ public byte[] getSignature() {
240238
.message(SdkBytes.fromByteArray(outputStream.toByteArray()))
241239
.build();
242240
SignResponse signResponse = kmsClient.sign(signRequest);
243-
assertNotNull(signResponse, "SignResponse");
241+
assert signResponse != null;
244242
SdkBytes signatureSdkBytes = signResponse.signature();
245-
assertNotNull(signatureSdkBytes, "signature SdkBytes");
243+
assert signatureSdkBytes != null;
246244
return signatureSdkBytes.asByteArray();
247245
}
248246
}

jce-utimaco/src/test/java/com/itextpdf/signingexamples/jce/utimaco/TestJceAccess.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.itextpdf.signingexamples.jce.utimaco;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotNull;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
63

74
import java.io.ByteArrayInputStream;
85
import java.io.IOException;
@@ -33,17 +30,17 @@ void test() throws IOException, CryptoServerException, GeneralSecurityException
3330
ks.load(null, null);
3431

3532
Enumeration<String> aliases = ks.aliases();
36-
assertNotNull(aliases, "Key store did not provide an aliases enumeration.");
37-
assertTrue(aliases.hasMoreElements(), "Aliases enumeration is empty.");
33+
assert aliases != null;
34+
assert aliases.hasMoreElements();
3835
String alias = aliases.nextElement();
3936
System.out.printf("Alias name: %s\n", alias);
4037

4138
PrivateKey pk = (PrivateKey) ks.getKey(alias, "5678".toCharArray());
42-
assertNotNull(pk, "Key store did not provide a private key for the alias " + alias);
39+
assert pk != null;
4340

4441
Certificate[] chain = ks.getCertificateChain(alias);
45-
assertNotNull(chain, "Key store did not provide a certificate chain for the alias " + alias);
46-
assertNotEquals(0, chain.length, "Key store provided an empty certificate chain for the alias " + alias);
42+
assert chain != null;
43+
assert 0 != chain.length;
4744
for (Certificate certificate : chain)
4845
if (certificate instanceof X509Certificate)
4946
System.out.printf("Subject: %s\n", ((X509Certificate) certificate).getSubjectDN());

jce-utimaco/src/test/java/com/itextpdf/signingexamples/jce/utimaco/TestSignSimple.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Enumeration;
1818

1919
import org.bouncycastle.jce.provider.BouncyCastleProvider;
20-
import org.junit.jupiter.api.Assertions;
2120
import org.junit.jupiter.api.BeforeAll;
2221
import org.junit.jupiter.api.Test;
2322

@@ -110,12 +109,12 @@ void testSignSimpleGeneric() throws NumberFormatException, IOException, CryptoSe
110109
ks.load(null, pin);
111110

112111
Enumeration<String> aliases = ks.aliases();
113-
Assertions.assertTrue(aliases.hasMoreElements(), "No alias in CryptoServerProvider key store");
112+
assert aliases.hasMoreElements();
114113
String alias = aliases.nextElement();
115114
PrivateKey pk = (PrivateKey) ks.getKey(alias, pin);
116-
Assertions.assertNotNull(pk, "No key for alias");
115+
assert pk != null;
117116
Certificate[] chain = ks.getCertificateChain(alias);
118-
Assertions.assertNotNull(chain, "No chain for alias");
117+
assert chain != null;
119118

120119
IExternalSignature signature = new PrivateKeySignature(pk, "SHA256", provider.getName());
121120
try ( InputStream resource = getClass().getResourceAsStream("/circles.pdf");
@@ -157,12 +156,12 @@ void testSignSimpleGenericPss() throws NumberFormatException, IOException, Crypt
157156
ks.load(null, pin);
158157

159158
Enumeration<String> aliases = ks.aliases();
160-
Assertions.assertTrue(aliases.hasMoreElements(), "No alias in CryptoServerProvider key store");
159+
assert aliases.hasMoreElements();
161160
String alias = aliases.nextElement();
162161
PrivateKey pk = (PrivateKey) ks.getKey(alias, pin);
163-
Assertions.assertNotNull(pk, "No key for alias");
162+
assert pk != null;
164163
Certificate[] chain = ks.getCertificateChain(alias);
165-
Assertions.assertNotNull(chain, "No chain for alias");
164+
assert chain != null;
166165

167166
String digestName = "SHA-256";
168167
IExternalSignature signature = new PrivateKeySignature(pk, digestName, "RSASSA-PSS", provider.getName(), RSASSAPSSMechanismParams.createForDigestAlgorithm(digestName)) {

pkcs11-java11/src/test/java/com/itextpdf/signingexamples/pkcs11/dtrust/TestIaikPkcs11Access.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.itextpdf.signingexamples.pkcs11.dtrust;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotNull;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
73
import java.io.IOException;
84
import java.security.GeneralSecurityException;
95
import java.security.Key;
@@ -41,8 +37,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
4137
tokenKeyStore.load(null, null);
4238

4339
Enumeration<String> aliases = tokenKeyStore.aliases();
44-
assertNotNull(aliases, "Key store did not provide an aliases enumeration.");
45-
assertTrue(aliases.hasMoreElements(), "Aliases enumeration is empty.");
40+
assert aliases != null;
41+
assert aliases.hasMoreElements();
4642
while (aliases.hasMoreElements()) {
4743
String alias = aliases.nextElement();
4844
System.out.printf("Alias name: %s\n", alias);
@@ -55,8 +51,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
5551
}
5652

5753
Certificate[] chain = tokenKeyStore.getCertificateChain(alias);
58-
assertNotNull(chain, "Key store did not provide a certificate chain for the alias " + alias);
59-
assertNotEquals(0, chain.length, "Key store provided an empty certificate chain for the alias " + alias);
54+
assert chain != null;
55+
assert 0 != chain.length;
6056
for (Certificate certificate : chain)
6157
if (certificate instanceof X509Certificate)
6258
System.out.printf("Subject: %s\n", ((X509Certificate) certificate).getSubjectDN());

pkcs11-java11/src/test/java/com/itextpdf/signingexamples/pkcs11/generic/TestPkcs11Access.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.itextpdf.signingexamples.pkcs11.generic;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotNull;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
73
import java.io.IOException;
84
import java.security.GeneralSecurityException;
95
import java.security.KeyStore;
@@ -35,20 +31,20 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
3531
String config = TestEnvironment.getPkcs11Config();
3632

3733
Provider p = Security.getProvider("SunPKCS11");
38-
assertNotNull(p, "Could not find SunPKCS11 provider.");
34+
assert p!= null;
3935

4036
Provider providerPKCS11 = p.configure(config);
41-
assertNotNull(providerPKCS11, "No provider generated for PKCS#11 configuration.");
37+
assert providerPKCS11!= null;
4238
Security.addProvider(providerPKCS11);
4339
System.out.printf("Provider name: %s\n", providerPKCS11.getName());
4440

4541
KeyStore ks = KeyStore.getInstance("PKCS11", providerPKCS11);
46-
assertNotNull(ks, "Provider did not provide a key store.");
42+
assert ks != null;
4743
ks.load(null, TestEnvironment.getPkcs11Pin());
4844

4945
Enumeration<String> aliases = ks.aliases();
50-
assertNotNull(aliases, "Key store did not provide an aliases enumeration.");
51-
assertTrue(aliases.hasMoreElements(), "Aliases enumeration is empty.");
46+
assert aliases != null;
47+
assert aliases.hasMoreElements();
5248
while (aliases.hasMoreElements()) {
5349
String alias = aliases.nextElement();
5450
System.out.printf("Alias name: %s\n", alias);
@@ -58,8 +54,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
5854
continue;
5955

6056
Certificate[] chain = ks.getCertificateChain(alias);
61-
assertNotNull(chain, "Key store did not provide a certificate chain for the alias " + alias);
62-
assertNotEquals(0, chain.length, "Key store provided an empty certificate chain for the alias " + alias);
57+
assert chain != null;
58+
assert 0 != chain.length;
6359
for (Certificate certificate : chain)
6460
if (certificate instanceof X509Certificate)
6561
System.out.printf("Subject: %s\n", ((X509Certificate) certificate).getSubjectDN());

pkcs11/src/test/java/com/itextpdf/signingexamples/pkcs11/dtrust/TestIaikPkcs11Access.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.itextpdf.signingexamples.pkcs11.dtrust;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotNull;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
73
import java.io.IOException;
84
import java.security.GeneralSecurityException;
95
import java.security.Key;
@@ -40,8 +36,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
4036
tokenKeyStore.load(null, null);
4137

4238
Enumeration<String> aliases = tokenKeyStore.aliases();
43-
assertNotNull(aliases, "Key store did not provide an aliases enumeration.");
44-
assertTrue(aliases.hasMoreElements(), "Aliases enumeration is empty.");
39+
assert aliases != null;
40+
assert aliases.hasMoreElements();
4541
while (aliases.hasMoreElements()) {
4642
String alias = aliases.nextElement();
4743
System.out.printf("Alias name: %s\n", alias);
@@ -54,8 +50,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
5450
}
5551

5652
Certificate[] chain = tokenKeyStore.getCertificateChain(alias);
57-
assertNotNull(chain, "Key store did not provide a certificate chain for the alias " + alias);
58-
assertNotEquals(0, chain.length, "Key store provided an empty certificate chain for the alias " + alias);
53+
assert chain != null;
54+
assert 0 != chain.length;
5955
for (Certificate certificate : chain)
6056
if (certificate instanceof X509Certificate)
6157
System.out.printf("Subject: %s\n", ((X509Certificate) certificate).getSubjectDN());

pkcs11/src/test/java/com/itextpdf/signingexamples/pkcs11/generic/TestPkcs11Access.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.itextpdf.signingexamples.pkcs11.generic;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotNull;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
73
import java.io.IOException;
84
import java.security.GeneralSecurityException;
95
import java.security.KeyStore;
@@ -37,17 +33,17 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
3733
String config = TestEnvironment.getPkcs11Config();
3834

3935
Provider providerPKCS11 = new SunPKCS11(config);
40-
assertNotNull(providerPKCS11, "No provider generated for PKCS#11 configuration.");
36+
assert providerPKCS11!= null;
4137
Security.addProvider(providerPKCS11);
4238
System.out.printf("Provider name: %s\n", providerPKCS11.getName());
4339

4440
KeyStore ks = KeyStore.getInstance("PKCS11", providerPKCS11);
45-
assertNotNull(ks, "Provider did not provide a key store.");
41+
assert ks != null;
4642
ks.load(null, TestEnvironment.getPkcs11Pin());
4743

4844
Enumeration<String> aliases = ks.aliases();
49-
assertNotNull(aliases, "Key store did not provide an aliases enumeration.");
50-
assertTrue(aliases.hasMoreElements(), "Aliases enumeration is empty.");
45+
assert aliases != null;
46+
assert aliases.hasMoreElements();
5147
while (aliases.hasMoreElements()) {
5248
String alias = aliases.nextElement();
5349
System.out.printf("Alias name: %s\n", alias);
@@ -57,8 +53,8 @@ void testAccessKeyAndCertificate() throws GeneralSecurityException, IOException
5753
continue;
5854

5955
Certificate[] chain = ks.getCertificateChain(alias);
60-
assertNotNull(chain, "Key store did not provide a certificate chain for the alias " + alias);
61-
assertNotEquals(0, chain.length, "Key store provided an empty certificate chain for the alias " + alias);
56+
assert chain != null;
57+
assert 0 != chain.length;
6258
for (Certificate certificate : chain)
6359
if (certificate instanceof X509Certificate)
6460
System.out.printf("Subject: %s\n", ((X509Certificate) certificate).getSubjectDN());

simple/src/test/java/com/itextpdf/signingexamples/jcajce/CreateSignatureAppearance.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Enumeration;
1515

1616
import org.bouncycastle.jce.provider.BouncyCastleProvider;
17-
import org.junit.jupiter.api.Assertions;
1817
import org.junit.jupiter.api.BeforeAll;
1918
import org.junit.jupiter.api.Test;
2019

@@ -606,7 +605,6 @@ void createSpecialAppearance(PdfSignatureFormField field, PdfDocument pdfDocumen
606605

607606
@Test
608607
public void testSignInNewHierarchicalField() throws IOException, GeneralSecurityException {
609-
Assertions.assertThrows(IllegalArgumentException.class, () -> {
610608
try ( InputStream resource = getClass().getResourceAsStream("/Blank.pdf");
611609
PdfReader pdfReader = new PdfReader(resource);
612610
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-SignInNewHierarchicalField.pdf")) ) {
@@ -621,7 +619,9 @@ public void testSignInNewHierarchicalField() throws IOException, GeneralSecurity
621619

622620
IExternalSignature pks = new PrivateKeySignature(pk, "SHA256", BouncyCastleProvider.PROVIDER_NAME);
623621
pdfSigner.signDetached(new BouncyCastleDigest(), pks, chain, null, null, null, 0, CryptoStandard.CMS);
624-
}});
622+
} catch (IllegalArgumentException ex) {
623+
assert true;
624+
}
625625
}
626626

627627
@Test

0 commit comments

Comments
 (0)