21
21
import static org .junit .Assert .assertEquals ;
22
22
import static org .junit .Assert .assertFalse ;
23
23
import static org .junit .Assert .assertTrue ;
24
- import static org .junit .Assert .fail ;
25
24
import static org .mockito .ArgumentMatchers .any ;
26
25
import static org .mockito .Mockito .reset ;
27
26
import static org .mockito .Mockito .spy ;
@@ -126,15 +125,10 @@ private void doTamperedEncryptDecrypt(final CryptoAlgorithm cryptoAlg, final int
126
125
plaintextBytes ,
127
126
encryptionContext ).getResult ();
128
127
cipherText [cipherText .length - 2 ] ^= (byte ) 0xff ;
129
- try {
130
- encryptionClient_ .decryptData (
131
- masterKeyProvider ,
132
- cipherText
133
- ).getResult ();
134
- fail ("Expected BadCiphertextException" );
135
- } catch (final BadCiphertextException ex ) {
136
- // Expected exception
137
- }
128
+
129
+ assertThrows (BadCiphertextException .class , () -> encryptionClient_ .decryptData (
130
+ masterKeyProvider ,
131
+ cipherText ));
138
132
}
139
133
140
134
private void doTamperedEncryptDecryptWithKeyring (final CryptoAlgorithm cryptoAlg , final int byteSize , final int frameSize ) {
@@ -150,14 +144,10 @@ private void doTamperedEncryptDecryptWithKeyring(final CryptoAlgorithm cryptoAlg
150
144
.keyring (keyring )
151
145
.plaintext (plaintextBytes ).build ()).getResult ();
152
146
cipherText [cipherText .length - 2 ] ^= (byte ) 0xff ;
153
- try {
154
- encryptionClient_ .decrypt (DecryptRequest .builder ()
155
- .keyring (keyring )
156
- .ciphertext (cipherText ).build ());
157
- fail ("Expected BadCiphertextException" );
158
- } catch (final BadCiphertextException ex ) {
159
- // Expected exception
160
- }
147
+
148
+ assertThrows (BadCiphertextException .class , () -> encryptionClient_ .decrypt (DecryptRequest .builder ()
149
+ .keyring (keyring )
150
+ .ciphertext (cipherText ).build ()));
161
151
}
162
152
163
153
private void doEncryptDecryptWithParsedCiphertext (final int byteSize , final int frameSize ) {
0 commit comments