Skip to content

Commit 14101de

Browse files
committed
Use Assumptions to skip tests when BouncyCastle is not available
1 parent 5bec0f5 commit 14101de

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.junit.jupiter.api.Test;
4646
import org.w3c.dom.Document;
4747

48+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
4849
import static org.junit.jupiter.api.Assertions.assertEquals;
4950
import static org.junit.jupiter.api.Assertions.assertFalse;
5051
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -104,9 +105,10 @@ void testConstructionWithProvider() throws Exception {
104105
assertFalse(algorithmHash.isEmpty());
105106

106107
Document doc = TestUtils.newDocument();
108+
Provider provider = null;
107109
try {
108110
Class<?> bouncyCastleProviderClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
109-
Provider provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
111+
provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
110112

111113
for (String algorithmURI : algorithmHash.keySet()) {
112114
try {
@@ -120,7 +122,8 @@ void testConstructionWithProvider() throws Exception {
120122
}
121123
}
122124
} catch (ReflectiveOperationException e) {
123-
// BouncyCastle not installed, ignore
125+
// BouncyCastle not installed, skip
126+
assumeFalse(provider == null);
124127
}
125128
}
126129

src/test/java/org/apache/xml/security/test/dom/signature/SignatureTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import static org.junit.jupiter.api.Assertions.assertEquals;
3838
import static org.junit.jupiter.api.Assertions.assertTrue;
39+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
3940

4041
class SignatureTest {
4142
public static final String DS_NS = "http://www.w3.org/2000/09/xmldsig#";
@@ -66,9 +67,10 @@ void testSigningVerifyingFromRebuildSignature() throws Throwable {
6667

6768
@Test
6869
void testSigningVerifyingFromRebuildSignatureWithProvider() throws Throwable {
70+
Provider provider = null;
6971
try {
7072
Class<?> bouncyCastleProviderClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
71-
Provider provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
73+
provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
7274

7375
Document doc = getOriginalDocument();
7476
XMLSignature signature = signDocument(doc, provider);
@@ -81,7 +83,8 @@ void testSigningVerifyingFromRebuildSignatureWithProvider() throws Throwable {
8183
PublicKey pubKey = getPublicKey();
8284
assertTrue(signature.checkSignatureValue(pubKey));
8385
} catch (ReflectiveOperationException e) {
84-
// BouncyCastle not installed, ignore
86+
// BouncyCastle not installed, skip
87+
assumeFalse(provider == null);
8588
}
8689
}
8790

@@ -96,17 +99,19 @@ void testSigningVerifyingFromExistingSignature() throws Throwable {
9699

97100
@Test
98101
void testSigningVerifyingFromExistingSignatureWithProvider() throws Throwable {
102+
Provider provider = null;
99103
try {
100104
Class<?> bouncyCastleProviderClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
101-
Provider provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
105+
provider = (Provider)bouncyCastleProviderClass.getConstructor().newInstance();
102106
Document doc = getOriginalDocument();
103107
XMLSignature signature = signDocument(doc, provider);
104108
assertEquals(provider.getName(), signature.getSignedInfo().getSignatureAlgorithm().getJCEProviderName());
105109

106110
PublicKey pubKey = getPublicKey();
107111
assertTrue(signature.checkSignatureValue(pubKey));
108112
} catch (ReflectiveOperationException e) {
109-
// BouncyCastle not installed, ignore
113+
// BouncyCastle not installed, skip
114+
assumeFalse(provider == null);
110115
}
111116
}
112117

0 commit comments

Comments
 (0)