kdfCalculator = factory.createKDFCalculator(FipsKDF.HKDF.withPRF(
+ AgreementKDFPRF.SHA256_HMAC).using(extractedKey).withIV(info));
+ byte[] hkdf = new byte[32];
+ kdfCalculator.generateBytes(hkdf);
+ return hkdf;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public byte[] generateHMACSHA256Token(byte[] key, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException {
+ Mac mac = Mac.getInstance("HMacSHA256", this.getProvider());
+ mac.init(new SecretKeySpec(key, "RawBytes"));
+ return mac.doFinal(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException {
+ Cipher cipher = Cipher.getInstance("AESWrap", this.getProvider());
+ cipher.init(Cipher.WRAP_MODE, new SecretKeySpec(kek, "AESWrap"));
+ return cipher.wrap(new SecretKeySpec(key, "AESWrap"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException {
+ Cipher cipher = Cipher.getInstance("AESWrap", this.getProvider());
+ cipher.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, "AESWrap"));
+ return cipher.unwrap(key, "AESWrap", Cipher.SECRET_KEY).getEncoded();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IGCMBlockCipher createGCMBlockCipher() {
+ Cipher cipher = null;
+ try {
+ cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName());
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
+ // Ignore.
+ }
+ return new GCMBlockCipherBCFips(cipher);
+ }
}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsTestConstantsFactory.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsTestConstantsFactory.java
index 7c5835538e..2f2027f4ab 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsTestConstantsFactory.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsTestConstantsFactory.java
@@ -32,6 +32,6 @@ class BouncyCastleFipsTestConstantsFactory implements IBouncyCastleTestConstants
@Override
public String getCertificateInfoTestConst() {
- return "DEF length 8 object truncated by 4";
+ return "corrupted stream - out of bounds length found: 8 >= 6";
}
}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1EncodableVectorBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1EncodableVectorBCFips.java
index 317a8cf356..fe33bcdc5f 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1EncodableVectorBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1EncodableVectorBCFips.java
@@ -120,6 +120,14 @@ public void addOptional(IAlgorithmIdentifier element) {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ return encodableVector.size();
+ }
+
/**
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
*/
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1OutputStreamBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1OutputStreamBCFips.java
index 3eafb3f904..c3170f45ff 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1OutputStreamBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/ASN1OutputStreamBCFips.java
@@ -42,7 +42,7 @@ public class ASN1OutputStreamBCFips implements IASN1OutputStream {
* @param stream OutputStream to create {@link ASN1OutputStream} to be wrapped
*/
public ASN1OutputStreamBCFips(OutputStream stream) {
- this.stream = new ASN1OutputStream(stream);
+ this.stream = ASN1OutputStream.create(stream);
}
/**
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/x500/X500NameBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/x500/X500NameBCFips.java
index 41d6f36acb..aa2cf677a2 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/x500/X500NameBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/x500/X500NameBCFips.java
@@ -25,6 +25,8 @@ This file is part of the iText (R) project.
import com.itextpdf.bouncycastlefips.asn1.ASN1EncodableBCFips;
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
+import java.io.IOException;
+import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
/**
@@ -48,4 +50,14 @@ public X500NameBCFips(X500Name x500Name) {
public X500Name getX500Name() {
return (X500Name) getEncodable();
}
+
+ @Override
+ public String getName(){
+ try {
+ return new X500Principal(getX500Name().getEncoded()).getName();
+ } catch (IOException e) {
+ // should never happen
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/BasicOCSPRespBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/BasicOCSPRespBCFips.java
index 5e2eef7a2e..fc1b60a7da 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/BasicOCSPRespBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/BasicOCSPRespBCFips.java
@@ -30,13 +30,13 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.bouncycastle.asn1.IASN1ObjectIdentifier;
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
import com.itextpdf.commons.bouncycastle.cert.ocsp.IBasicOCSPResp;
+import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
import com.itextpdf.commons.bouncycastle.cert.ocsp.ISingleResp;
import com.itextpdf.commons.bouncycastle.operator.IContentVerifierProvider;
import java.io.IOException;
import java.util.Date;
import java.util.Objects;
-
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.ocsp.BasicOCSPResp;
@@ -134,6 +134,14 @@ public IASN1Encodable getExtensionParsedValue(IASN1ObjectIdentifier objectIdenti
return new ASN1EncodableBCFips(extension == null ? null : extension.getParsedValue());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IRespID getResponderId() {
+ return new RespIDBCFips(basicOCSPResp.getResponderId());
+ }
+
/**
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
*/
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/RespIDBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/RespIDBCFips.java
index b8c4d9e336..0ae0d19a77 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/RespIDBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/RespIDBCFips.java
@@ -25,6 +25,7 @@ This file is part of the iText (R) project.
import com.itextpdf.bouncycastlefips.asn1.x500.X500NameBCFips;
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
+import com.itextpdf.commons.bouncycastle.cert.ocsp.IResponderID;
import java.util.Objects;
import org.bouncycastle.cert.ocsp.RespID;
@@ -53,6 +54,14 @@ public RespIDBCFips(IX500Name x500Name) {
this(new RespID(((X500NameBCFips) x500Name).getX500Name()));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IResponderID toASN1Primitive() {
+ return new ResponderIDBCFips(respID.toASN1Primitive());
+ }
+
/**
* Gets actual org.bouncycastle object being wrapped.
*
@@ -92,4 +101,5 @@ public int hashCode() {
public String toString() {
return respID.toString();
}
+
}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/ResponderIDBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/ResponderIDBCFips.java
new file mode 100644
index 0000000000..9f44006203
--- /dev/null
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/ResponderIDBCFips.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.bouncycastlefips.cert.ocsp;
+
+import com.itextpdf.bouncycastlefips.asn1.x500.X500NameBCFips;
+import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
+import com.itextpdf.commons.bouncycastle.cert.ocsp.IResponderID;
+
+import org.bouncycastle.asn1.ocsp.ResponderID;
+
+/**
+ * Wrapper class for {@link ResponderID}.
+ */
+public class ResponderIDBCFips implements IResponderID {
+ private final ResponderID responderID;
+
+ /**
+ * Creates new wrapper instance for {@link ResponderID}.
+ *
+ * @param responderID {@link ResponderID} to be wrapped
+ */
+ public ResponderIDBCFips(ResponderID responderID) {
+ this.responderID = responderID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IX500Name getName() {
+ return new X500NameBCFips(responderID.getName());
+ }
+
+ /**
+ * Gets actual org.bouncycastle object being wrapped.
+ *
+ * @return wrapped {@link ResponderID}.
+ */
+ public ResponderID getResponderID() {
+ return responderID;
+ }
+}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/crypto/modes/GCMBlockCipherBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/crypto/modes/GCMBlockCipherBCFips.java
new file mode 100644
index 0000000000..25574ae9db
--- /dev/null
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/crypto/modes/GCMBlockCipherBCFips.java
@@ -0,0 +1,139 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.bouncycastlefips.crypto.modes;
+
+import com.itextpdf.commons.bouncycastle.crypto.modes.IGCMBlockCipher;
+import javax.crypto.Cipher;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.GeneralSecurityException;
+import java.util.Objects;
+
+/**
+ * This class provides the functionality of a cryptographic cipher of aes-gcm for encryption and decryption via
+ * wrapping and correctly populating {@link Cipher} class.
+ */
+public class GCMBlockCipherBCFips implements IGCMBlockCipher {
+ private final Cipher cipher;
+ private boolean forEncryption;
+ private int macSize;
+
+ /**
+ * Creates new aes-gcm block cipher class.
+ *
+ * @param cipher crypto instance to populate for aes-gcm encryption
+ */
+ public GCMBlockCipherBCFips(Cipher cipher) {
+ this.cipher = cipher;
+ }
+
+ /**
+ * Gets actual aes-gcm cipher being wrapped.
+ *
+ * @return wrapped {@link Cipher}
+ */
+ public Cipher getCipher() {
+ return cipher;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(boolean forEncryption, byte[] key, int macSizeBits, byte[] iv) throws GeneralSecurityException {
+ cipher.init(forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE,
+ new SecretKeySpec(key, "AES"), new GCMParameterSpec(macSizeBits, iv));
+ this.forEncryption = forEncryption;
+ this.macSize = macSizeBits / 8;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getUpdateOutputSize(int len) {
+ int size;
+ if (this.forEncryption) {
+ size = getOutputSize(len) - this.macSize;
+ } else {
+ size = getOutputSize(len);
+ }
+
+ return size - size % 16;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processBytes(byte[] input, int inputOffset, int len, byte[] output, int outOffset) throws GeneralSecurityException {
+ cipher.update(input, inputOffset, len, output, outOffset);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getOutputSize(int len) {
+ return cipher.getOutputSize(len);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doFinal(byte[] plainText, int i) throws GeneralSecurityException {
+ cipher.doFinal(plainText, i);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GCMBlockCipherBCFips that = (GCMBlockCipherBCFips) o;
+ return Objects.equals(cipher, that.cipher);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(cipher);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return cipher.toString();
+ }
+}
diff --git a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/tsp/TimeStampRequestGeneratorBCFips.java b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/tsp/TimeStampRequestGeneratorBCFips.java
index 92e2882bf5..60d145fb66 100644
--- a/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/tsp/TimeStampRequestGeneratorBCFips.java
+++ b/bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/tsp/TimeStampRequestGeneratorBCFips.java
@@ -29,6 +29,7 @@ This file is part of the iText (R) project.
import java.math.BigInteger;
import java.util.Objects;
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.tsp.TimeStampRequestGenerator;
/**
@@ -68,7 +69,7 @@ public void setCertReq(boolean var1) {
*/
@Override
public void setReqPolicy(String reqPolicy) {
- requestGenerator.setReqPolicy(reqPolicy);
+ requestGenerator.setReqPolicy(new ASN1ObjectIdentifier(reqPolicy));
}
/**
diff --git a/commons/pom.xml b/commons/pom.xml
index ffd184a730..15d2d0d72c 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -5,7 +5,7 @@
com.itextpdf
root
- 8.0.5
+ 9.0.0
commons
diff --git a/commons/src/main/java/com/itextpdf/commons/actions/EventManager.java b/commons/src/main/java/com/itextpdf/commons/actions/EventManager.java
index 76aad0e5db..397482425b 100644
--- a/commons/src/main/java/com/itextpdf/commons/actions/EventManager.java
+++ b/commons/src/main/java/com/itextpdf/commons/actions/EventManager.java
@@ -44,7 +44,7 @@ private EventManager() {
}
/**
- * Allows an access to the instance of EventManager.
+ * Allows access to the instance of EventManager.
*
* @return the instance of the class
*/
diff --git a/commons/src/main/java/com/itextpdf/commons/actions/IEvent.java b/commons/src/main/java/com/itextpdf/commons/actions/IEvent.java
index e9651280b5..de5cab0e07 100644
--- a/commons/src/main/java/com/itextpdf/commons/actions/IEvent.java
+++ b/commons/src/main/java/com/itextpdf/commons/actions/IEvent.java
@@ -24,7 +24,6 @@ This file is part of the iText (R) project.
/**
* Base marker interface for any generated event of any source.
- *
*/
public interface IEvent {
}
diff --git a/commons/src/main/java/com/itextpdf/commons/actions/data/CommonsProductData.java b/commons/src/main/java/com/itextpdf/commons/actions/data/CommonsProductData.java
index 0e97fd68e9..8f444b9ba1 100644
--- a/commons/src/main/java/com/itextpdf/commons/actions/data/CommonsProductData.java
+++ b/commons/src/main/java/com/itextpdf/commons/actions/data/CommonsProductData.java
@@ -28,7 +28,7 @@ This file is part of the iText (R) project.
public final class CommonsProductData {
static final String COMMONS_PUBLIC_PRODUCT_NAME = "Commons";
static final String COMMONS_PRODUCT_NAME = "commons";
- static final String COMMONS_VERSION = "8.0.5";
+ static final String COMMONS_VERSION = "9.0.0";
static final String MINIMAL_COMPATIBLE_LICENSEKEY_VERSION = "4.1.0";
static final int COMMONS_COPYRIGHT_SINCE = 2000;
static final int COMMONS_COPYRIGHT_TO = 2024;
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java
index d5e7f2d0ae..5bea97831a 100644
--- a/commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java
@@ -115,6 +115,7 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.bouncycastle.cms.jcajce.IJcaSimpleSignerInfoVerifierBuilder;
import com.itextpdf.commons.bouncycastle.cms.jcajce.IJceKeyAgreeEnvelopedRecipient;
import com.itextpdf.commons.bouncycastle.cms.jcajce.IJceKeyTransEnvelopedRecipient;
+import com.itextpdf.commons.bouncycastle.crypto.modes.IGCMBlockCipher;
import com.itextpdf.commons.bouncycastle.openssl.IPEMParser;
import com.itextpdf.commons.bouncycastle.openssl.jcajce.IJcaPEMKeyConverter;
import com.itextpdf.commons.bouncycastle.openssl.jcajce.IJceOpenSSLPKCS8DecryptorProviderBuilder;
@@ -137,6 +138,8 @@ This file is part of the iText (R) project.
import java.io.Reader;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
@@ -1382,6 +1385,15 @@ ITimeStampTokenGenerator createTimeStampTokenGenerator(ISignerInfoGenerator siGe
*/
IX500Name createX500Name(String s);
+ /**
+ * Create X500 Name wrapper from {@link IASN1Sequence}.
+ *
+ * @param s {@link IASN1Sequence} to create X500 Name wrapper from
+ *
+ * @return created X500 Name wrapper
+ */
+ IX500Name createX500Name(IASN1Sequence s);
+
/**
* Create resp ID wrapper from X500 Name wrapper.
*
@@ -1677,4 +1689,59 @@ byte[] createCipherBytes(X509Certificate x509certificate, byte[] abyte0, IAlgori
* @param withCertificate true when used with a certificate, false otherwise
*/
void isEncryptionFeatureSupported(int encryptionAlgorithm, boolean withCertificate);
+
+ /**
+ * Generates byte array based on extract-and-expand key derivation function, using provided parameters.
+ *
+ * @param inputKey {@code byte[]} input key material
+ * @param salt {@code byte[]} salt
+ * @param info {@code byte[]} info
+ *
+ * @return {@code byte[]} key derivation function result.
+ */
+ byte[] generateHKDF(byte[] inputKey, byte[] salt, byte[] info);
+
+ /**
+ * Generates byte array based MAC token according to HMACSHA256 algorithm.
+ *
+ * @param key {@code byte[]} MAC key
+ * @param data {@code byte[]} data to be encrypted
+ *
+ * @return byte array based MAC token.
+ *
+ * @throws NoSuchAlgorithmException if there is no such algorithm.
+ * @throws InvalidKeyException if key is invalid.
+ */
+ byte[] generateHMACSHA256Token(byte[] key, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException;
+
+ /**
+ * Generates encrypted key based on AES256 without padding wrapping algorithm.
+ *
+ * @param key key to be encrypted
+ * @param kek key encryption key to be used
+ *
+ * @return encrypted key.
+ *
+ * @throws GeneralSecurityException in case of encryption related exceptions.
+ */
+ byte[] generateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException;
+
+ /**
+ * Generates decrypted key based on AES256 without padding unwrapping algorithm.
+ *
+ * @param key key to be decrypted
+ * @param kek key encryption key to be used
+ *
+ * @return decrypted key.
+ *
+ * @throws GeneralSecurityException in case of encryption related exceptions.
+ */
+ byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) throws GeneralSecurityException;
+
+ /**
+ * Returns a Block Cipher object that implements the aes-gcm transformation.
+ *
+ * @return {@link IGCMBlockCipher} instance with provider specific implementation
+ */
+ IGCMBlockCipher createGCMBlockCipher();
}
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/IASN1EncodableVector.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/IASN1EncodableVector.java
index 34b12c7d5f..1566f1223e 100644
--- a/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/IASN1EncodableVector.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/IASN1EncodableVector.java
@@ -71,4 +71,11 @@ public interface IASN1EncodableVector {
* @param element AlgorithmIdentifier wrapper.
*/
void addOptional(IAlgorithmIdentifier element);
+
+ /**
+ * Calls actual {@code size} method for the wrapped ASN1EncodableVector object.
+ *
+ * @return {@code int} representing current vector size
+ */
+ int size();
}
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/x500/IX500Name.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/x500/IX500Name.java
index 8ae58e48a7..d3768ed987 100644
--- a/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/x500/IX500Name.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/x500/IX500Name.java
@@ -29,4 +29,10 @@ This file is part of the iText (R) project.
* to switch between bouncy-castle and bouncy-castle FIPS implementations.
*/
public interface IX500Name extends IASN1Encodable {
+ /**
+ * Gets the RFC2253 name.
+ *
+ * @return the RFC2253 name
+ */
+ String getName();
}
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IBasicOCSPResp.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IBasicOCSPResp.java
index 239f975967..86f6583e40 100644
--- a/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IBasicOCSPResp.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IBasicOCSPResp.java
@@ -85,4 +85,12 @@ public interface IBasicOCSPResp {
* @return wrapped extension parsed value.
*/
IASN1Encodable getExtensionParsedValue(IASN1ObjectIdentifier objectIdentifier);
+
+
+ /**
+ * Calls actual {@code getEncoded} method for the wrapped BasicOCSPResp object.
+ *
+ * @return the Responder Id
+ */
+ IRespID getResponderId();
}
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IRespID.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IRespID.java
index 93c5f0e96b..a4161e3707 100644
--- a/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IRespID.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IRespID.java
@@ -27,4 +27,10 @@ This file is part of the iText (R) project.
* to switch between bouncy-castle and bouncy-castle FIPS implementations.
*/
public interface IRespID {
+ /**
+ * Calls actual {@code toASN1Primitive} method for the wrapped BasicOCSPResp object.
+ *
+ * @return Responder ID as a ASN1 primitive.
+ */
+ IResponderID toASN1Primitive();
}
diff --git a/kernel/src/main/java/com/itextpdf/kernel/events/IEventHandler.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IResponderID.java
similarity index 70%
rename from kernel/src/main/java/com/itextpdf/kernel/events/IEventHandler.java
rename to commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IResponderID.java
index a0870266ab..c723b95d4a 100644
--- a/kernel/src/main/java/com/itextpdf/kernel/events/IEventHandler.java
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/cert/ocsp/IResponderID.java
@@ -20,19 +20,19 @@ This file is part of the iText (R) project.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
-package com.itextpdf.kernel.events;
+package com.itextpdf.commons.bouncycastle.cert.ocsp;
+
+import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
/**
- * Interface for handling events. EventHandlers are added to the {@link EventDispatcher}.
+ * This interface represents the wrapper for ResponderID that provides the ability
+ * to switch between bouncy-castle and bouncy-castle FIPS implementations.
*/
-public interface IEventHandler {
-
+public interface IResponderID {
/**
- * Hook for handling events. Implementations can access the PdfDocument instance
- * associated to the specified Event or, if available, the PdfPage instance.
+ * Calls actual {@code getName} method for the wrapped BasicOCSPResp object.
*
- * @param event the Event that needs to be processed
+ * @return wrapped X500NAme.
*/
- void handleEvent(Event event);
-
+ IX500Name getName();
}
diff --git a/commons/src/main/java/com/itextpdf/commons/bouncycastle/crypto/modes/IGCMBlockCipher.java b/commons/src/main/java/com/itextpdf/commons/bouncycastle/crypto/modes/IGCMBlockCipher.java
new file mode 100644
index 0000000000..ca6d3d43f2
--- /dev/null
+++ b/commons/src/main/java/com/itextpdf/commons/bouncycastle/crypto/modes/IGCMBlockCipher.java
@@ -0,0 +1,90 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.bouncycastle.crypto.modes;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * Interface for aes-gcm cryptographic ciphers.
+ */
+public interface IGCMBlockCipher {
+
+ /**
+ * Initialize this cipher with a key and a set of algorithm parameters.
+ *
+ * @param forEncryption true to use encrypt mode, false to use decrypt mode
+ * @param key the encryption key
+ * @param macSizeBits MAC size, MAC sizes from 32 bits to 128 bits (must be a multiple of 8)
+ * @param iv the IV source buffer
+ *
+ * @throws GeneralSecurityException in case any error during encryption or decryption
+ */
+ void init(boolean forEncryption, byte[] key, int macSizeBits, byte[] iv) throws GeneralSecurityException;
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be in order to hold the result of
+ * the next update operation, given the input length (in bytes).
+ *
+ * @param len input length (in bytes)
+ *
+ * @return output length in bytes
+ */
+ int getUpdateOutputSize(int len);
+
+ /**
+ * Perform a multiple-part encryption or decryption operation (depending on how this cipher was initialized),
+ * processing another data part.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in input where the input starts
+ * @param len the input length
+ * @param output the buffer for the result
+ * @param outOffset the offset in output where the result is stored
+ *
+ * @throws GeneralSecurityException in case any error during encryption or decryption
+ */
+ void processBytes(byte[] input, int inputOffset, int len, byte[] output, int outOffset)
+ throws GeneralSecurityException;
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be in order to hold the result of
+ * the next doFinal operation, given the input length (in bytes).
+ *
+ * @param len input length (in bytes)
+ *
+ * @return output length in bytes
+ */
+ int getOutputSize(int len);
+
+ /**
+ * Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialized.
+ * Input data that may have been buffered during a previous update operation is processed, also
+ * the authentication tag is appended in the case of encryption, or verified in the case of decryption.
+ *
+ * @param plainText the buffer for the result
+ * @param i the offset in output where the result is stored
+ *
+ * @throws GeneralSecurityException in case any error during encryption or decryption
+ */
+ void doFinal(byte[] plainText, int i) throws GeneralSecurityException;
+}
diff --git a/commons/src/main/java/com/itextpdf/commons/datastructures/ISimpleList.java b/commons/src/main/java/com/itextpdf/commons/datastructures/ISimpleList.java
new file mode 100644
index 0000000000..0a0d006ab9
--- /dev/null
+++ b/commons/src/main/java/com/itextpdf/commons/datastructures/ISimpleList.java
@@ -0,0 +1,96 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.datastructures;
+
+/**
+ * Interface for a simple list abstraction.
+ *
+ * This interface is a subset of the {@link java.util.List} interface.
+ * It is intended to be used in cases where the full {@link java.util.List} interface is not needed.
+ *
+ * @param The type of elements in this list.
+ */
+public interface ISimpleList {
+ /**
+ * Adds an element to the end of the list.
+ *
+ * @param element the element to add
+ */
+ void add(T element);
+
+ /**
+ * Adds an element to the list at the specified index.
+ *
+ * @param index the index at which to add the element
+ * @param element the element to add
+ */
+ void add(int index, T element);
+
+ /**
+ * Returns the element at the specified index.
+ *
+ * @param index the index of the element to return
+ * @return the element at the specified index
+ */
+ T get(int index);
+
+ /**
+ * Replaces the element at the specified index with the specified element.
+ *
+ * @param index the index of the element to replace
+ * @param element the element to be stored at the specified index
+ * @return the element previously at the specified index
+ */
+ T set(int index, T element);
+
+ /**
+ * Returns the index of the first occurrence of the specified element in the list,
+ * or -1 if the list does not contain the element.
+ *
+ * @param element the element to search for
+ * @return the index of the first occurrence of the specified element in the list,
+ * or -1 if the list does not contain the element
+ */
+ int indexOf(Object element);
+
+ /**
+ * Removes the element at the specified index.
+ *
+ * @param index the index of the element to be removed
+ */
+ void remove(int index);
+
+ /**
+ * Returns the number of elements in the list.
+ *
+ * @return the number of elements in the list
+ */
+ int size();
+
+ /**
+ * Returns {@code true} if the list contains no elements, false otherwise.
+ *
+ * @return {@code true} if the list contains no elements, false otherwise
+ */
+ boolean isEmpty();
+}
diff --git a/commons/src/main/java/com/itextpdf/commons/datastructures/NullUnlimitedList.java b/commons/src/main/java/com/itextpdf/commons/datastructures/NullUnlimitedList.java
new file mode 100644
index 0000000000..32078858fc
--- /dev/null
+++ b/commons/src/main/java/com/itextpdf/commons/datastructures/NullUnlimitedList.java
@@ -0,0 +1,167 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.datastructures;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The class represents a list which allows null elements, but doesn't allocate a memory for them, in the rest of
+ * cases it behaves like usual {@link ArrayList} and should have the same complexity (because keys are unique
+ * integers, so collisions are impossible).
+ *
+ * @param elements of the list
+ */
+public final class NullUnlimitedList implements ISimpleList {
+ private final Map map = new HashMap<>();
+ private int size = 0;
+
+ /**
+ * Creates a new instance of {@link NullUnlimitedList}.
+ */
+ public NullUnlimitedList() {
+ // Empty constructor
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void add(T element) {
+ if (element == null) {
+ size++;
+ } else {
+ int position = size++;
+ map.put(position, element);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * In worth scenario O(n^2) but it is mostly impossible because keys shouldn't have
+ * collisions at all (they are integers). So in average should be O(n).
+ */
+ @Override
+ public void add(int index, T element) {
+ if (index < 0 || index > size) {
+ return;
+ }
+ size++;
+ // Shifts the element currently at that position (if any) and any
+ // subsequent elements to the right (adds one to their indices).
+ T previous = map.get(index);
+ for (int i = index + 1; i < size; i++) {
+ T currentToAdd = previous;
+ previous = map.get(i);
+ this.set(i, currentToAdd);
+ }
+
+ this.set(index, element);
+ }
+
+ /**
+ * {@inheritDoc}
+ * average O(1), worth O(n) (mostly impossible in case when keys are integers)
+ */
+ @Override
+ public T get(int index) {
+ return map.get(index);
+ }
+
+ /**
+ * {@inheritDoc}
+ * average O(1), worth O(n) (mostly impossible in case when keys are integers)
+ */
+ @Override
+ public T set(int index, T element) {
+ if (element == null) {
+ map.remove(index);
+ } else {
+ map.put(index, element);
+ }
+ return element;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int indexOf(Object element) {
+ if (element == null) {
+ for (int i = 0; i < size; i++) {
+ if (!map.containsKey(i)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ for (Map.Entry entry : map.entrySet()) {
+ if (element.equals(entry.getValue())) {
+ return entry.getKey();
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * In worth scenario O(n^2) but it is mostly impossible because keys shouldn't have
+ * collisions at all (they are integers). So in average should be O(n).
+ *
+ * @param index the index of the element to be removed
+ */
+ @Override
+ public void remove(int index) {
+ if (index < 0 || index >= size) {
+ return;
+ }
+ map.remove(index);
+ // Shifts any subsequent elements to the left (subtracts one from their indices).
+ T previous = map.get(size - 1);
+ final int offset = 2;
+ for (int i = size - offset; i >= index; i--) {
+ T current = previous;
+ previous = map.get(i);
+ this.set(i, current);
+ }
+ map.remove(--size);
+ }
+
+ /**
+ * @return the size of the list
+ */
+ @Override
+ public int size() {
+ return size;
+ }
+
+ /**
+ * @return true if the list is empty, false otherwise
+ */
+ @Override
+ public boolean isEmpty() {
+ return size == 0;
+ }
+
+}
diff --git a/commons/src/main/java/com/itextpdf/commons/datastructures/SimpleArrayList.java b/commons/src/main/java/com/itextpdf/commons/datastructures/SimpleArrayList.java
new file mode 100644
index 0000000000..344d50bfe6
--- /dev/null
+++ b/commons/src/main/java/com/itextpdf/commons/datastructures/SimpleArrayList.java
@@ -0,0 +1,117 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.datastructures;
+
+import java.util.ArrayList;
+
+/**
+ * Portable implementation of {@link ArrayList}.
+ *
+ * @param the type of elements in this list
+ */
+public class SimpleArrayList implements ISimpleList {
+
+ private final ArrayList list;
+
+ /**
+ * Creates a new instance of {@link SimpleArrayList}.
+ */
+ public SimpleArrayList() {
+ this.list = new ArrayList<>();
+ }
+
+ /**
+ * Creates a new instance of {@link SimpleArrayList} with the specified initial capacity.
+ *
+ * @param initialCapacity the initial capacity of the list
+ */
+ public SimpleArrayList(int initialCapacity) {
+ this.list = new ArrayList<>(initialCapacity);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void add(T element) {
+ list.add(element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void add(int index, T element) {
+ list.add(index, element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T get(int index) {
+ return list.get(index);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T set(int index, T element) {
+ T value = list.get(index);
+ list.set(index, element);
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int indexOf(Object element) {
+ return list.indexOf((T) element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void remove(int index) {
+ list.remove(index);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEmpty() {
+ return list.isEmpty();
+ }
+}
diff --git a/commons/src/main/java/com/itextpdf/commons/utils/DIContainerConfigurations.java b/commons/src/main/java/com/itextpdf/commons/utils/DIContainerConfigurations.java
index 3b78f8db92..3770338587 100644
--- a/commons/src/main/java/com/itextpdf/commons/utils/DIContainerConfigurations.java
+++ b/commons/src/main/java/com/itextpdf/commons/utils/DIContainerConfigurations.java
@@ -32,7 +32,8 @@ private DIContainerConfigurations() {
}
private static final String[] DEFAULT_CONFIGURATIONS_CLASS = new String[] {
- "com.itextpdf.forms.util.RegisterDefaultDiContainer"
+ "com.itextpdf.forms.util.RegisterDefaultDiContainer",
+ "com.itextpdf.kernel.utils.RegisterDefaultDiContainer"
};
/**
diff --git a/commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java b/commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java
index 55bf1d1665..6e9c31479a 100644
--- a/commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java
+++ b/commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java
@@ -211,8 +211,8 @@ public static PrintWriter createPrintWriter(OutputStream output,
*
* @throws FileNotFoundException if file not found.
*/
- public static java.io.OutputStream getBufferedOutputStream(String filename) throws FileNotFoundException {
- return new BufferedOutputStream(new FileOutputStream(filename));
+ public static OutputStream getBufferedOutputStream(String filename) throws IOException {
+ return new BufferedOutputStream(getFileOutputStream(filename));
}
/**
@@ -267,10 +267,10 @@ public static File createTempFile(String path) throws IOException {
*
* @return {@code FileOutputStream} instance.
*
- * @throws FileNotFoundException in case file not found.
+ @throws IOException in file reading errors.
*/
- public static FileOutputStream getFileOutputStream(File tempFile) throws FileNotFoundException {
- return new FileOutputStream(tempFile);
+ public static OutputStream getFileOutputStream(File tempFile) throws IOException {
+ return Files.newOutputStream(tempFile.toPath());
}
/**
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedEventHandlerTest.java b/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedEventHandlerTest.java
index a4cc2918ca..f1748c3afd 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedEventHandlerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedEventHandlerTest.java
@@ -28,13 +28,12 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.ecosystem.ITextTestEvent;
import com.itextpdf.commons.ecosystem.TestMetaInfo;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AbstractContextBasedEventHandlerTest extends ExtendedITextTest {
@Test
@@ -43,7 +42,7 @@ public void coreEventProcessedByHandlerTest() {
handler.onEvent(new ITextTestEvent(new SequenceId(), null,
"test-event",
ProductNameConstant.ITEXT_CORE));
- Assert.assertTrue(handler.wasInvoked());
+ Assertions.assertTrue(handler.wasInvoked());
}
@Test
@@ -52,7 +51,7 @@ public void anotherProductEventNotProcessedByHandlerTest() {
handler.onEvent(new ITextTestEvent(new SequenceId(), null,
"test-event",
ProductNameConstant.PDF_HTML));
- Assert.assertTrue(handler.wasInvoked());
+ Assertions.assertTrue(handler.wasInvoked());
}
@Test
@@ -61,14 +60,14 @@ public void eventWithMetaInfoTest() {
handler.onEvent(new ITextTestEvent(new SequenceId(), new TestMetaInfo("meta info from iTextCore"),
"test-event",
ProductNameConstant.ITEXT_CORE));
- Assert.assertTrue(handler.wasInvoked());
+ Assertions.assertTrue(handler.wasInvoked());
}
@Test
public void notITextEventIsIgnoredTest() {
TestEventHandler handler = new TestEventHandler(UnknownContext.PERMISSIVE);
handler.onEvent(new UnknownEvent());
- Assert.assertFalse(handler.wasInvoked());
+ Assertions.assertFalse(handler.wasInvoked());
}
private static class TestEventHandler extends AbstractContextBasedEventHandler {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedITextEventTest.java b/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedITextEventTest.java
index 40e8dcb3c6..89925ae61f 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedITextEventTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/AbstractContextBasedITextEventTest.java
@@ -26,15 +26,13 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.data.CommonsProductData;
import com.itextpdf.commons.actions.data.ProductData;
import com.itextpdf.commons.ecosystem.TestMetaInfo;
-import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AbstractContextBasedITextEventTest extends ExtendedITextTest {
@Test
@@ -44,7 +42,7 @@ public void setMetaInfoTest() {
TestMetaInfo metaInfoAfter = new TestMetaInfo("meta-info-after");
e.setMetaInfo(metaInfoAfter);
- Assert.assertSame(metaInfoAfter, e.getMetaInfo());
+ Assertions.assertSame(metaInfoAfter, e.getMetaInfo());
}
@Test
@@ -54,9 +52,9 @@ public void resetMetaInfoForbiddenTest() {
BasicAbstractContextBasedITextEvent e =
new BasicAbstractContextBasedITextEvent(CommonsProductData.getInstance(), metaInfoBefore);
- Assert.assertSame(metaInfoBefore, e.getMetaInfo());
+ Assertions.assertSame(metaInfoBefore, e.getMetaInfo());
- Assert.assertFalse(e.setMetaInfo(metaInfoAfter));
+ Assertions.assertFalse(e.setMetaInfo(metaInfoAfter));
}
private static class BasicAbstractContextBasedITextEvent extends AbstractContextBasedITextEvent {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/AbstractITextConfigurationEventTest.java b/commons/src/test/java/com/itextpdf/commons/actions/AbstractITextConfigurationEventTest.java
index 57355e62b5..913fc045ca 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/AbstractITextConfigurationEventTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/AbstractITextConfigurationEventTest.java
@@ -27,19 +27,18 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.processors.ITextProductEventProcessor;
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
import java.util.List;
import java.util.Map;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AbstractITextConfigurationEventTest extends ExtendedITextTest {
- @After
+ @AfterEach
public void after() {
ProductEventHandler.INSTANCE.clearProcessors();
}
@@ -51,8 +50,8 @@ public void addProcessorTest() {
event.addProcessor(processor);
Map processors = ProductEventHandler.INSTANCE.getProcessors();
- Assert.assertEquals(1, processors.size());
- Assert.assertTrue(processors.values().contains(processor));
+ Assertions.assertEquals(1, processors.size());
+ Assertions.assertTrue(processors.values().contains(processor));
}
@Test
@@ -61,7 +60,7 @@ public void getProcessorsTest() {
ITextProductEventProcessor processor = new TestITextProductEventProcessor();
event.addProcessor(processor);
- Assert.assertEquals(ProductEventHandler.INSTANCE.getProcessors(), event.getProcessors());
+ Assertions.assertEquals(ProductEventHandler.INSTANCE.getProcessors(), event.getProcessors());
}
@Test
@@ -73,7 +72,7 @@ public void removeProcessorTest() {
event.removeProcessor(processor.getProductName());
Map processors = ProductEventHandler.INSTANCE.getProcessors();
- Assert.assertEquals(0, processors.size());
+ Assertions.assertEquals(0, processors.size());
}
@Test
@@ -82,7 +81,7 @@ public void getActiveProcessorTest() {
ITextProductEventProcessor processor = new TestITextProductEventProcessor();
event.addProcessor(processor);
- Assert.assertEquals(processor, event.getActiveProcessor(processor.getProductName()));
+ Assertions.assertEquals(processor, event.getActiveProcessor(processor.getProductName()));
}
@Test
@@ -93,8 +92,8 @@ public void addEventTest() {
configurationEvent.addEvent(id, processEvent);
List events = ProductEventHandler.INSTANCE.getEvents(id);
- Assert.assertEquals(1, events.size());
- Assert.assertEquals(processEvent, events.get(0));
+ Assertions.assertEquals(1, events.size());
+ Assertions.assertEquals(processEvent, events.get(0));
}
@Test
@@ -104,7 +103,7 @@ public void getEventsTest() {
configurationEvent.addEvent(id, new TestAbstractProductProcessITextEvent());
configurationEvent.addEvent(id, new TestAbstractProductProcessITextEvent());
- Assert.assertEquals(ProductEventHandler.INSTANCE.getEvents(id), configurationEvent.getEvents(id));
+ Assertions.assertEquals(ProductEventHandler.INSTANCE.getEvents(id), configurationEvent.getEvents(id));
}
static class TestAbstractITextConfigurationEvent extends AbstractITextConfigurationEvent {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/AbstractProductITextEventTest.java b/commons/src/test/java/com/itextpdf/commons/actions/AbstractProductITextEventTest.java
index bb2fade3d3..281e00c593 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/AbstractProductITextEventTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/AbstractProductITextEventTest.java
@@ -23,17 +23,16 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.actions;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AbstractProductITextEventTest extends ExtendedITextTest {
@Test
public void nullProductDataTest() {
Exception exception =
- Assert.assertThrows(IllegalStateException.class, () -> new AbstractProductITextEvent(null) {});
- Assert.assertEquals("ProductData shouldn't be null.", exception.getMessage());
+ Assertions.assertThrows(IllegalStateException.class, () -> new AbstractProductITextEvent(null) {});
+ Assertions.assertEquals("ProductData shouldn't be null.", exception.getMessage());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/AbstractStatisticsEventTest.java b/commons/src/test/java/com/itextpdf/commons/actions/AbstractStatisticsEventTest.java
index e951d00955..8bf5a04aee 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/AbstractStatisticsEventTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/AbstractStatisticsEventTest.java
@@ -27,15 +27,14 @@ This file is part of the iText (R) project.
import com.itextpdf.test.ExtendedITextTest;
import com.itextpdf.test.annotations.LogMessage;
import com.itextpdf.test.annotations.LogMessages;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
import java.util.Collections;
import java.util.List;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AbstractStatisticsEventTest extends ExtendedITextTest {
@Test
public void constructorTest() {
@@ -43,11 +42,11 @@ public void constructorTest() {
new DummyStatisticsEvent(new ProductData("public name", "product name", "version", 15, 3000));
ProductData data = dummyEvent.getProductData();
- Assert.assertEquals("public name", data.getPublicProductName());
- Assert.assertEquals("product name", data.getProductName());
- Assert.assertEquals("version", data.getVersion());
- Assert.assertEquals(15, data.getSinceCopyrightYear());
- Assert.assertEquals(3000, data.getToCopyrightYear());
+ Assertions.assertEquals("public name", data.getPublicProductName());
+ Assertions.assertEquals("product name", data.getProductName());
+ Assertions.assertEquals("version", data.getVersion());
+ Assertions.assertEquals(15, data.getSinceCopyrightYear());
+ Assertions.assertEquals(3000, data.getToCopyrightYear());
}
@Test
@@ -56,7 +55,7 @@ public void createStatisticsAggregatorFromNameTest() {
DummyStatisticsEvent dummyEvent =
new DummyStatisticsEvent(new ProductData("public name", "product name", "version", 15, 3000));
- Assert.assertNull(dummyEvent.createStatisticsAggregatorFromName("statisticsName"));
+ Assertions.assertNull(dummyEvent.createStatisticsAggregatorFromName("statisticsName"));
}
static class DummyStatisticsEvent extends AbstractStatisticsEvent {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/EventManagerTest.java b/commons/src/test/java/com/itextpdf/commons/actions/EventManagerTest.java
index 4294f9ed3f..3623da4d26 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/EventManagerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/EventManagerTest.java
@@ -33,18 +33,17 @@ This file is part of the iText (R) project.
import com.itextpdf.test.ExtendedITextTest;
import com.itextpdf.test.annotations.LogMessage;
import com.itextpdf.test.annotations.LogMessages;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.List;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class EventManagerTest extends ExtendedITextTest {
- @After
+ @AfterEach
public void afterEach() {
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
}
@@ -70,15 +69,15 @@ public void throwSomeExceptionsTest() {
try {
eventManager.onEvent(new ITextTestEvent(sequenceId, null, "test-event", ProductNameConstant.ITEXT_CORE));
} catch (AggregatedException e) {
- Assert.assertEquals("Error during event processing:\n"
+ Assertions.assertEquals("Error during event processing:\n"
+ "0) ThrowArithmeticExpHandler\n"
+ "1) ThrowIllegalArgumentExpHandler\n", e.getMessage());
List aggregatedExceptions = e.getAggregatedExceptions();
- Assert.assertEquals(2, aggregatedExceptions.size());
- Assert.assertEquals("ThrowArithmeticExpHandler", aggregatedExceptions.get(0).getMessage());
- Assert.assertEquals("ThrowIllegalArgumentExpHandler", aggregatedExceptions.get(1).getMessage());
+ Assertions.assertEquals(2, aggregatedExceptions.size());
+ Assertions.assertEquals("ThrowArithmeticExpHandler", aggregatedExceptions.get(0).getMessage());
+ Assertions.assertEquals("ThrowIllegalArgumentExpHandler", aggregatedExceptions.get(1).getMessage());
}
eventManager.unregister(handler1);
@@ -92,10 +91,10 @@ public void throwOneUncheckedExceptionsTest() {
eventManager.register(handler1);
try {
SequenceId sequenceId = new SequenceId();
- Exception exception = Assert.assertThrows(ArithmeticException.class,
+ Exception exception = Assertions.assertThrows(ArithmeticException.class,
() -> eventManager.onEvent(
new ITextTestEvent(sequenceId, null, "test-event", ProductNameConstant.ITEXT_CORE)));
- Assert.assertEquals("ThrowArithmeticExpHandler", exception.getMessage());
+ Assertions.assertEquals("ThrowArithmeticExpHandler", exception.getMessage());
} finally {
eventManager.unregister(handler1);
}
@@ -106,24 +105,24 @@ public void configureHandlersTest() {
EventManager eventManager = EventManager.getInstance();
IEventHandler handler = new ThrowArithmeticExpHandler();
- Assert.assertFalse(eventManager.isRegistered(handler));
+ Assertions.assertFalse(eventManager.isRegistered(handler));
eventManager.register(handler);
- Assert.assertTrue(eventManager.isRegistered(handler));
+ Assertions.assertTrue(eventManager.isRegistered(handler));
- Assert.assertTrue(eventManager.unregister(handler));
- Assert.assertFalse(eventManager.isRegistered(handler));
+ Assertions.assertTrue(eventManager.unregister(handler));
+ Assertions.assertFalse(eventManager.isRegistered(handler));
- Assert.assertFalse(eventManager.unregister(handler));
+ Assertions.assertFalse(eventManager.unregister(handler));
}
@Test
public void turningOffAgplTest() {
IProductProcessorFactory defaultProductProcessorFactory = ProductProcessorFactoryKeeper.getProductProcessorFactory();
- Assert.assertTrue(defaultProductProcessorFactory instanceof DefaultProductProcessorFactory);
+ Assertions.assertTrue(defaultProductProcessorFactory instanceof DefaultProductProcessorFactory);
EventManager.acknowledgeAgplUsageDisableWarningMessage();
IProductProcessorFactory underAgplProductProcessorFactory1 = ProductProcessorFactoryKeeper.getProductProcessorFactory();
- Assert.assertTrue(underAgplProductProcessorFactory1 instanceof UnderAgplProductProcessorFactory);
+ Assertions.assertTrue(underAgplProductProcessorFactory1 instanceof UnderAgplProductProcessorFactory);
}
private static class ThrowArithmeticExpHandler implements IEventHandler {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerIntegrationTest.java b/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerIntegrationTest.java
index 5dada564b8..00badee136 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerIntegrationTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerIntegrationTest.java
@@ -27,27 +27,26 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.commons.ecosystem.ITextTestEvent;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.IntegrationTest;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(IntegrationTest.class)
+@Tag("IntegrationTest")
public class ProductEventHandlerIntegrationTest extends ExtendedITextTest {
private PrintStream outBackup;
- @Before
+ @BeforeEach
public void initTest() {
outBackup = System.out;
ProductEventHandler.INSTANCE.clearProcessors();
}
- @After
+ @AfterEach
public void afterEach() {
System.setOut(outBackup);
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
@@ -66,7 +65,7 @@ public void removeAGPLLoggingTest() {
SequenceId sequenceId = new SequenceId();
- Assert.assertTrue(handler.getEvents(sequenceId).isEmpty());
+ Assertions.assertTrue(handler.getEvents(sequenceId).isEmpty());
ITextTestEvent event = new ITextTestEvent(sequenceId, null, "test-event",
ProductNameConstant.ITEXT_CORE);
EventManager.getInstance().onEvent(event);
@@ -74,10 +73,10 @@ public void removeAGPLLoggingTest() {
ConfirmEvent confirmEvent = new ConfirmEvent(sequenceId, event);
EventManager.getInstance().onEvent(confirmEvent);
- Assert.assertEquals(1, handler.getEvents(sequenceId).size());
- Assert.assertTrue(handler.getEvents(sequenceId).get(0) instanceof ConfirmedEventWrapper);
- Assert.assertEquals(event, ((ConfirmedEventWrapper) handler.getEvents(sequenceId).get(0)).getEvent());
+ Assertions.assertEquals(1, handler.getEvents(sequenceId).size());
+ Assertions.assertTrue(handler.getEvents(sequenceId).get(0) instanceof ConfirmedEventWrapper);
+ Assertions.assertEquals(event, ((ConfirmedEventWrapper) handler.getEvents(sequenceId).get(0)).getEvent());
}
- Assert.assertEquals("", testOut.toString());
+ Assertions.assertEquals("", testOut.toString());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerTest.java b/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerTest.java
index 27c63104d0..22fbd4da7a 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/ProductEventHandlerTest.java
@@ -34,22 +34,21 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.test.AssertUtil;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ProductEventHandlerTest extends ExtendedITextTest {
- @Before
+ @BeforeEach
public void clearProcessors() {
ProductEventHandler.INSTANCE.clearProcessors();
}
- @After
+ @AfterEach
public void afterEach() {
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
}
@@ -59,9 +58,9 @@ public void unknownProductTest() {
ProductEventHandler handler = ProductEventHandler.INSTANCE;
AbstractContextBasedITextEvent event = new ITextTestEvent(new SequenceId(), null, "test-event", "Unknown Product");
- Exception ex = Assert.assertThrows(UnknownProductException.class,
+ Exception ex = Assertions.assertThrows(UnknownProductException.class,
() -> handler.onAcceptedEvent(event));
- Assert.assertEquals(MessageFormatUtil.format(UnknownProductException.UNKNOWN_PRODUCT, "Unknown Product"),
+ Assertions.assertEquals(MessageFormatUtil.format(UnknownProductException.UNKNOWN_PRODUCT, "Unknown Product"),
ex.getMessage());
}
@@ -71,18 +70,18 @@ public void sequenceIdBasedEventTest() {
SequenceId sequenceId = new SequenceId();
- Assert.assertTrue(handler.getEvents(sequenceId).isEmpty());
+ Assertions.assertTrue(handler.getEvents(sequenceId).isEmpty());
handler.onAcceptedEvent(new ITextTestEvent(sequenceId, null, "test-event",
ProductNameConstant.ITEXT_CORE));
- Assert.assertEquals(1, handler.getEvents(sequenceId).size());
+ Assertions.assertEquals(1, handler.getEvents(sequenceId).size());
AbstractProductProcessITextEvent event = handler.getEvents(sequenceId).get(0);
- Assert.assertEquals(sequenceId.getId(), event.getSequenceId().getId());
- Assert.assertNull(event.getMetaInfo());
- Assert.assertEquals("test-event", event.getEventType());
- Assert.assertEquals(ProductNameConstant.ITEXT_CORE, event.getProductName());
+ Assertions.assertEquals(sequenceId.getId(), event.getSequenceId().getId());
+ Assertions.assertNull(event.getMetaInfo());
+ Assertions.assertEquals("test-event", event.getEventType());
+ Assertions.assertEquals(ProductNameConstant.ITEXT_CORE, event.getProductName());
}
@Test
@@ -91,19 +90,19 @@ public void reportEventSeveralTimesTest() {
SequenceId sequenceId = new SequenceId();
- Assert.assertTrue(handler.getEvents(sequenceId).isEmpty());
+ Assertions.assertTrue(handler.getEvents(sequenceId).isEmpty());
ITextTestEvent event = new ITextTestEvent(sequenceId, null, "test-event",
ProductNameConstant.ITEXT_CORE);
EventManager.getInstance().onEvent(event);
- Assert.assertEquals(1, handler.getEvents(sequenceId).size());
- Assert.assertEquals(event, handler.getEvents(sequenceId).get(0));
+ Assertions.assertEquals(1, handler.getEvents(sequenceId).size());
+ Assertions.assertEquals(event, handler.getEvents(sequenceId).get(0));
EventManager.getInstance().onEvent(event);
- Assert.assertEquals(2, handler.getEvents(sequenceId).size());
- Assert.assertEquals(event, handler.getEvents(sequenceId).get(0));
- Assert.assertEquals(event, handler.getEvents(sequenceId).get(1));
+ Assertions.assertEquals(2, handler.getEvents(sequenceId).size());
+ Assertions.assertEquals(event, handler.getEvents(sequenceId).get(0));
+ Assertions.assertEquals(event, handler.getEvents(sequenceId).get(1));
}
@Test
@@ -112,7 +111,7 @@ public void confirmEventTest() {
SequenceId sequenceId = new SequenceId();
- Assert.assertTrue(handler.getEvents(sequenceId).isEmpty());
+ Assertions.assertTrue(handler.getEvents(sequenceId).isEmpty());
ITextTestEvent event = new ITextTestEvent(sequenceId, null, "test-event",
ProductNameConstant.ITEXT_CORE);
@@ -121,9 +120,9 @@ public void confirmEventTest() {
ConfirmEvent confirmEvent = new ConfirmEvent(sequenceId, event);
EventManager.getInstance().onEvent(confirmEvent);
- Assert.assertEquals(1, handler.getEvents(sequenceId).size());
- Assert.assertTrue(handler.getEvents(sequenceId).get(0) instanceof ConfirmedEventWrapper);
- Assert.assertEquals(event, ((ConfirmedEventWrapper) handler.getEvents(sequenceId).get(0)).getEvent());
+ Assertions.assertEquals(1, handler.getEvents(sequenceId).size());
+ Assertions.assertTrue(handler.getEvents(sequenceId).get(0) instanceof ConfirmedEventWrapper);
+ Assertions.assertEquals(event, ((ConfirmedEventWrapper) handler.getEvents(sequenceId).get(0)).getEvent());
}
@Test
@@ -135,7 +134,7 @@ public void settingCustomProcessFactoryTest() {
ProductEventHandler handler = ProductEventHandler.INSTANCE;
ITextProductEventProcessor activeProcessor = handler.getActiveProcessor(ProductNameConstant.ITEXT_CORE);
- Assert.assertTrue(activeProcessor instanceof TestProductEventProcessor);
+ Assertions.assertTrue(activeProcessor instanceof TestProductEventProcessor);
}
@Test
@@ -147,9 +146,9 @@ public void repeatEventHandlingWithFiveExceptionOnProcessingTest() {
AbstractContextBasedITextEvent event = new ITextTestEvent(new SequenceId(), null, "test",
ProductNameConstant.ITEXT_CORE);
- Exception e = Assert.assertThrows(ProductEventHandlerRepeatException.class,
+ Exception e = Assertions.assertThrows(ProductEventHandlerRepeatException.class,
() -> handler.onAcceptedEvent(event));
- Assert.assertEquals("customMessage5", e.getMessage());
+ Assertions.assertEquals("customMessage5", e.getMessage());
}
@Test
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/ProductProcessorFactoryKeeperTest.java b/commons/src/test/java/com/itextpdf/commons/actions/ProductProcessorFactoryKeeperTest.java
index 864845f076..ebd3ec999d 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/ProductProcessorFactoryKeeperTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/ProductProcessorFactoryKeeperTest.java
@@ -26,17 +26,16 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.processors.IProductProcessorFactory;
import com.itextpdf.commons.actions.processors.UnderAgplProductProcessorFactory;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ProductProcessorFactoryKeeperTest extends ExtendedITextTest {
- @After
+ @AfterEach
public void afterEach() {
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
}
@@ -44,17 +43,17 @@ public void afterEach() {
@Test
public void gettingDefaultFactoryFromKeeper() {
IProductProcessorFactory productProcessorFactory = ProductProcessorFactoryKeeper.getProductProcessorFactory();
- Assert.assertTrue(productProcessorFactory instanceof DefaultProductProcessorFactory);
+ Assertions.assertTrue(productProcessorFactory instanceof DefaultProductProcessorFactory);
}
@Test
public void restoringDefaultFactory() {
ProductProcessorFactoryKeeper.setProductProcessorFactory(new UnderAgplProductProcessorFactory());
- Assert.assertTrue(ProductProcessorFactoryKeeper.getProductProcessorFactory()
+ Assertions.assertTrue(ProductProcessorFactoryKeeper.getProductProcessorFactory()
instanceof UnderAgplProductProcessorFactory);
ProductProcessorFactoryKeeper.restoreDefaultProductProcessorFactory();
- Assert.assertTrue(ProductProcessorFactoryKeeper.getProductProcessorFactory()
+ Assertions.assertTrue(ProductProcessorFactoryKeeper.getProductProcessorFactory()
instanceof DefaultProductProcessorFactory);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/confirmations/ConfirmEventTest.java b/commons/src/test/java/com/itextpdf/commons/actions/confirmations/ConfirmEventTest.java
index e328fab8b8..850fe4ccc5 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/confirmations/ConfirmEventTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/confirmations/ConfirmEventTest.java
@@ -26,13 +26,12 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.ecosystem.TestMetaInfo;
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ConfirmEventTest extends ExtendedITextTest {
@Test
public void constructorWithSequenceIdTest() {
@@ -40,13 +39,13 @@ public void constructorWithSequenceIdTest() {
ITextTestEvent iTextTestEvent = new ITextTestEvent(new SequenceId(), new TestMetaInfo(""), "eventType", "productName");
ConfirmEvent confirmEvent = new ConfirmEvent(sequenceId, iTextTestEvent);
- Assert.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
- Assert.assertEquals("eventType", confirmEvent.getEventType());
- Assert.assertEquals("productName", confirmEvent.getProductName());
- Assert.assertSame(sequenceId, confirmEvent.getSequenceId());
- Assert.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
- Assert.assertNotNull(confirmEvent.getProductData());
- Assert.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
+ Assertions.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
+ Assertions.assertEquals("eventType", confirmEvent.getEventType());
+ Assertions.assertEquals("productName", confirmEvent.getProductName());
+ Assertions.assertSame(sequenceId, confirmEvent.getSequenceId());
+ Assertions.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
+ Assertions.assertNotNull(confirmEvent.getProductData());
+ Assertions.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
}
@Test
@@ -54,13 +53,13 @@ public void constructorWithoutSequenceIdTest() {
ITextTestEvent iTextTestEvent = new ITextTestEvent(new SequenceId(), new TestMetaInfo(""), "eventType", "productName");
ConfirmEvent confirmEvent = new ConfirmEvent(iTextTestEvent);
- Assert.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
- Assert.assertEquals("eventType", confirmEvent.getEventType());
- Assert.assertEquals("productName", confirmEvent.getProductName());
- Assert.assertSame(iTextTestEvent.getSequenceId(), confirmEvent.getSequenceId());
- Assert.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
- Assert.assertNotNull(confirmEvent.getProductData());
- Assert.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
+ Assertions.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
+ Assertions.assertEquals("eventType", confirmEvent.getEventType());
+ Assertions.assertEquals("productName", confirmEvent.getProductName());
+ Assertions.assertSame(iTextTestEvent.getSequenceId(), confirmEvent.getSequenceId());
+ Assertions.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
+ Assertions.assertNotNull(confirmEvent.getProductData());
+ Assertions.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
}
@Test
@@ -69,14 +68,14 @@ public void confirmEventInsideOtherConfirmEventTest() {
ConfirmEvent child = new ConfirmEvent(iTextTestEvent.getSequenceId(), iTextTestEvent);
ConfirmEvent confirmEvent = new ConfirmEvent(child);
- Assert.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
+ Assertions.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
- Assert.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
- Assert.assertEquals("eventType", confirmEvent.getEventType());
- Assert.assertEquals("productName", confirmEvent.getProductName());
- Assert.assertSame(iTextTestEvent.getSequenceId(), confirmEvent.getSequenceId());
- Assert.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
- Assert.assertNotNull(confirmEvent.getProductData());
- Assert.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
+ Assertions.assertSame(iTextTestEvent, confirmEvent.getConfirmedEvent());
+ Assertions.assertEquals("eventType", confirmEvent.getEventType());
+ Assertions.assertEquals("productName", confirmEvent.getProductName());
+ Assertions.assertSame(iTextTestEvent.getSequenceId(), confirmEvent.getSequenceId());
+ Assertions.assertEquals(EventConfirmationType.UNCONFIRMABLE, confirmEvent.getConfirmationType());
+ Assertions.assertNotNull(confirmEvent.getProductData());
+ Assertions.assertEquals(ITextTestEvent.class, confirmEvent.getClassFromContext());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/contexts/ContextManagerTest.java b/commons/src/test/java/com/itextpdf/commons/actions/contexts/ContextManagerTest.java
index 252e57c90d..1c5d27f039 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/contexts/ContextManagerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/contexts/ContextManagerTest.java
@@ -24,16 +24,15 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.NamespaceConstant;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ContextManagerTest extends ExtendedITextTest {
@Test
@@ -41,7 +40,7 @@ public void getRecognisedNamespaceForSpecificNamespaceTest() {
String outerNamespaces = NamespaceConstant.ITEXT.toLowerCase();
String innerNamespaces = NamespaceConstant.PDF_HTML.toLowerCase();
- Assert.assertTrue(innerNamespaces.startsWith(outerNamespaces));
+ Assertions.assertTrue(innerNamespaces.startsWith(outerNamespaces));
ContextManager managerOuterBeforeInner = new ContextManager();
managerOuterBeforeInner
@@ -49,9 +48,9 @@ public void getRecognisedNamespaceForSpecificNamespaceTest() {
managerOuterBeforeInner
.registerGenericContext(Collections.singletonList(innerNamespaces), Collections.emptyList());
- Assert.assertEquals(outerNamespaces,
+ Assertions.assertEquals(outerNamespaces,
managerOuterBeforeInner.getRecognisedNamespace(outerNamespaces));
- Assert.assertEquals(innerNamespaces,
+ Assertions.assertEquals(innerNamespaces,
managerOuterBeforeInner.getRecognisedNamespace(innerNamespaces));
ContextManager managerInnerBeforeOuter = new ContextManager();
@@ -60,9 +59,9 @@ public void getRecognisedNamespaceForSpecificNamespaceTest() {
managerInnerBeforeOuter
.registerGenericContext(Collections.singletonList(outerNamespaces), Collections.emptyList());
- Assert.assertEquals(outerNamespaces,
+ Assertions.assertEquals(outerNamespaces,
managerInnerBeforeOuter.getRecognisedNamespace(outerNamespaces));
- Assert.assertEquals(innerNamespaces,
+ Assertions.assertEquals(innerNamespaces,
managerInnerBeforeOuter.getRecognisedNamespace(innerNamespaces));
}
@@ -70,7 +69,7 @@ public void getRecognisedNamespaceForSpecificNamespaceTest() {
public void notRegisteredNamespaceTest() {
String notRegisteredNamespace = "com.hello.world";
- Assert.assertNull(ContextManager.getInstance().getRecognisedNamespace(notRegisteredNamespace));
+ Assertions.assertNull(ContextManager.getInstance().getRecognisedNamespace(notRegisteredNamespace));
}
@Test
@@ -83,27 +82,27 @@ public void unregisterNamespaceTest() {
);
ContextManager manager = new ContextManager();
- Assert.assertNull(manager.getRecognisedNamespace(testNamespace));
- Assert.assertNull(manager.getRecognisedNamespace(testNamespaceWithCapitals));
+ Assertions.assertNull(manager.getRecognisedNamespace(testNamespace));
+ Assertions.assertNull(manager.getRecognisedNamespace(testNamespaceWithCapitals));
manager.registerGenericContext(testNamespaces, Arrays.asList("myProduct"));
- Assert.assertEquals(testNamespace,
+ Assertions.assertEquals(testNamespace,
manager.getRecognisedNamespace(testNamespace + ".MyClass"));
- Assert.assertEquals(testNamespaceWithCapitals.toLowerCase(),
+ Assertions.assertEquals(testNamespaceWithCapitals.toLowerCase(),
manager.getRecognisedNamespace(testNamespaceWithCapitals + ".MyClass"));
manager.unregisterContext(testNamespaces);
- Assert.assertNull(manager.getRecognisedNamespace(testNamespace));
- Assert.assertNull(manager.getRecognisedNamespace(testNamespaceWithCapitals));
+ Assertions.assertNull(manager.getRecognisedNamespace(testNamespace));
+ Assertions.assertNull(manager.getRecognisedNamespace(testNamespaceWithCapitals));
}
@Test
public void registeredNamespaceTest() {
String registeredNamespace = NamespaceConstant.CORE_LAYOUT + "custompackage";
- Assert.assertEquals(NamespaceConstant.CORE_LAYOUT.toLowerCase(),
+ Assertions.assertEquals(NamespaceConstant.CORE_LAYOUT.toLowerCase(),
ContextManager.getInstance().getRecognisedNamespace(registeredNamespace));
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/data/CommonsProductDataTest.java b/commons/src/test/java/com/itextpdf/commons/actions/data/CommonsProductDataTest.java
index de4cdfc5da..cfdfeb6dd2 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/data/CommonsProductDataTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/data/CommonsProductDataTest.java
@@ -23,24 +23,23 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.actions.data;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class CommonsProductDataTest extends ExtendedITextTest {
@Test
public void getInstanceTest() {
ProductData commonsProductData = CommonsProductData.getInstance();
- Assert.assertEquals(CommonsProductData.COMMONS_PUBLIC_PRODUCT_NAME, commonsProductData.getPublicProductName());
- Assert.assertEquals(CommonsProductData.COMMONS_PRODUCT_NAME, commonsProductData.getProductName());
- Assert.assertEquals(CommonsProductData.COMMONS_VERSION, commonsProductData.getVersion());
- Assert.assertEquals(CommonsProductData.MINIMAL_COMPATIBLE_LICENSEKEY_VERSION,
+ Assertions.assertEquals(CommonsProductData.COMMONS_PUBLIC_PRODUCT_NAME, commonsProductData.getPublicProductName());
+ Assertions.assertEquals(CommonsProductData.COMMONS_PRODUCT_NAME, commonsProductData.getProductName());
+ Assertions.assertEquals(CommonsProductData.COMMONS_VERSION, commonsProductData.getVersion());
+ Assertions.assertEquals(CommonsProductData.MINIMAL_COMPATIBLE_LICENSEKEY_VERSION,
commonsProductData.getMinCompatibleLicensingModuleVersion());
- Assert.assertEquals(CommonsProductData.COMMONS_COPYRIGHT_SINCE, commonsProductData.getSinceCopyrightYear());
- Assert.assertEquals(CommonsProductData.COMMONS_COPYRIGHT_TO, commonsProductData.getToCopyrightYear());
+ Assertions.assertEquals(CommonsProductData.COMMONS_COPYRIGHT_SINCE, commonsProductData.getSinceCopyrightYear());
+ Assertions.assertEquals(CommonsProductData.COMMONS_COPYRIGHT_TO, commonsProductData.getToCopyrightYear());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/data/ProductDataTest.java b/commons/src/test/java/com/itextpdf/commons/actions/data/ProductDataTest.java
index 97687f31c6..40c7c03c43 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/data/ProductDataTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/data/ProductDataTest.java
@@ -23,35 +23,34 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.actions.data;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ProductDataTest extends ExtendedITextTest {
@Test
public void productDataCreationTest() {
ProductData productData = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
- Assert.assertEquals("publicProductName", productData.getPublicProductName());
- Assert.assertEquals("productName", productData.getProductName());
- Assert.assertEquals("1.2", productData.getVersion());
- Assert.assertEquals(1900, productData.getSinceCopyrightYear());
- Assert.assertEquals(2100, productData.getToCopyrightYear());
+ Assertions.assertEquals("publicProductName", productData.getPublicProductName());
+ Assertions.assertEquals("productName", productData.getProductName());
+ Assertions.assertEquals("1.2", productData.getVersion());
+ Assertions.assertEquals(1900, productData.getSinceCopyrightYear());
+ Assertions.assertEquals(2100, productData.getToCopyrightYear());
}
@Test
public void productDataAnotherCreationTest() {
ProductData productData = new ProductData("publicProductName", "productName", "1.2", "4.0.0", 1900, 2100);
- Assert.assertEquals("publicProductName", productData.getPublicProductName());
- Assert.assertEquals("productName", productData.getProductName());
- Assert.assertEquals("1.2", productData.getVersion());
- Assert.assertEquals("4.0.0", productData.getMinCompatibleLicensingModuleVersion());
- Assert.assertEquals(1900, productData.getSinceCopyrightYear());
- Assert.assertEquals(2100, productData.getToCopyrightYear());
+ Assertions.assertEquals("publicProductName", productData.getPublicProductName());
+ Assertions.assertEquals("productName", productData.getProductName());
+ Assertions.assertEquals("1.2", productData.getVersion());
+ Assertions.assertEquals("4.0.0", productData.getMinCompatibleLicensingModuleVersion());
+ Assertions.assertEquals(1900, productData.getSinceCopyrightYear());
+ Assertions.assertEquals(2100, productData.getToCopyrightYear());
}
@Test
@@ -59,10 +58,10 @@ public void equalsTest() {
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
ProductData b = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
- Assert.assertEquals(a, a);
+ Assertions.assertEquals(a, a);
- Assert.assertEquals(a, b);
- Assert.assertEquals(b, a);
+ Assertions.assertEquals(a, b);
+ Assertions.assertEquals(b, a);
}
@Test
@@ -70,7 +69,7 @@ public void notEqualsTest() {
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
ProductData d = new ProductData("publicProductName", "productName", "1.2", 1910, 2110);
- Assert.assertNotEquals(a, d);
+ Assertions.assertNotEquals(a, d);
}
@Test
@@ -78,11 +77,11 @@ public void hashCodeTest() {
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
ProductData b = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
- Assert.assertEquals(a, b);
- Assert.assertEquals(a.hashCode(), b.hashCode());
+ Assertions.assertEquals(a, b);
+ Assertions.assertEquals(a.hashCode(), b.hashCode());
int h1 = a.hashCode();
int h2 = a.hashCode();
- Assert.assertEquals(h1, h2);
+ Assertions.assertEquals(h1, h2);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultITextProductEventProcessorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultITextProductEventProcessorTest.java
index 400cccf9c2..cf142b44a2 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultITextProductEventProcessorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultITextProductEventProcessorTest.java
@@ -32,20 +32,19 @@ This file is part of the iText (R) project.
import com.itextpdf.test.LogLevelConstants;
import com.itextpdf.test.annotations.LogMessage;
import com.itextpdf.test.annotations.LogMessages;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class DefaultITextProductEventProcessorTest extends ExtendedITextTest {
@Test
public void constructorWithNullProductNameTest() {
Exception e =
- Assert.assertThrows(IllegalArgumentException.class, () -> new DefaultITextProductEventProcessor(null));
- Assert.assertEquals(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL, e.getMessage());
+ Assertions.assertThrows(IllegalArgumentException.class, () -> new DefaultITextProductEventProcessor(null));
+ Assertions.assertEquals(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL, e.getMessage());
}
@Test
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultProductProcessorFactoryTest.java b/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultProductProcessorFactoryTest.java
index c746b1c9df..411935e1c1 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultProductProcessorFactoryTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/processors/DefaultProductProcessorFactoryTest.java
@@ -24,20 +24,19 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.ProductNameConstant;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class DefaultProductProcessorFactoryTest extends ExtendedITextTest {
@Test
public void createDefaultProductProcessor() {
DefaultProductProcessorFactory defaultProductProcessorFactory = new DefaultProductProcessorFactory();
ITextProductEventProcessor processor = defaultProductProcessorFactory.createProcessor(ProductNameConstant.ITEXT_CORE);
- Assert.assertNotNull(processor);
- Assert.assertTrue(processor instanceof DefaultITextProductEventProcessor);
+ Assertions.assertNotNull(processor);
+ Assertions.assertTrue(processor instanceof DefaultITextProductEventProcessor);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplITextProductEventProcessorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplITextProductEventProcessorTest.java
index 731c76950a..61a47a7104 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplITextProductEventProcessorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplITextProductEventProcessorTest.java
@@ -29,12 +29,11 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.ecosystem.ITextTestEvent;
import com.itextpdf.test.AssertUtil;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class UnderAgplITextProductEventProcessorTest extends ExtendedITextTest {
@Test
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplProductProcessorFactoryTest.java b/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplProductProcessorFactoryTest.java
index 380e02e3d0..935225e94d 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplProductProcessorFactoryTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/processors/UnderAgplProductProcessorFactoryTest.java
@@ -24,20 +24,19 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.actions.ProductNameConstant;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class UnderAgplProductProcessorFactoryTest extends ExtendedITextTest {
@Test
public void createUnderAgplProductProcessor() {
UnderAgplProductProcessorFactory underAgplProductProcessorFactory = new UnderAgplProductProcessorFactory();
ITextProductEventProcessor processor = underAgplProductProcessorFactory.createProcessor(ProductNameConstant.ITEXT_CORE);
- Assert.assertNotNull(processor);
- Assert.assertTrue(processor instanceof UnderAgplITextProductEventProcessor);
+ Assertions.assertNotNull(processor);
+ Assertions.assertTrue(processor instanceof UnderAgplITextProductEventProcessor);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightSincePlaceholderPopulatorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightSincePlaceholderPopulatorTest.java
index 4ddc3cda52..79202a08b8 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightSincePlaceholderPopulatorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightSincePlaceholderPopulatorTest.java
@@ -27,15 +27,14 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.ecosystem.ITextTestEvent;
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class CopyrightSincePlaceholderPopulatorTest extends ExtendedITextTest {
private CopyrightSincePlaceholderPopulator populator = new CopyrightSincePlaceholderPopulator();
@@ -43,21 +42,21 @@ public class CopyrightSincePlaceholderPopulatorTest extends ExtendedITextTest {
public void oneEventTest() {
List events = getEvents(1994);
String result = populator.populate(events, null);
- Assert.assertEquals("1994", result);
+ Assertions.assertEquals("1994", result);
}
@Test
public void severalEventsTest() {
List events = getEvents(2012, 1994, 1998);
String result = populator.populate(events, null);
- Assert.assertEquals("1994", result);
+ Assertions.assertEquals("1994", result);
}
@Test
public void severalEventsWithSameYearTest() {
List events = getEvents(1992, 1998, 1992, 1998);
String result = populator.populate(events, null);
- Assert.assertEquals("1992", result);
+ Assertions.assertEquals("1992", result);
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightToPlaceholderPopulatorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightToPlaceholderPopulatorTest.java
index e1501c8277..656413c709 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightToPlaceholderPopulatorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/producer/CopyrightToPlaceholderPopulatorTest.java
@@ -27,15 +27,14 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.ecosystem.ITextTestEvent;
import com.itextpdf.commons.actions.sequence.SequenceId;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class CopyrightToPlaceholderPopulatorTest extends ExtendedITextTest {
private CopyrightToPlaceholderPopulator populator = new CopyrightToPlaceholderPopulator();
@@ -43,21 +42,21 @@ public class CopyrightToPlaceholderPopulatorTest extends ExtendedITextTest {
public void oneEventTest() {
List events = getEvents(2010);
String result = populator.populate(events, null);
- Assert.assertEquals("2010", result);
+ Assertions.assertEquals("2010", result);
}
@Test
public void severalEventsTest() {
List events = getEvents(2007, 2030, 2020);
String result = populator.populate(events, null);
- Assert.assertEquals("2030", result);
+ Assertions.assertEquals("2030", result);
}
@Test
public void severalEventsWithSameYearTest() {
List events = getEvents(2009, 1998, 2009, 1998);
String result = populator.populate(events, null);
- Assert.assertEquals("2009", result);
+ Assertions.assertEquals("2009", result);
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/producer/CurrentDatePlaceholderPopulatorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/producer/CurrentDatePlaceholderPopulatorTest.java
index 9de823c590..1a60efd3fa 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/producer/CurrentDatePlaceholderPopulatorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/producer/CurrentDatePlaceholderPopulatorTest.java
@@ -27,82 +27,81 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.test.AssertUtil;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.Date;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class CurrentDatePlaceholderPopulatorTest extends ExtendedITextTest {
private final CurrentDatePlaceholderPopulator populator = new CurrentDatePlaceholderPopulator();
@Test
public void nullTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, null));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "currentDate"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "currentDate"),
exception.getMessage());
}
@Test
public void plainTextTest() {
String result = populator.populate(null, "'plain text'");
- Assert.assertEquals("plain text", result);
+ Assertions.assertEquals("plain text", result);
}
@Test
public void plainTextWithIgnoredBackSlashesTest() {
String result = populator.populate(null, "'\\p\\l\\a\\i\\n \\t\\e\\x\\t'");
- Assert.assertEquals("plain text", result);
+ Assertions.assertEquals("plain text", result);
}
@Test
public void plainTextWithEscapedBackSlashesTest() {
String result = populator.populate(null, "'plain\\\\text'");
- Assert.assertEquals("plain\\text", result);
+ Assertions.assertEquals("plain\\text", result);
}
@Test
public void plainTextWithEscapedApostrophesTest() {
String result = populator.populate(null, "'plain\\'text'");
- Assert.assertEquals("plain'text", result);
+ Assertions.assertEquals("plain'text", result);
}
@Test
public void plainTextSeveralQuotedStringsTest() {
String result = populator.populate(null, "'plain'' ''text'");
- Assert.assertEquals("plain text", result);
+ Assertions.assertEquals("plain text", result);
}
@Test
public void plainTextWithUnquotedCharactersTest() {
String result = populator.populate(null, "'plain text'$$$");
- Assert.assertEquals("plain text$$$", result);
+ Assertions.assertEquals("plain text$$$", result);
}
@Test
public void plainTextEndlessQuotationErrorTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "'plain text"));
- Assert.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
+ Assertions.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
exception.getMessage());
}
@Test
public void plainTextMultipleQuotationsEndlessQuotationErrorTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "'plain'' ''text"));
- Assert.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
+ Assertions.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
exception.getMessage());
}
@Test
public void plainTextEscapedApostropheEndlessQuotationErrorTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "'plain text\\'"));
- Assert.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
+ Assertions.assertEquals(CommonsExceptionMessageConstant.PATTERN_CONTAINS_OPEN_QUOTATION,
exception.getMessage());
}
@@ -118,30 +117,30 @@ public void validComponentsComparisonTest() {
Date date = DateTimeUtil.getCurrentTimeDate();
String result = populator.populate(null, "dd MM yy yyyy HH");
String expectedResult = DateTimeUtil.format(date, "dd MM yy yyyy HH");
- Assert.assertEquals(expectedResult, result);
+ Assertions.assertEquals(expectedResult, result);
}
@Test
public void unexpectedLetterComponentTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "dd MM tyy yyyy HH"));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "t"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "t"),
exception.getMessage());
}
@Test
public void unexpectedLongComponentTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "dd MMMMM yy yyyy HH"));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "MMMMM"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "MMMMM"),
exception.getMessage());
}
@Test
public void unexpectedShortComponentTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(null, "dd MM y yyyy HH"));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "y"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_COMPONENT, "y"),
exception.getMessage());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/producer/ProducerBuilderTest.java b/commons/src/test/java/com/itextpdf/commons/actions/producer/ProducerBuilderTest.java
index 90083ad7a5..386a532b32 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/producer/ProducerBuilderTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/producer/ProducerBuilderTest.java
@@ -35,31 +35,30 @@ This file is part of the iText (R) project.
import com.itextpdf.test.LogLevelConstants;
import com.itextpdf.test.annotations.LogMessage;
import com.itextpdf.test.annotations.LogMessages;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ProducerBuilderTest extends ExtendedITextTest {
@Test
public void emptyEventsProducerLineTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> ProducerBuilder.modifyProducer(Collections.emptyList(), null));
- Assert.assertEquals(CommonsExceptionMessageConstant.NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT,
+ Assertions.assertEquals(CommonsExceptionMessageConstant.NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT,
exception.getMessage());
}
@Test
public void nullEventsProducerLineTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> ProducerBuilder.modifyProducer((List)null, null));
- Assert.assertEquals(CommonsExceptionMessageConstant.NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT,
+ Assertions.assertEquals(CommonsExceptionMessageConstant.NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT,
exception.getMessage());
}
@@ -68,7 +67,7 @@ public void plainTextNewProducerLineTest() {
List events = getEvents("Plain Text", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("Plain Text", newProducerLine);
+ Assertions.assertEquals("Plain Text", newProducerLine);
}
@Test
@@ -76,7 +75,7 @@ public void plainTextEmptyOldProducerLineTest() {
List events = getEvents("Plain Text", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, "");
- Assert.assertEquals("Plain Text", newProducerLine);
+ Assertions.assertEquals("Plain Text", newProducerLine);
}
@Test
@@ -84,7 +83,7 @@ public void plainTextExistingOldProducerLineTest() {
List events = getEvents("Plain Text", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, "Old producer");
- Assert.assertEquals("Old producer; modified using Plain Text", newProducerLine);
+ Assertions.assertEquals("Old producer; modified using Plain Text", newProducerLine);
}
@Test
@@ -92,7 +91,7 @@ public void plainTextExistingOldProducerWithModifiedPartLineTest() {
List events = getEvents("New Author", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, "Old producer; modified using Plain Text");
- Assert.assertEquals("Old producer; modified using Plain Text; modified using New Author", newProducerLine);
+ Assertions.assertEquals("Old producer; modified using Plain Text; modified using New Author", newProducerLine);
}
@@ -101,7 +100,7 @@ public void copyrightSinceProducerLineTest() {
List events = getEvents("Prod. since ${copyrightSince}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("Prod. since 1901", newProducerLine);
+ Assertions.assertEquals("Prod. since 1901", newProducerLine);
}
@Test
@@ -109,7 +108,7 @@ public void copyrightToProducerLineTest() {
List events = getEvents("All rights reserved, ${copyrightTo}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("All rights reserved, 2103", newProducerLine);
+ Assertions.assertEquals("All rights reserved, 2103", newProducerLine);
}
@Test
@@ -117,7 +116,7 @@ public void currentDateProducerLineTest() {
List events = getEvents("Created at ${currentDate:yyyy}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("Created at " + DateTimeUtil.format(DateTimeUtil.getCurrentTimeDate(), "yyyy"), newProducerLine);
+ Assertions.assertEquals("Created at " + DateTimeUtil.format(DateTimeUtil.getCurrentTimeDate(), "yyyy"), newProducerLine);
}
@Test
@@ -126,7 +125,7 @@ public void currentDateComplexFormatProducerLineTest() {
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
String currentYear = DateTimeUtil.format(DateTimeUtil.getCurrentTimeDate(), "yyyy");
- Assert.assertEquals("Created at " + currentYear + ", {'yes::yes', " + currentYear, newProducerLine);
+ Assertions.assertEquals("Created at " + currentYear + ", {'yes::yes', " + currentYear, newProducerLine);
}
@Test
@@ -134,15 +133,15 @@ public void currentDatePlaceholderFormatProducerLineTest() {
List events = getEvents("Created at ${currentDate:'${currentDate'}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("Created at ${currentDate", newProducerLine);
+ Assertions.assertEquals("Created at ${currentDate", newProducerLine);
}
@Test
public void currentDateNoFormatProducerLineTest() {
List events = getEvents("Created at ${currentDate}", 1, 2, 3);
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> ProducerBuilder.modifyProducer(events, null));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "currentDate"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "currentDate"),
exception.getMessage());
}
@@ -151,7 +150,7 @@ public void currentDateEmptyFormatProducerLineTest() {
List events = getEvents("Created at ${currentDate:}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("Created at ", newProducerLine);
+ Assertions.assertEquals("Created at ", newProducerLine);
}
@Test
@@ -159,7 +158,7 @@ public void usedProductsProducerLineTest() {
List events = getEvents("Used products: ${usedProducts:P #V (T 'version')}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals(
+ Assertions.assertEquals(
"Used products: product1 #1.0 (type1 version), product2 #2.0 (type2 version), product3 #3.0 (type3 version)",
newProducerLine);
}
@@ -167,9 +166,9 @@ public void usedProductsProducerLineTest() {
@Test
public void usedProductsEmptyFormatProducerLineTest() {
List events = getEvents("Used products: ${usedProducts}", 1, 2, 3);
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> ProducerBuilder.modifyProducer(events, null));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "usedProducts"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "usedProducts"),
exception.getMessage());
}
@@ -182,7 +181,7 @@ public void unknownPlaceHoldersTest() {
getEvents("${plchldr}|${plchldrWithParam:param}|${plchldrWithWeirdParam::$$:'''\\''}", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, null);
- Assert.assertEquals("||", newProducerLine);
+ Assertions.assertEquals("||", newProducerLine);
}
@Test
@@ -191,7 +190,7 @@ public void modifiedUsingEqualsCurrentProducerTest() {
String newProducerLine = ProducerBuilder.modifyProducer(events
, "Old producer; modified using some Author");
- Assert.assertEquals("Old producer; modified using some Author", newProducerLine);
+ Assertions.assertEquals("Old producer; modified using some Author", newProducerLine);
}
@Test
@@ -200,7 +199,7 @@ public void prevModifiedUsingEqualsCurrentProducerTest() {
String newProducerLine = ProducerBuilder.modifyProducer(events
, "Old producer; modified using some Author; modified using another tool");
- Assert.assertEquals("Old producer; modified using some Author; modified using another tool; " +
+ Assertions.assertEquals("Old producer; modified using some Author; modified using another tool; " +
"modified using some Author", newProducerLine);
}
@@ -210,7 +209,7 @@ public void severalModifiedUsingEqualsCurrentProducerTest() {
String newProducerLine = ProducerBuilder.modifyProducer(events
, "Old producer; modified using some Author; modified using some Author");
- Assert.assertEquals("Old producer; modified using some Author; modified using some Author", newProducerLine);
+ Assertions.assertEquals("Old producer; modified using some Author; modified using some Author", newProducerLine);
}
@Test
@@ -218,7 +217,7 @@ public void oldProducerEqualsCurrentProducerTest() {
List events = getEvents("some Author", 1, 2, 3);
String newProducerLine = ProducerBuilder.modifyProducer(events, "some Author");
- Assert.assertEquals("some Author", newProducerLine);
+ Assertions.assertEquals("some Author", newProducerLine);
}
private List getEvents(String initialProducerLine, int ... indexes) {
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/producer/UsedProductsPlaceholderPopulatorTest.java b/commons/src/test/java/com/itextpdf/commons/actions/producer/UsedProductsPlaceholderPopulatorTest.java
index 7004ffebf0..97ee787aa7 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/producer/UsedProductsPlaceholderPopulatorTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/producer/UsedProductsPlaceholderPopulatorTest.java
@@ -29,98 +29,97 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class UsedProductsPlaceholderPopulatorTest extends ExtendedITextTest {
private final UsedProductsPlaceholderPopulator populator = new UsedProductsPlaceholderPopulator();
@Test
public void nullTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(getEvents(1), null));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "usedProducts"),
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.INVALID_USAGE_FORMAT_REQUIRED, "usedProducts"),
exception.getMessage());
}
@Test
public void plainTextTest() {
String result = populator.populate(getEvents(0), "'plain text'");
- Assert.assertEquals("plain text", result);
+ Assertions.assertEquals("plain text", result);
}
@Test
public void plainTextMultipleEventsMergedTest() {
String result = populator.populate(getEvents(1, 2, 3, 4), "'plain text'");
- Assert.assertEquals("plain text", result);
+ Assertions.assertEquals("plain text", result);
}
@Test
public void productNameOneEventTest() {
String result = populator.populate(getEvents(0), "P");
- Assert.assertEquals("product0", result);
+ Assertions.assertEquals("product0", result);
}
@Test
public void productNameSeveralEventsTest() {
String result = populator.populate(getEvents(0, 1, 2), "P");
- Assert.assertEquals("product0, product1, product2", result);
+ Assertions.assertEquals("product0, product1, product2", result);
}
@Test
public void sameProductsMergedTest() {
String result = populator.populate(getEvents(0, 1, 0, 1, 2), "P");
- Assert.assertEquals("product0, product1, product2", result);
+ Assertions.assertEquals("product0, product1, product2", result);
}
@Test
public void versionOneEventTest() {
String result = populator.populate(getEvents(1), "V");
- Assert.assertEquals("1.0", result);
+ Assertions.assertEquals("1.0", result);
}
@Test
public void versionSeveralEventsTest() {
String result = populator.populate(getEvents(1, 2, 3), "V");
- Assert.assertEquals("1.0, 2.0, 3.0", result);
+ Assertions.assertEquals("1.0, 2.0, 3.0", result);
}
@Test
public void sameVersionsMergedTest() {
String result = populator.populate(getEvents(1, 2, 1, 2, 3), "V");
- Assert.assertEquals("1.0, 2.0, 3.0", result);
+ Assertions.assertEquals("1.0, 2.0, 3.0", result);
}
@Test
public void typeOneEventTest() {
String result = populator.populate(getEvents(1), "T");
- Assert.assertEquals("type1", result);
+ Assertions.assertEquals("type1", result);
}
@Test
public void typeSeveralEventsTest() {
String result = populator.populate(getEvents(1, 2, 3), "T");
- Assert.assertEquals("type1, type2, type3", result);
+ Assertions.assertEquals("type1, type2, type3", result);
}
@Test
public void sameTypesMergedTest() {
String result = populator.populate(getEvents(1, 2, 1, 2, 3), "T");
- Assert.assertEquals("type1, type2, type3", result);
+ Assertions.assertEquals("type1, type2, type3", result);
}
@Test
public void complexFormatTest() {
String result = populator.populate(getEvents(1, 2, 1, 2, 3), "'module:'P #V (T)");
- Assert.assertEquals("module:product1 #1.0 (type1), module:product2 #2.0 (type2), module:product3 #3.0 (type3)", result);
+ Assertions.assertEquals("module:product1 #1.0 (type1), module:product2 #2.0 (type2), module:product3 #3.0 (type3)", result);
}
@Test
@@ -130,14 +129,14 @@ public void humanReadableNormalizationTest() {
new ITextTestEvent(new SequenceId(), productData, null, "testing"),
"nonproduction", "iText product");
String result = populator.populate(Arrays.asList(event), "'module:'P #V (T)");
- Assert.assertEquals("module:public-name #1.0.0 (non-production)", result);
+ Assertions.assertEquals("module:public-name #1.0.0 (non-production)", result);
}
@Test
public void invalidLetterFormatTest() {
- Exception exception = Assert.assertThrows(IllegalArgumentException.class,
+ Exception exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> populator.populate(getEvents(1), "PVTX"));
- Assert.assertEquals(
+ Assertions.assertEquals(
MessageFormatUtil.format(CommonsExceptionMessageConstant.PATTERN_CONTAINS_UNEXPECTED_CHARACTER, "X"),
exception.getMessage());
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdManagerTest.java b/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdManagerTest.java
index ec8031bbe0..f09218a91e 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdManagerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdManagerTest.java
@@ -25,23 +25,22 @@ This file is part of the iText (R) project.
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class SequenceIdManagerTest extends ExtendedITextTest {
@Test
public void setIdentifier() {
IdentifiableElement element = new IdentifiableElement();
- Assert.assertNull(SequenceIdManager.getSequenceId(element));
+ Assertions.assertNull(SequenceIdManager.getSequenceId(element));
SequenceId sequenceId = new SequenceId();
SequenceIdManager.setSequenceId(element, sequenceId);
- Assert.assertEquals(sequenceId, SequenceIdManager.getSequenceId(element));
+ Assertions.assertEquals(sequenceId, SequenceIdManager.getSequenceId(element));
}
@Test
@@ -51,10 +50,10 @@ public void overrideIdentifierTest() {
SequenceId sequenceId2 = new SequenceId();
SequenceIdManager.setSequenceId(element, sequenceId1);
- Exception e = Assert.assertThrows(IllegalStateException.class,
+ Exception e = Assertions.assertThrows(IllegalStateException.class,
() -> SequenceIdManager.setSequenceId(element, sequenceId2));
- Assert.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.ELEMENT_ALREADY_HAS_IDENTIFIER,
+ Assertions.assertEquals(MessageFormatUtil.format(CommonsExceptionMessageConstant.ELEMENT_ALREADY_HAS_IDENTIFIER,
sequenceId1.getId(), sequenceId2.getId()), e.getMessage());
}
diff --git a/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdTest.java b/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdTest.java
index ab29afe153..18db11bf30 100644
--- a/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/actions/sequence/SequenceIdTest.java
@@ -23,19 +23,18 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.actions.sequence;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class SequenceIdTest extends ExtendedITextTest {
@Test
public void differentIdsCreatedTest() {
SequenceId sequenceId1 = new SequenceId();
SequenceId sequenceId2 = new SequenceId();
- Assert.assertNotEquals(sequenceId1.getId(), sequenceId2.getId());
+ Assertions.assertNotEquals(sequenceId1.getId(), sequenceId2.getId());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/datastructures/BiMapTest.java b/commons/src/test/java/com/itextpdf/commons/datastructures/BiMapTest.java
index b91adcede4..74a270be41 100644
--- a/commons/src/test/java/com/itextpdf/commons/datastructures/BiMapTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/datastructures/BiMapTest.java
@@ -23,33 +23,32 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.datastructures;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class BiMapTest extends ExtendedITextTest {
@Test
public void sizeTest01() {
BiMap map = new BiMap();
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
@Test
public void sizeTest02() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertEquals(1, map.size());
+ Assertions.assertEquals(1, map.size());
}
@Test
public void isEmptyTest01() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertFalse(map.isEmpty());
+ Assertions.assertFalse(map.isEmpty());
}
@@ -57,8 +56,8 @@ public void isEmptyTest01() {
public void putTest() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertEquals(1, (int) map.getByKey("a"));
- Assert.assertEquals("a", map.getByValue(1));
+ Assertions.assertEquals(1, (int) map.getByKey("a"));
+ Assertions.assertEquals("a", map.getByValue(1));
}
@Test
@@ -66,8 +65,8 @@ public void putOnExistingKey() {
BiMap map = new BiMap();
map.put("a", 1);
map.put("a", 2);
- Assert.assertEquals(2, (int) map.getByKey("a"));
- Assert.assertEquals("a", map.getByValue(2));
+ Assertions.assertEquals(2, (int) map.getByKey("a"));
+ Assertions.assertEquals("a", map.getByValue(2));
}
@Test
@@ -75,8 +74,8 @@ public void putOnExistingValue() {
BiMap map = new BiMap();
map.put("a", 1);
map.put("b", 1);
- Assert.assertEquals(1, (int) map.getByKey("b"));
- Assert.assertEquals("b", map.getByValue(1));
+ Assertions.assertEquals(1, (int) map.getByKey("b"));
+ Assertions.assertEquals("b", map.getByValue(1));
}
@Test
@@ -84,8 +83,8 @@ public void putOnExistingKeyAndValue() {
BiMap map = new BiMap();
map.put("a", 1);
map.put("a", 1);
- Assert.assertEquals(1, (int) map.getByKey("a"));
- Assert.assertEquals("a", map.getByValue(1));
+ Assertions.assertEquals(1, (int) map.getByKey("a"));
+ Assertions.assertEquals("a", map.getByValue(1));
}
@Test
@@ -94,13 +93,13 @@ public void putMultipleValues() {
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
- Assert.assertEquals(1, (int) map.getByKey("a"));
- Assert.assertEquals("a", map.getByValue(1));
- Assert.assertEquals(2, (int) map.getByKey("b"));
- Assert.assertEquals("b", map.getByValue(2));
- Assert.assertEquals(3, (int) map.getByKey("c"));
- Assert.assertEquals("c", map.getByValue(3));
- Assert.assertEquals(3, map.size());
+ Assertions.assertEquals(1, (int) map.getByKey("a"));
+ Assertions.assertEquals("a", map.getByValue(1));
+ Assertions.assertEquals(2, (int) map.getByKey("b"));
+ Assertions.assertEquals("b", map.getByValue(2));
+ Assertions.assertEquals(3, (int) map.getByKey("c"));
+ Assertions.assertEquals("c", map.getByValue(3));
+ Assertions.assertEquals(3, map.size());
}
@@ -109,35 +108,35 @@ public void clearTest() {
BiMap map = new BiMap();
map.put("a", 1);
map.clear();
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
@Test
public void containsKeyTest() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertTrue(map.containsKey("a"));
+ Assertions.assertTrue(map.containsKey("a"));
}
@Test
public void containsValueTest() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertTrue(map.containsValue(1));
+ Assertions.assertTrue(map.containsValue(1));
}
@Test
public void getByValue() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertEquals(1, (int) map.getByKey("a"));
+ Assertions.assertEquals(1, (int) map.getByKey("a"));
}
@Test
public void getByKey() {
BiMap map = new BiMap();
map.put("a", 1);
- Assert.assertEquals("a", map.getByValue(1));
+ Assertions.assertEquals("a", map.getByValue(1));
}
@Test
@@ -145,7 +144,7 @@ public void removeByKey() {
BiMap map = new BiMap();
map.put("a", 1);
map.removeByKey("a");
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
@Test
@@ -153,7 +152,7 @@ public void removeByValue() {
BiMap map = new BiMap();
map.put("a", 1);
map.removeByValue(1);
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
@Test
@@ -161,7 +160,7 @@ public void removeOnEmptyMap() {
BiMap map = new BiMap();
map.removeByKey("a");
map.removeByValue(1);
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/datastructures/ConcurrentWeakMapTest.java b/commons/src/test/java/com/itextpdf/commons/datastructures/ConcurrentWeakMapTest.java
index 8dd99c86a5..ccffedd0f4 100644
--- a/commons/src/test/java/com/itextpdf/commons/datastructures/ConcurrentWeakMapTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/datastructures/ConcurrentWeakMapTest.java
@@ -23,16 +23,15 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.datastructures;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ConcurrentWeakMapTest extends ExtendedITextTest {
@Test
public void sizeTest() {
@@ -41,69 +40,69 @@ public void sizeTest() {
map.put(3, 0);
map.put(6, 2);
map.put(5, 2);
- Assert.assertEquals(3, map.size());
+ Assertions.assertEquals(3, map.size());
}
@Test
public void isEmptyMapNotEmptyTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertFalse(map.isEmpty());
+ Assertions.assertFalse(map.isEmpty());
}
@Test
public void isEmptyMapEmptyTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
- Assert.assertTrue(map.isEmpty());
+ Assertions.assertTrue(map.isEmpty());
}
@Test
public void containsKeyTrueTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertTrue(map.containsKey(5));
+ Assertions.assertTrue(map.containsKey(5));
}
@Test
public void containsKeyFalseTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertFalse(map.containsKey(6));
+ Assertions.assertFalse(map.containsKey(6));
}
@Test
public void containsValueTrueTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertTrue(map.containsValue(6));
+ Assertions.assertTrue(map.containsValue(6));
}
@Test
public void containsValueFalseTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertFalse(map.containsValue(5));
+ Assertions.assertFalse(map.containsValue(5));
}
@Test
public void getTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertEquals(6, (int) map.get(5));
+ Assertions.assertEquals(6, (int) map.get(5));
}
@Test
public void putTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertEquals(6, (int) map.put(5, 10));
+ Assertions.assertEquals(6, (int) map.put(5, 10));
}
@Test
public void removeTest() {
ConcurrentWeakMap map = new ConcurrentWeakMap<>();
map.put(5, 6);
- Assert.assertEquals(6, (int) map.remove(5));
+ Assertions.assertEquals(6, (int) map.remove(5));
}
@Test
@@ -118,8 +117,8 @@ public void putAllTest() {
map.putAll(anotherMap);
- Assert.assertEquals(10, (int) map.get(5));
- Assert.assertEquals(3, map.size());
+ Assertions.assertEquals(10, (int) map.get(5));
+ Assertions.assertEquals(3, map.size());
}
@Test
@@ -131,7 +130,7 @@ public void clearTest() {
map.clear();
- Assert.assertEquals(0, map.size());
+ Assertions.assertEquals(0, map.size());
}
@Test
@@ -146,7 +145,7 @@ public void keySetTest() {
map.putAll(anotherMap);
- Assert.assertEquals(anotherMap.keySet(), map.keySet());
+ Assertions.assertEquals(anotherMap.keySet(), map.keySet());
}
@Test
@@ -162,9 +161,9 @@ public void valuesTest() {
map.putAll(anotherMap);
Collection values = map.values();
- Assert.assertEquals(3, values.size());
- Assert.assertTrue(values.contains(10));
- Assert.assertFalse(values.contains(6));
+ Assertions.assertEquals(3, values.size());
+ Assertions.assertTrue(values.contains(10));
+ Assertions.assertFalse(values.contains(6));
}
@Test
@@ -179,6 +178,6 @@ public void entrySetTest() {
map.putAll(anotherMap);
- Assert.assertEquals(anotherMap.entrySet(), map.entrySet());
+ Assertions.assertEquals(anotherMap.entrySet(), map.entrySet());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/datastructures/Tuple2Test.java b/commons/src/test/java/com/itextpdf/commons/datastructures/Tuple2Test.java
index 884885c6ae..1fc5d83ad0 100644
--- a/commons/src/test/java/com/itextpdf/commons/datastructures/Tuple2Test.java
+++ b/commons/src/test/java/com/itextpdf/commons/datastructures/Tuple2Test.java
@@ -23,14 +23,13 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.datastructures;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class Tuple2Test extends ExtendedITextTest {
@Test
diff --git a/commons/src/test/java/com/itextpdf/commons/datastructures/portable/NullUnlimitedListTest.java b/commons/src/test/java/com/itextpdf/commons/datastructures/portable/NullUnlimitedListTest.java
new file mode 100644
index 0000000000..0dbe8eaedd
--- /dev/null
+++ b/commons/src/test/java/com/itextpdf/commons/datastructures/portable/NullUnlimitedListTest.java
@@ -0,0 +1,239 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.datastructures.portable;
+
+
+import com.itextpdf.commons.datastructures.ISimpleList;
+import com.itextpdf.commons.datastructures.NullUnlimitedList;
+import com.itextpdf.commons.datastructures.SimpleArrayList;
+import com.itextpdf.test.ExtendedITextTest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
+@Tag("UnitTest")
+public class NullUnlimitedListTest extends ExtendedITextTest {
+
+
+ @Test
+ public void nullUnlimitedListAddTest() {
+ NullUnlimitedList list = new NullUnlimitedList<>();
+ list.add("hey");
+ list.add("bye");
+ Assertions.assertEquals(2, list.size());
+ list.add(-1, "hello");
+ list.add(3, "goodbye");
+ Assertions.assertEquals(2, list.size());
+ }
+
+ @Test
+ public void nullUnlimitedListIndexOfTest() {
+ NullUnlimitedList list = new NullUnlimitedList<>();
+ list.add("hey");
+ list.add(null);
+ list.add("bye");
+ list.add(null);
+ Assertions.assertEquals(4, list.size());
+ Assertions.assertEquals(1, list.indexOf(null));
+ }
+
+ @Test
+ public void nullUnlimitedListRemoveTest() {
+ NullUnlimitedList list = new NullUnlimitedList<>();
+ list.add("hey");
+ list.add("bye");
+ Assertions.assertEquals(2, list.size());
+ list.remove(-1);
+ list.remove(2);
+ Assertions.assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ NullUnlimitedList list = new NullUnlimitedList<>();
+ Assertions.assertTrue(list.isEmpty());
+ list.add("hey");
+ Assertions.assertFalse(list.isEmpty());
+ }
+
+ @Test
+ public void testSameBehaviour01() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> Assertions.assertEquals(1, list.indexOf(null)));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour02() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> Assertions.assertEquals(4, list.size()));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour03() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> list.set(1, "4"));
+ actionList.add((list) -> Assertions.assertEquals(list.get(1), "4"));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour04() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add(null));
+ actionList.add((list) -> Assertions.assertEquals(1, list.indexOf(null)));
+
+ executeActions(actionList);
+ }
+
+
+ @Test
+ public void testSameBehaviour05() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> Assertions.assertEquals(-1, list.indexOf(null)));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour06() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> list.add("5"));
+ actionList.add((list) -> Assertions.assertEquals(4, list.indexOf("5")));
+
+ executeActions(actionList);
+ }
+
+
+ @Test
+ public void testSameBehaviour07() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> list.add("5"));
+ actionList.add((list) -> Assertions.assertEquals(-1, list.indexOf("6")));
+
+ executeActions(actionList);
+ }
+
+
+ @Test
+ public void testSameBehaviour08() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> list.add(2, "5"));
+ actionList.add((list) -> Assertions.assertEquals(5, list.size()));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour09() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> list.set(2, null));
+ actionList.add((list) -> Assertions.assertEquals(4, list.size()));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour10() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> list.remove(2));
+ actionList.add((list) -> Assertions.assertEquals(3, list.size()));
+
+ executeActions(actionList);
+ }
+
+ @Test
+ public void testSameBehaviour11() {
+ List>> actionList = new ArrayList<>();
+ actionList.add((list) -> Assertions.assertTrue(list.isEmpty()));
+ actionList.add((list) -> list.add("1"));
+ actionList.add((list) -> Assertions.assertFalse(list.isEmpty()));
+ actionList.add((list) -> list.add("2"));
+ actionList.add((list) -> list.add("3"));
+ actionList.add((list) -> list.add("4"));
+ actionList.add((list) -> Assertions.assertFalse(list.isEmpty()));
+
+ executeActions(actionList);
+ }
+
+ public void executeActions(List>> actionList) {
+ NullUnlimitedList list = new NullUnlimitedList<>();
+ SimpleArrayList list2 = new SimpleArrayList<>();
+ for (Consumer> action : actionList) {
+ action.accept(list);
+ action.accept(list2);
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/commons/src/test/java/com/itextpdf/commons/datastructures/portable/SimpleArrayListTest.java b/commons/src/test/java/com/itextpdf/commons/datastructures/portable/SimpleArrayListTest.java
new file mode 100644
index 0000000000..f50377ab61
--- /dev/null
+++ b/commons/src/test/java/com/itextpdf/commons/datastructures/portable/SimpleArrayListTest.java
@@ -0,0 +1,116 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.datastructures.portable;
+
+import com.itextpdf.commons.datastructures.SimpleArrayList;
+import com.itextpdf.test.ExtendedITextTest;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@Tag("UnitTest")
+public class SimpleArrayListTest extends ExtendedITextTest {
+
+ @Test
+ public void add01() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ assertEquals(3, list.size());
+ assertEquals(1, list.get(0));
+ assertEquals(2, list.get(1));
+ assertEquals(3, list.get(2));
+ }
+
+ @Test
+ public void add02() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(3);
+ list.add(2, 2);
+ assertEquals(3, list.size());
+ }
+
+
+ @Test
+ public void set01() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ assertEquals(2, list.set(1, 4));
+ assertEquals(4, list.get(1));
+ }
+
+
+ @Test
+ public void indexOf01() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ assertEquals(0, list.indexOf(1));
+ assertEquals(1, list.indexOf(2));
+ assertEquals(2, list.indexOf(3));
+ }
+
+ @Test
+ public void remove() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.remove(1);
+ assertEquals(2, list.size());
+ assertEquals(1, list.get(0));
+ assertEquals(3, list.get(1));
+ }
+
+ @Test
+ public void size() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void initializeWithCapacity() {
+ SimpleArrayList list = new SimpleArrayList<>(20);
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void isEmpty() {
+ SimpleArrayList list = new SimpleArrayList<>();
+ assertTrue(list.isEmpty());
+ list.add(1);
+ assertFalse(list.isEmpty());
+ }
+}
\ No newline at end of file
diff --git a/commons/src/test/java/com/itextpdf/commons/exceptions/AggregatedExceptionTest.java b/commons/src/test/java/com/itextpdf/commons/exceptions/AggregatedExceptionTest.java
index a6eb0882d8..dcc0c3bdd8 100644
--- a/commons/src/test/java/com/itextpdf/commons/exceptions/AggregatedExceptionTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/exceptions/AggregatedExceptionTest.java
@@ -23,15 +23,14 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.exceptions;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class AggregatedExceptionTest extends ExtendedITextTest {
@Test
@@ -42,8 +41,8 @@ public void aggregatedMessageWithGeneralMessageTest() {
exceptions.add(new CustomException("Message 3"));
AggregatedException exception = new AggregatedException("General message", exceptions);
- Assert.assertEquals(exceptions, exception.getAggregatedExceptions());
- Assert.assertEquals("General message:\n"
+ Assertions.assertEquals(exceptions, exception.getAggregatedExceptions());
+ Assertions.assertEquals("General message:\n"
+ "0) Message 1\n"
+ "1) Message 2\n"
+ "2) Message 3\n", exception.getMessage());
@@ -57,7 +56,7 @@ public void aggregatedMessageWithoutGeneralMessageTest() {
exceptions.add(new CustomException("Message 3"));
AggregatedException exception = new AggregatedException(exceptions);
- Assert.assertEquals("Aggregated message:\n"
+ Assertions.assertEquals("Aggregated message:\n"
+ "0) Message 1\n"
+ "1) Message 2\n"
+ "2) Message 3\n", exception.getMessage());
diff --git a/commons/src/test/java/com/itextpdf/commons/exceptions/ITextExceptionTest.java b/commons/src/test/java/com/itextpdf/commons/exceptions/ITextExceptionTest.java
index 607a8e467e..7627bf8240 100644
--- a/commons/src/test/java/com/itextpdf/commons/exceptions/ITextExceptionTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/exceptions/ITextExceptionTest.java
@@ -23,37 +23,36 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.exceptions;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class ITextExceptionTest extends ExtendedITextTest {
@Test
public void noParametersConstructorTest() {
- Exception exception = Assert.assertThrows(ITextException.class, () -> {
+ Exception exception = Assertions.assertThrows(ITextException.class, () -> {
throw new ITextException();
});
- Assert.assertEquals(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.getMessage());
+ Assertions.assertEquals(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.getMessage());
}
@Test
public void stringConstructorTest() {
- Exception exception = Assert.assertThrows(ITextException.class, () -> {
+ Exception exception = Assertions.assertThrows(ITextException.class, () -> {
throw new ITextException("message");
});
- Assert.assertEquals("message", exception.getMessage());
+ Assertions.assertEquals("message", exception.getMessage());
}
@Test
public void throwableConstructorTest() {
RuntimeException cause = new RuntimeException("cause");
- Exception exception = Assert.assertThrows(ITextException.class, () -> {
+ Exception exception = Assertions.assertThrows(ITextException.class, () -> {
throw new ITextException(cause);
});
- Assert.assertEquals(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.getMessage());
- Assert.assertEquals(cause, exception.getCause());
+ Assertions.assertEquals(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.getMessage());
+ Assertions.assertEquals(cause, exception.getCause());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/Base64Test.java b/commons/src/test/java/com/itextpdf/commons/utils/Base64Test.java
index 2e60771e77..fd6052cf90 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/Base64Test.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/Base64Test.java
@@ -23,23 +23,22 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.utils;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class Base64Test extends ExtendedITextTest {
@Test
public void testEncodeObjectForNullObject() {
- Assert.assertEquals("rO0ABXA=", Base64.encodeObject(null));
+ Assertions.assertEquals("rO0ABXA=", Base64.encodeObject(null));
}
@Test
public void testDecodeForSourceIsEmptyArray() {
- Assert.assertEquals("", Base64.encodeBytes(new byte[] {}));
+ Assertions.assertEquals("", Base64.encodeBytes(new byte[] {}));
}
@Test
@@ -61,8 +60,8 @@ public void testDecodeForSourceIsEmptyArrayGzip() {
String generatedHeader = generatedBase64.substring(startIndexHeader, endIndexHeaderWithoutOsFlag);
String generatedFooter = generatedBase64.substring(startIndexFooter, endIndexFooter);
- Assert.assertEquals(expectedHeaderWithoutOsFlag, generatedHeader);
- Assert.assertEquals(expectedFooter, generatedFooter);
+ Assertions.assertEquals(expectedHeaderWithoutOsFlag, generatedHeader);
+ Assertions.assertEquals(expectedFooter, generatedFooter);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/DIContainerTest.java b/commons/src/test/java/com/itextpdf/commons/utils/DIContainerTest.java
index 56443aaceb..9a85c3307a 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/DIContainerTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/DIContainerTest.java
@@ -23,27 +23,26 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.utils;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class DIContainerTest extends ExtendedITextTest {
@Test
public void testGetRegisteredInstance() {
DIContainer di = new DIContainer();
di.register(String.class, "hello");
- Assert.assertEquals("hello", di.getInstance(String.class));
+ Assertions.assertEquals("hello", di.getInstance(String.class));
}
@Test
public void testRegisterDefaultInstance() {
DIContainer.registerDefault(String.class, () -> "hello");
DIContainer di = new DIContainer();
- Assert.assertEquals("hello", di.getInstance(String.class));
+ Assertions.assertEquals("hello", di.getInstance(String.class));
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/DateTimeUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/DateTimeUtilTest.java
index e8f6254d84..148d74c325 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/DateTimeUtilTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/DateTimeUtilTest.java
@@ -23,17 +23,16 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.utils;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class DateTimeUtilTest extends ExtendedITextTest {
private static final double ZERO_DELTA = 1e-6;
@@ -43,13 +42,13 @@ public class DateTimeUtilTest extends ExtendedITextTest {
public void getCurrentTest() {
long nowEpoch = new Date().getTime();
long nowDateTimeUtilEpoch = DateTimeUtil.getCurrentTimeDate().getTime();
- Assert.assertEquals(nowEpoch, nowDateTimeUtilEpoch, ONE_SECOND_DELTA);
+ Assertions.assertEquals(nowEpoch, nowDateTimeUtilEpoch, ONE_SECOND_DELTA);
}
@Test
public void isInPastTest() {
Date date = new Date(1);
- Assert.assertTrue(DateTimeUtil.isInPast(date));
+ Assertions.assertTrue(DateTimeUtil.isInPast(date));
}
@Test
@@ -61,28 +60,28 @@ public void parseDateAndGetUtcMillisFromEpochTest() {
long offset = DateTimeUtil.getCurrentTimeZoneOffset(date);
- Assert.assertEquals(1588636800000d - offset, millisFromEpochTo2020_05_05, ZERO_DELTA);
+ Assertions.assertEquals(1588636800000d - offset, millisFromEpochTo2020_05_05, ZERO_DELTA);
}
@Test
public void getCalenderForNullDateTest() {
Calendar result = DateTimeUtil.getCalendar(null);
- Assert.assertNull(result);
+ Assertions.assertNull(result);
}
@Test
public void getCalenderTest() {
Date testDate = DateTimeUtil.getCurrentTimeDate();
Calendar result = DateTimeUtil.getCalendar(testDate);
- Assert.assertNotNull(result);
- Assert.assertEquals(testDate, result.getTime());
+ Assertions.assertNotNull(result);
+ Assertions.assertEquals(testDate, result.getTime());
}
@Test
public void addMillisToDateTest() {
Date almostCurrentTime = new Date(new Date().getTime() - 2000);
long twoSeconds = 2000;
- Assert.assertEquals(new Date().getTime(),
+ Assertions.assertEquals(new Date().getTime(),
DateTimeUtil.addMillisToDate(almostCurrentTime, twoSeconds).getTime(), ONE_SECOND_DELTA);
}
@@ -91,7 +90,7 @@ public void compareUtcMillisFromEpochWithNullParamAndCurrentTimeTest() {
double getUtcMillisFromEpochWithNullParam = DateTimeUtil.getUtcMillisFromEpoch(null);
double millisFromEpochToCurrentTime = DateTimeUtil.getUtcMillisFromEpoch(DateTimeUtil.getCurrentTimeCalendar());
- Assert.assertEquals(millisFromEpochToCurrentTime, getUtcMillisFromEpochWithNullParam, ONE_SECOND_DELTA);
+ Assertions.assertEquals(millisFromEpochToCurrentTime, getUtcMillisFromEpochWithNullParam, ONE_SECOND_DELTA);
}
@Test
@@ -101,7 +100,7 @@ public void parseDateAndGetRelativeTimeTest() {
long offset = DateTimeUtil.getCurrentTimeZoneOffset(date);
- Assert.assertEquals(1588636800000d - offset, relativeTime, ZERO_DELTA);
+ Assertions.assertEquals(1588636800000d - offset, relativeTime, ZERO_DELTA);
}
@Test
@@ -111,7 +110,7 @@ public void addYearPositiveValueTest () {
Date newDate = DateTimeUtil.addYearsToDate(originalDate.getTime(), 5);
- Assert.assertEquals(2005, newDate.getYear());
+ Assertions.assertEquals(2005, newDate.getYear());
}
@Test
@@ -121,6 +120,6 @@ public void addYearNegativeValueTest () {
Date newDate = DateTimeUtil.addYearsToDate(originalDate.getTime(), -3);
- Assert.assertEquals(1997, newDate.getYear());
+ Assertions.assertEquals(1997, newDate.getYear());
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/FileUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/FileUtilTest.java
new file mode 100644
index 0000000000..bae409e00a
--- /dev/null
+++ b/commons/src/test/java/com/itextpdf/commons/utils/FileUtilTest.java
@@ -0,0 +1,74 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.commons.utils;
+
+import com.itextpdf.test.ExtendedITextTest;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag("UnitTest")
+public class FileUtilTest extends ExtendedITextTest {
+
+ public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/commons/utils/FileUtilTest/";
+
+ @BeforeAll
+ public static void beforeClass() {
+ createOrClearDestinationFolder(DESTINATION_FOLDER);
+ }
+
+ @Test
+ public void getBufferedOutputStreamTest() throws IOException {
+ String filePath = DESTINATION_FOLDER + "bufferedOutput.txt";
+ String text = "Hello world!";
+
+ try (OutputStream out = FileUtil.getBufferedOutputStream(filePath)) {
+ out.write(text.getBytes(StandardCharsets.UTF_8));
+ }
+
+ byte[] resultBytes = Files.readAllBytes(Paths.get(filePath));
+ Assertions.assertEquals(text, new String(resultBytes, StandardCharsets.UTF_8));
+ }
+
+ @Test
+ public void getFileOutputStreamTest() throws IOException {
+ String filePath = DESTINATION_FOLDER + "fileOutput.txt";
+ File file = new File(filePath);
+ String text = "Hello world!";
+
+ try (OutputStream out = FileUtil.getFileOutputStream(file)) {
+ out.write(text.getBytes(StandardCharsets.UTF_8));
+ }
+
+ byte[] resultBytes = Files.readAllBytes(Paths.get(filePath));
+ Assertions.assertEquals(text, new String(resultBytes, StandardCharsets.UTF_8));
+ }
+}
\ No newline at end of file
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java
index 56191896d1..c4fd95c99f 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/JsonUtilTest.java
@@ -27,7 +27,6 @@ This file is part of the iText (R) project.
import com.itextpdf.test.LogLevelConstants;
import com.itextpdf.test.annotations.LogMessage;
import com.itextpdf.test.annotations.LogMessages;
-import com.itextpdf.test.annotations.type.UnitTest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -42,11 +41,11 @@ This file is part of the iText (R) project.
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class JsonUtilTest extends ExtendedITextTest {
private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/commons/utils/JsonUtilTest/";
@@ -61,14 +60,14 @@ public class JsonUtilTest extends ExtendedITextTest {
@Test
public void utf8CharsetStringTest() {
- Assert.assertEquals("\"©\"", JsonUtil.serializeToString("©"));
+ Assertions.assertEquals("\"©\"", JsonUtil.serializeToString("©"));
}
@Test
public void utf8CharsetStreamTest() throws UnsupportedEncodingException {
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
JsonUtil.serializeToStream(byteArray, "©");
- Assert.assertEquals("\"©\"",
+ Assertions.assertEquals("\"©\"",
EncodingUtil.convertToString(byteArray.toByteArray(), "UTF-8"));
}
@@ -80,7 +79,7 @@ public void serializeInstanceWithEnumStringTest() throws IOException {
String resultString = JsonUtil.serializeToString(classWithEnum);
String cmpString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(cmpString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(cmpString, resultString));
}
@Test
@@ -100,7 +99,7 @@ public void serializeInstanceWithEnumStreamTest() throws IOException {
JsonUtil.serializeToStream(serializationResult, createClassWithEnumObject());
serializationResult.flush();
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -112,7 +111,7 @@ public void serializeToMinimalInstanceWithEnumStringTest() throws IOException {
String resultString = JsonUtil.serializeToMinimalString(classWithEnum);
String compareString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
}
@Test
@@ -132,7 +131,7 @@ public void serializeToMinimalInstanceWithEnumStreamTest() throws IOException {
JsonUtil.serializeToMinimalStream(serializationResult, createClassWithEnumObject());
serializationResult.flush();
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -144,7 +143,7 @@ public void serializeStringWithLineBreakStringTest() throws IOException {
String resultString = JsonUtil.serializeToString(stringsForSerialization);
String cmpString = getJsonStringFromFile(cmp);
- Assert.assertEquals(cmpString,resultString);
+ Assertions.assertEquals(cmpString,resultString);
}
@Test
@@ -156,7 +155,7 @@ public void serializeStringWithLineBreakStreamTest() throws IOException {
ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) {
JsonUtil.serializeToStream(serializationResult, createStringWithLineBreaks());
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -168,7 +167,7 @@ public void serializeToMinimalStringWithLineBreakStringTest() throws IOException
String resultString = JsonUtil.serializeToMinimalString(stringsForSerialization);
String cmpString = getJsonStringFromFile(cmp);
- Assert.assertEquals(cmpString,resultString);
+ Assertions.assertEquals(cmpString,resultString);
}
@Test
@@ -180,7 +179,7 @@ public void serializeToMinimalStringWithLineBreakStreamTest() throws IOException
ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) {
JsonUtil.serializeToMinimalStream(serializationResult, createStringWithLineBreaks());
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -192,7 +191,7 @@ public void serializeComplexStructureStringTest() throws IOException {
String resultString = JsonUtil.serializeToString(complexStructure);
String compareString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
}
@Test
@@ -211,8 +210,8 @@ public void serializeComplexStructureStreamTest() throws IOException {
ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) {
JsonUtil.serializeToStream(serializationResult, createComplexStructureObject());
- Assert.assertNotEquals(0, serializationResult.size());
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertNotEquals(0, serializationResult.size());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -224,7 +223,7 @@ public void serializeToMinimalComplexStructureStringTest() throws IOException {
String resultString = JsonUtil.serializeToMinimalString(complexStructure);
String compareString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
}
@Test
@@ -243,8 +242,8 @@ public void serializeToMinimalComplexStructureStreamTest() throws IOException {
ByteArrayOutputStream serializationResult = new ByteArrayOutputStream()) {
JsonUtil.serializeToMinimalStream(serializationResult, createComplexStructureObject());
- Assert.assertNotEquals(0, serializationResult.size());
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertNotEquals(0, serializationResult.size());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -257,7 +256,7 @@ public void serializeWithNullFieldsStringTest() throws IOException {
String resultString = JsonUtil.serializeToString(complexStructure);
String compareString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
}
@Test
@@ -270,7 +269,7 @@ public void serializeWithNullFieldsStreamTest() throws IOException {
JsonUtil.serializeToStream(serializationResult,
createClassWithDefaultValueObject(null, 4, null));
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -283,7 +282,7 @@ public void serializeToMinimalWithNullFieldsStringTest() throws IOException {
String resultString = JsonUtil.serializeToMinimalString(complexStructure);
String compareString = getJsonStringFromFile(cmp);
- Assert.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
+ Assertions.assertTrue(JsonUtil.areTwoJsonObjectEquals(compareString, resultString));
}
@Test
@@ -296,7 +295,7 @@ public void serializeToMinimalWithNullFieldsStreamTest() throws IOException {
JsonUtil.serializeToMinimalStream(serializationResult,
createClassWithDefaultValueObject(null, 4, null));
- Assert.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
+ Assertions.assertArrayEquals(baos.toByteArray(), serializationResult.toByteArray());
}
}
@@ -311,7 +310,7 @@ public void deserializeInvalidJsonFileStringTest() throws IOException {
String jsonString = getJsonStringFromFile(source);
String resultStr = JsonUtil.deserializeFromString(jsonString, String.class);
- Assert.assertNull(resultStr);
+ Assertions.assertNull(resultStr);
}
@Test
@@ -324,7 +323,7 @@ public void deserializeInvalidJsonFileStreamTest() throws IOException {
try (InputStream inputStream = FileUtil.getInputStreamForFile(source)) {
String resultStr = JsonUtil.deserializeFromStream(inputStream, String.class);
- Assert.assertNull(resultStr);
+ Assertions.assertNull(resultStr);
}
}
@@ -336,7 +335,7 @@ public void deserializeWithDefaultValueStringTest() throws IOException {
ClassWithDefaultValue instance =
JsonUtil.deserializeFromString(jsonString, ClassWithDefaultValue.class);
- Assert.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
+ Assertions.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
}
@Test
@@ -346,7 +345,7 @@ public void deserializeWithDefaultValueStreamTest() throws IOException {
try (InputStream inputStream = FileUtil.getInputStreamForFile(source)) {
ClassWithDefaultValue instance =
JsonUtil.deserializeFromStream(inputStream, ClassWithDefaultValue.class);
- Assert.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
+ Assertions.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
}
}
@@ -359,7 +358,7 @@ public void deserializeComplexStructureStringTest() throws IOException {
ComplexStructure complexStructure =
JsonUtil.deserializeFromString(jsonString, ComplexStructure.class);
- Assert.assertEquals(createComplexStructureObject(), complexStructure);
+ Assertions.assertEquals(createComplexStructureObject(), complexStructure);
}
@Test
@@ -370,7 +369,7 @@ public void deserializeComplexStructureStreamTest() throws IOException {
ComplexStructure complexStructure =
JsonUtil.deserializeFromStream(inputStream, ComplexStructure.class);
- Assert.assertEquals(createComplexStructureObject(), complexStructure);
+ Assertions.assertEquals(createComplexStructureObject(), complexStructure);
}
}
@@ -382,7 +381,7 @@ public void deserializeInstanceWithEnumStringTest() throws IOException {
ClassWithEnum classWithEnum = JsonUtil.deserializeFromString(jsonString, ClassWithEnum.class);
- Assert.assertEquals(createClassWithEnumObject(), classWithEnum);
+ Assertions.assertEquals(createClassWithEnumObject(), classWithEnum);
}
@Test
@@ -393,7 +392,7 @@ public void deserializeInstanceWithEnumStreamTest() throws IOException {
ClassWithEnum classWithEnum = JsonUtil
.deserializeFromStream(inputStream, ClassWithEnum.class);
- Assert.assertEquals(createClassWithEnumObject(), classWithEnum);
+ Assertions.assertEquals(createClassWithEnumObject(), classWithEnum);
}
}
@@ -406,7 +405,7 @@ public void deserializeWithUnknownPropertiesStringTest() throws IOException {
ClassWithDefaultValue instance =
JsonUtil.deserializeFromString(jsonString, ClassWithDefaultValue.class);
- Assert.assertEquals(
+ Assertions.assertEquals(
createClassWithDefaultValueObject("some small string", 8, 26.0), instance);
}
@@ -418,8 +417,8 @@ public void deserializeWithUnknownPropertiesStreamTest() throws IOException {
ClassWithDefaultValue instance =
JsonUtil.deserializeFromStream(inputStream, ClassWithDefaultValue.class);
- Assert.assertNotNull(instance);
- Assert.assertEquals(
+ Assertions.assertNotNull(instance);
+ Assertions.assertEquals(
createClassWithDefaultValueObject("some small string", 8, 26.0), instance);
}
}
@@ -433,7 +432,7 @@ public void deserializeWithDefaultValueTypeReferenceStreamTest() throws IOExcept
JsonUtil.deserializeFromStream(inputStream,
new TypeReference() {
});
- Assert.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
+ Assertions.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
}
}
@@ -447,7 +446,7 @@ public void deserializeWithDefaultValueTypeReferenceStringTest() throws IOExcept
JsonUtil.deserializeFromString(jsonString,
new TypeReference() {
});
- Assert.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
+ Assertions.assertEquals(createClassWithDefaultValueObject(null, 2, 5.0), instance);
}
private String getJsonStringFromFile(String pathToFile) throws IOException {
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/MapUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/MapUtilTest.java
index bfbda31588..e65a6d0994 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/MapUtilTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/MapUtilTest.java
@@ -23,33 +23,32 @@ This file is part of the iText (R) project.
package com.itextpdf.commons.utils;
import com.itextpdf.test.ExtendedITextTest;
-import com.itextpdf.test.annotations.type.UnitTest;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class MapUtilTest extends ExtendedITextTest {
@Test
public void nullMapsAreEqualTest() {
- Assert.assertTrue(MapUtil.equals(null, null));
+ Assertions.assertTrue(MapUtil.equals(null, null));
}
@Test
public void nullMapIsNotEqualToEmptyMapTest() {
- Assert.assertFalse(MapUtil.equals(new HashMap(), null));
- Assert.assertFalse(MapUtil.equals(null, new HashMap()));
+ Assertions.assertFalse(MapUtil.equals(new HashMap(), null));
+ Assertions.assertFalse(MapUtil.equals(null, new HashMap()));
}
@Test
public void mapsOfDifferentTypesAreNotEqualTest() {
- Assert.assertFalse(MapUtil.equals(new HashMap(), new TreeMap<>()));
+ Assertions.assertFalse(MapUtil.equals(new HashMap(), new TreeMap<>()));
}
@Test
@@ -61,7 +60,7 @@ public void mapsOfDifferentSizeAreNotEqualTest() {
m2.put("m1", "m1");
m2.put("m2", "m2");
- Assert.assertFalse(MapUtil.equals(m1, m2));
+ Assertions.assertFalse(MapUtil.equals(m1, m2));
}
@Test
@@ -69,7 +68,7 @@ public void nullValueInMapTest() {
Map m1 = Collections.singletonMap("nullKey", null);
Map m2 = Collections.singletonMap("notNullKey", "notNull");
- Assert.assertFalse(MapUtil.equals(m1, m2));
+ Assertions.assertFalse(MapUtil.equals(m1, m2));
}
@Test
@@ -79,7 +78,7 @@ public void mapsWithDifferentKeysAreNotEqualTest() {
Map m2 = new HashMap<>();
m2.put("m2", "value");
- Assert.assertFalse(MapUtil.equals(m1, m2));
+ Assertions.assertFalse(MapUtil.equals(m1, m2));
}
@Test
@@ -89,7 +88,7 @@ public void mapsWithDifferentValuesAreNotEqualTest() {
Map m2 = new HashMap<>();
m2.put("key", "m2");
- Assert.assertFalse(MapUtil.equals(m1, m2));
+ Assertions.assertFalse(MapUtil.equals(m1, m2));
}
@Test
@@ -99,33 +98,33 @@ public void equalArraysTest() {
Map m2 = new HashMap<>();
m2.put("key", "value");
- Assert.assertTrue(MapUtil.equals(m1, m2));
+ Assertions.assertTrue(MapUtil.equals(m1, m2));
}
@Test
public void putIfNotNullTest() {
Map m1 = new HashMap<>();
MapUtil.putIfNotNull(m1, "key", null);
- Assert.assertTrue(m1.isEmpty());
+ Assertions.assertTrue(m1.isEmpty());
MapUtil.putIfNotNull(m1, "key", "value");
- Assert.assertFalse(m1.isEmpty());
- Assert.assertEquals("value", m1.get("key"));
+ Assertions.assertFalse(m1.isEmpty());
+ Assertions.assertEquals("value", m1.get("key"));
}
@Test
public void nullMapsEqualEqualHashCodeTest() {
- Assert.assertEquals(MapUtil.getHashCode((Map)null), MapUtil.getHashCode((Map)null));
+ Assertions.assertEquals(MapUtil.getHashCode((Map)null), MapUtil.getHashCode((Map)null));
}
@Test
public void nullMapEmptyMapDiffHashCodeTest() {
- Assert.assertEquals(MapUtil.getHashCode((Map)null), MapUtil.getHashCode(new HashMap()));
+ Assertions.assertEquals(MapUtil.getHashCode((Map)null), MapUtil.getHashCode(new HashMap()));
}
@Test
public void mapsOfDifferentTypesHashCodeTest() {
- Assert.assertEquals(MapUtil.getHashCode(new TreeMap<>()),
+ Assertions.assertEquals(MapUtil.getHashCode(new TreeMap<>()),
MapUtil.getHashCode(new HashMap()));
}
@@ -136,7 +135,7 @@ public void equalMapsHashCodeTest() {
Map m2 = new HashMap<>();
m2.put("key", "value");
- Assert.assertEquals(MapUtil.getHashCode(m1), MapUtil.getHashCode(m2));
+ Assertions.assertEquals(MapUtil.getHashCode(m1), MapUtil.getHashCode(m2));
}
@Test
@@ -156,7 +155,7 @@ public void mapsMergeTest() {
expectedMap.put(2, 15);
expectedMap.put(3, 10);
expectedMap.put(4, 5);
- Assert.assertEquals(expectedMap, destination);
+ Assertions.assertEquals(expectedMap, destination);
}
@Test
@@ -168,6 +167,6 @@ public void sameMapsMergeTest() {
Map expectedMap = new HashMap<>(map);
MapUtil.merge(map, map, (d, s) -> d + s);
- Assert.assertEquals(expectedMap, map);
+ Assertions.assertEquals(expectedMap, map);
}
}
diff --git a/commons/src/test/java/com/itextpdf/commons/utils/MessageFormatUtilTest.java b/commons/src/test/java/com/itextpdf/commons/utils/MessageFormatUtilTest.java
index ac0c823e43..ef9c7a4e20 100644
--- a/commons/src/test/java/com/itextpdf/commons/utils/MessageFormatUtilTest.java
+++ b/commons/src/test/java/com/itextpdf/commons/utils/MessageFormatUtilTest.java
@@ -26,28 +26,14 @@ This file is part of the iText (R) project.
import java.util.Arrays;
-import com.itextpdf.test.annotations.type.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
-@RunWith(Parameterized.class)
-@Category(UnitTest.class)
+@Tag("UnitTest")
public class MessageFormatUtilTest extends ExtendedITextTest {
- private String expectedResult;
- private String pattern;
- private Object[] arguments;
-
- public MessageFormatUtilTest(Object expectedResult, Object pattern, Object arguments, Object name) {
- this.expectedResult = (String) expectedResult;
- this.pattern = (String) pattern;
- this.arguments = (Object[]) arguments;
- }
-
- @Parameterized.Parameters(name = "{index}: {3} format: {1}; {0}")
public static Iterable