diff options
Diffstat (limited to 'sonar-plugin-api-impl/src')
-rw-r--r-- | sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java | 24 | ||||
-rw-r--r-- | sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java | 8 |
2 files changed, 10 insertions, 22 deletions
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java index cf57bcf914a..6be6c5b4b26 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java @@ -30,7 +30,6 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.fail; public class AesECBCipherTest { @@ -61,7 +60,7 @@ public class AesECBCipherTest { assertThatThrownBy(() -> cipher.encrypt("this is a secret")) .isInstanceOf(RuntimeException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -79,13 +78,9 @@ public class AesECBCipherTest { URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/bad_secret_key.txt"); AesECBCipher cipher = new AesECBCipher(new File(resource.toURI()).getCanonicalPath()); - try { - cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); - fail(); - - } catch (RuntimeException e) { - assertThat(e.getCause()).isInstanceOf(InvalidKeyException.class); - } + assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) + .isInstanceOf(RuntimeException.class) + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -93,14 +88,9 @@ public class AesECBCipherTest { URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/other_secret_key.txt"); AesECBCipher cipher = new AesECBCipher(new File(resource.toURI()).getCanonicalPath()); - try { - // text encrypted with another key - cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); - fail(); - - } catch (RuntimeException e) { - assertThat(e.getCause()).isInstanceOf(BadPaddingException.class); - } + assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) + .isInstanceOf(RuntimeException.class) + .hasCauseInstanceOf(BadPaddingException.class); } @Test diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java index e402d11efd0..bda1d4cac0c 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java @@ -49,8 +49,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.encrypt("this is a secret")) - .hasRootCauseInstanceOf(InvalidKeyException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -71,8 +70,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) - .hasRootCauseInstanceOf(InvalidKeyException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -82,7 +80,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.decrypt(originalCipher.encrypt("this is a secret"))) - .hasRootCauseInstanceOf(BadPaddingException.class); + .hasCauseInstanceOf(BadPaddingException.class); } private String pathToSecretKey() throws Exception { |