3636
3737import static org .junit .jupiter .api .Assertions .assertEquals ;
3838import static org .junit .jupiter .api .Assertions .assertTrue ;
39+ import static org .junit .jupiter .api .Assumptions .assumeFalse ;
3940
4041class 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