You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2021/07/16 11:09:52 UTC

[sling-org-apache-sling-commons-crypto] branch master updated: change component lifecycle method's visibility to private

This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ff5acf  change component lifecycle method's visibility to private
2ff5acf is described below

commit 2ff5acfe9960e6d1b2a9a5872075e8acfca6b4e5
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Jul 16 13:08:25 2021 +0200

    change component lifecycle method's visibility to private
---
 .../EnvironmentVariablePasswordProvider.java       |  9 +++--
 .../crypto/internal/FilePasswordProvider.java      |  9 +++--
 .../crypto/internal/PbeSecretKeyProvider.java      |  7 +++-
 .../crypto/internal/SecureRandomSaltProvider.java  |  9 +++--
 .../internal/JasyptRandomIvGeneratorRegistrar.java |  6 ++-
 .../JasyptRandomSaltGeneratorRegistrar.java        |  6 ++-
 .../JasyptStandardPbeStringCryptoService.java      |  9 +++--
 .../internal/EncryptWebConsolePlugin.java          |  6 ++-
 .../EnvironmentVariablePasswordProviderTest.java   |  7 ++--
 .../crypto/internal/FilePasswordProviderTest.java  | 43 ++++++++++++----------
 .../crypto/internal/PbeSecretKeyProviderTest.java  | 18 +++++----
 .../internal/SecureRandomSaltProviderTest.java     |  9 +++--
 .../JasyptRandomIvGeneratorRegistrarTest.java      |  3 +-
 .../JasyptRandomSaltGeneratorRegistrarTest.java    |  3 +-
 .../JasyptStandardPbeStringCryptoServiceTest.java  | 17 +++++----
 .../internal/EncryptWebConsolePluginTest.java      | 23 ++++++------
 16 files changed, 107 insertions(+), 77 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProvider.java b/src/main/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProvider.java
index 2ed7d23..38bb213 100644
--- a/src/main/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProvider.java
+++ b/src/main/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProvider.java
@@ -52,19 +52,22 @@ public final class EnvironmentVariablePasswordProvider implements PasswordProvid
     }
 
     @Activate
-    protected void activate(final EnvironmentVariablePasswordProviderConfiguration configuration) {
+    @SuppressWarnings("unused")
+    private void activate(final EnvironmentVariablePasswordProviderConfiguration configuration) {
         logger.debug("activating");
         this.configuration = configuration;
     }
 
     @Modified
-    protected void modified(final EnvironmentVariablePasswordProviderConfiguration configuration) {
+    @SuppressWarnings("unused")
+    private void modified(final EnvironmentVariablePasswordProviderConfiguration configuration) {
         logger.debug("modifying");
         this.configuration = configuration;
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
     }
 
diff --git a/src/main/java/org/apache/sling/commons/crypto/internal/FilePasswordProvider.java b/src/main/java/org/apache/sling/commons/crypto/internal/FilePasswordProvider.java
index 2d5d136..24ccc3b 100644
--- a/src/main/java/org/apache/sling/commons/crypto/internal/FilePasswordProvider.java
+++ b/src/main/java/org/apache/sling/commons/crypto/internal/FilePasswordProvider.java
@@ -60,21 +60,24 @@ public final class FilePasswordProvider implements PasswordProvider {
     }
 
     @Activate
-    protected void activate(final FilePasswordProviderConfiguration configuration) throws IOException {
+    @SuppressWarnings("unused")
+    private void activate(final FilePasswordProviderConfiguration configuration) throws IOException {
         logger.debug("activating");
         this.configuration = configuration;
         checkConfiguration(configuration);
     }
 
     @Modified
-    protected void modified(final FilePasswordProviderConfiguration configuration) throws IOException {
+    @SuppressWarnings("unused")
+    private void modified(final FilePasswordProviderConfiguration configuration) throws IOException {
         logger.debug("modifying");
         this.configuration = configuration;
         checkConfiguration(configuration);
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
     }
 
diff --git a/src/main/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProvider.java b/src/main/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProvider.java
index 2f9af7a..e1f62da 100644
--- a/src/main/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProvider.java
+++ b/src/main/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProvider.java
@@ -70,20 +70,23 @@ public final class PbeSecretKeyProvider implements SecretKeyProvider {
     }
 
     @Activate
-    protected void activate(final PbeSecretKeyProviderConfiguration configuration) throws NoSuchAlgorithmException {
+    @SuppressWarnings("unused")
+    private void activate(final PbeSecretKeyProviderConfiguration configuration) throws NoSuchAlgorithmException {
         logger.debug("activating");
         this.configuration = configuration;
         factory = SecretKeyFactory.getInstance(configuration.algorithm());
     }
 
     @Modified
-    protected void modified(final PbeSecretKeyProviderConfiguration configuration) throws NoSuchAlgorithmException {
+    @SuppressWarnings("unused")
+    private void modified(final PbeSecretKeyProviderConfiguration configuration) throws NoSuchAlgorithmException {
         logger.debug("modifying");
         this.configuration = configuration;
         factory = SecretKeyFactory.getInstance(configuration.algorithm());
     }
 
     @Deactivate
+    @SuppressWarnings("unused")
     protected void deactivate() {
         logger.debug("deactivating");
     }
diff --git a/src/main/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProvider.java b/src/main/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProvider.java
index 000a963..9f2a206 100644
--- a/src/main/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProvider.java
+++ b/src/main/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProvider.java
@@ -56,7 +56,8 @@ public final class SecureRandomSaltProvider implements SaltProvider {
     }
 
     @Activate
-    protected void activate(final SecureRandomSaltProviderConfiguration configuration) throws NoSuchAlgorithmException {
+    @SuppressWarnings("unused")
+    private void activate(final SecureRandomSaltProviderConfiguration configuration) throws NoSuchAlgorithmException {
         logger.debug("activating");
         this.configuration = configuration;
         secureRandom = SecureRandom.getInstance(configuration.algorithm());
@@ -64,14 +65,16 @@ public final class SecureRandomSaltProvider implements SaltProvider {
     }
 
     @Modified
-    protected void modified(final SecureRandomSaltProviderConfiguration configuration) throws NoSuchAlgorithmException {
+    @SuppressWarnings("unused")
+    private void modified(final SecureRandomSaltProviderConfiguration configuration) throws NoSuchAlgorithmException {
         logger.debug("modifying");
         this.configuration = configuration;
         secureRandom = SecureRandom.getInstance(configuration.algorithm());
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
     }
 
diff --git a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrar.java b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrar.java
index 7933a17..8c0c771 100644
--- a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrar.java
+++ b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrar.java
@@ -55,7 +55,8 @@ public final class JasyptRandomIvGeneratorRegistrar {
     }
 
     @Activate
-    protected void activate(final JasyptRandomIvGeneratorRegistrarConfiguration configuration, final BundleContext bundleContext) {
+    @SuppressWarnings("unused")
+    private void activate(final JasyptRandomIvGeneratorRegistrarConfiguration configuration, final BundleContext bundleContext) {
         logger.debug("activating");
         final String algorithm = configuration.algorithm();
         final RandomIvGenerator ivGenerator = new RandomIvGenerator(algorithm);
@@ -67,7 +68,8 @@ public final class JasyptRandomIvGeneratorRegistrar {
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
         if (Objects.nonNull(serviceRegistration)) {
             serviceRegistration.unregister();
diff --git a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrar.java b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrar.java
index c33cf10..ad5b14d 100644
--- a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrar.java
+++ b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrar.java
@@ -55,7 +55,8 @@ public final class JasyptRandomSaltGeneratorRegistrar {
     }
 
     @Activate
-    protected void activate(final JasyptRandomSaltGeneratorRegistrarConfiguration configuration, final BundleContext bundleContext) {
+    @SuppressWarnings("unused")
+    private void activate(final JasyptRandomSaltGeneratorRegistrarConfiguration configuration, final BundleContext bundleContext) {
         logger.debug("activating");
         final String algorithm = configuration.algorithm();
         final RandomSaltGenerator saltGenerator = new RandomSaltGenerator(algorithm);
@@ -67,7 +68,8 @@ public final class JasyptRandomSaltGeneratorRegistrar {
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
         if (Objects.nonNull(serviceRegistration)) {
             serviceRegistration.unregister();
diff --git a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoService.java b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoService.java
index 2f0a8f7..e021bfd 100644
--- a/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoService.java
+++ b/src/main/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoService.java
@@ -78,19 +78,22 @@ public final class JasyptStandardPbeStringCryptoService implements CryptoService
     }
 
     @Activate
-    protected void activate(final JasyptStandardPbeStringCryptoServiceConfiguration configuration) {
+    @SuppressWarnings("unused")
+    private void activate(final JasyptStandardPbeStringCryptoServiceConfiguration configuration) {
         logger.debug("activating");
         setupEncryptor(configuration);
     }
 
     @Modified
-    protected void modified(final JasyptStandardPbeStringCryptoServiceConfiguration configuration) {
+    @SuppressWarnings("unused")
+    private void modified(final JasyptStandardPbeStringCryptoServiceConfiguration configuration) {
         logger.debug("modifying");
         setupEncryptor(configuration);
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         logger.debug("deactivating");
     }
 
diff --git a/src/main/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePlugin.java
index 0bb94fb..fe97773 100644
--- a/src/main/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePlugin.java
@@ -67,14 +67,16 @@ public final class EncryptWebConsolePlugin extends HttpServlet {
     }
 
     @Activate
-    protected void activate(final BundleContext bundleContext) {
+    @SuppressWarnings("unused")
+    private void activate(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         tracker = new ServiceTracker<>(bundleContext, CryptoService.class, null);
         tracker.open();
     }
 
     @Deactivate
-    protected void deactivate() {
+    @SuppressWarnings("unused")
+    private void deactivate() {
         this.bundleContext = null;
         if (Objects.nonNull(tracker)) {
             tracker.close();
diff --git a/src/test/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProviderTest.java b/src/test/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProviderTest.java
index fd00acf..3a1c5a1 100644
--- a/src/test/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProviderTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/internal/EnvironmentVariablePasswordProviderTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.commons.crypto.internal;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -46,19 +47,19 @@ public class EnvironmentVariablePasswordProviderTest {
         { // activate
             final EnvironmentVariablePasswordProviderConfiguration configuration = mock(EnvironmentVariablePasswordProviderConfiguration.class);
             when(configuration.name()).thenReturn("password_ascii85");
-            provider.activate(configuration);
+            MethodUtils.invokeMethod(provider, true, "activate", configuration);
             final char[] password = withEnvironmentVariable("password_ascii85", "+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?").execute(provider::getPassword);
             assertThat(password).isEqualTo("+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?".toCharArray());
         }
         { // modified
             final EnvironmentVariablePasswordProviderConfiguration configuration = mock(EnvironmentVariablePasswordProviderConfiguration.class);
             when(configuration.name()).thenReturn("password_utf8");
-            provider.modified(configuration);
+            MethodUtils.invokeMethod(provider, true, "modified", configuration);
             final char[] password = withEnvironmentVariable("password_utf8", " Napøleøn Sølø (DK) 🏁🇩🇰").execute(provider::getPassword);
             assertThat(password).isEqualTo(" Napøleøn Sølø (DK) 🏁🇩🇰".toCharArray());
         }
         { // deactivate
-            provider.deactivate();
+            MethodUtils.invokeMethod(provider, true, "deactivate");
             final char[] password = withEnvironmentVariable("password_utf8", " Napøleøn Sølø (DK) 🏁🇩🇰").execute(provider::getPassword);
             assertThat(password).isEqualTo(" Napøleøn Sølø (DK) 🏁🇩🇰".toCharArray());
         }
diff --git a/src/test/java/org/apache/sling/commons/crypto/internal/FilePasswordProviderTest.java b/src/test/java/org/apache/sling/commons/crypto/internal/FilePasswordProviderTest.java
index 1ce0cf0..5be5027 100644
--- a/src/test/java/org/apache/sling/commons/crypto/internal/FilePasswordProviderTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/internal/FilePasswordProviderTest.java
@@ -22,12 +22,14 @@ import java.io.File;
 import java.io.IOException;
 import java.util.UUID;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.ops4j.pax.exam.util.PathUtils;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -53,95 +55,96 @@ public class FilePasswordProviderTest {
     }
 
     @Test
-    public void testComponentLifecycle() throws IOException {
+    public void testComponentLifecycle() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         { // activate
             final String path = String.format("%s/src/test/resources/password.ascii85", PathUtils.getBaseDir());
             final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
             when(configuration.path()).thenReturn(path);
-            provider.activate(configuration);
+            MethodUtils.invokeMethod(provider, true, "activate", configuration);
             assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII);
         }
         { // modified
             final String path = String.format("%s/src/test/resources/password.utf8", PathUtils.getBaseDir());
             final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
             when(configuration.path()).thenReturn(path);
-            provider.modified(configuration);
+            MethodUtils.invokeMethod(provider, true, "modified", configuration);
             assertThat(provider.getPassword()).isEqualTo(PASSWORD_UTF8);
         }
         { // deactivate
-            provider.deactivate();
+            MethodUtils.invokeMethod(provider, true, "deactivate");
             assertThat(provider.getPassword()).isEqualTo(PASSWORD_UTF8);
         }
     }
 
     @Test
-    public void testPasswordFile() throws IOException {
+    public void testPasswordFile() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         final String path = String.format("%s/src/test/resources/password.ascii85", PathUtils.getBaseDir());
         final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
         when(configuration.path()).thenReturn(path);
         when(configuration.fix_posixNewline()).thenReturn(false);
-        provider.activate(configuration);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII);
         // enable fix for POSIX newline
         when(configuration.fix_posixNewline()).thenReturn(true);
-        provider.modified(configuration);
+        MethodUtils.invokeMethod(provider, true, "modified", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII);
     }
 
     @Test
-    public void testPasswordFileWithNewline() throws IOException {
+    public void testPasswordFileWithNewline() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         final String path = String.format("%s/src/test/resources/password.ascii85_newline", PathUtils.getBaseDir());
         final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
         when(configuration.path()).thenReturn(path);
         when(configuration.fix_posixNewline()).thenReturn(false);
-        provider.activate(configuration);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII_NEWLINE);
         // enable fix for POSIX newline
         when(configuration.fix_posixNewline()).thenReturn(true);
-        provider.modified(configuration);
+        MethodUtils.invokeMethod(provider, true, "modified", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII);
     }
 
     @Test
-    public void testPasswordFileWithNewlines() throws IOException {
+    public void testPasswordFileWithNewlines() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         final String path = String.format("%s/src/test/resources/password.ascii85_newlines", PathUtils.getBaseDir());
         final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
         when(configuration.path()).thenReturn(path);
         when(configuration.fix_posixNewline()).thenReturn(false);
-        provider.activate(configuration);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII_NEWLINES);
         // enable fix for POSIX newline
         when(configuration.fix_posixNewline()).thenReturn(true);
-        provider.modified(configuration);
+        MethodUtils.invokeMethod(provider, true, "modified", configuration);
         assertThat(provider.getPassword()).isEqualTo(PASSWORD_ASCII_NEWLINE);
     }
 
     @Test
-    public void testPasswordFileNotReadableDuringConfigurationCheck() throws IOException {
+    public void testPasswordFileNotReadableDuringConfigurationCheck() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         final String path = String.format("%s%s", System.getProperty("java.io.tmpdir"), UUID.randomUUID());
         final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
         when(configuration.path()).thenReturn(path);
         when(configuration.fix_posixNewline()).thenReturn(false);
-        exception.expect(IOException.class);
-        final String message = String.format("Unable to read password file '%s'", path);
-        exception.expectMessage(message);
-        provider.activate(configuration);
+        exception.expectCause(instanceOf(IOException.class));
+        // no way to check message of *cause*?
+        // final String message = String.format("Unable to read password file '%s'", path);
+        // exception.expectMessage(message);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
     }
 
     @Test
-    public void testPasswordFileNotReadableAfterConfigurationCheck() throws IOException {
+    public void testPasswordFileNotReadableAfterConfigurationCheck() throws Exception {
         final FilePasswordProvider provider = new FilePasswordProvider();
         final File file = File.createTempFile(UUID.randomUUID().toString(), null);
         final String path = file.getPath();
         final FilePasswordProviderConfiguration configuration = mock(FilePasswordProviderConfiguration.class);
         when(configuration.path()).thenReturn(path);
         when(configuration.fix_posixNewline()).thenReturn(false);
-        provider.activate(configuration);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
         file.delete();
         exception.expect(RuntimeException.class);
         final String message = String.format("Unable to read password file '%s'", path);
diff --git a/src/test/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProviderTest.java b/src/test/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProviderTest.java
index 7d5522c..f069ed3 100644
--- a/src/test/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProviderTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/internal/PbeSecretKeyProviderTest.java
@@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets;
 import java.security.NoSuchAlgorithmException;
 
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.apache.sling.commons.crypto.PasswordProvider;
 import org.apache.sling.commons.crypto.SaltProvider;
 import org.junit.Rule;
@@ -29,6 +30,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -46,16 +48,16 @@ public class PbeSecretKeyProviderTest {
     }
 
     @Test
-    public void testInvalidAlgorithm() throws NoSuchAlgorithmException {
+    public void testInvalidAlgorithm() throws Exception {
         final PbeSecretKeyProvider provider = new PbeSecretKeyProvider();
         final PbeSecretKeyProviderConfiguration configuration = mock(PbeSecretKeyProviderConfiguration.class);
         when(configuration.algorithm()).thenReturn("Invalid");
-        exception.expect(NoSuchAlgorithmException.class);
-        provider.activate(configuration);
+        exception.expectCause(instanceOf(NoSuchAlgorithmException.class));
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
     }
 
     @Test
-    public void testInvalidKeySpec() throws NoSuchAlgorithmException, IllegalAccessException {
+    public void testInvalidKeySpec() throws Exception {
         final PasswordProvider passwordProvider = mock(PasswordProvider.class);
         when(passwordProvider.getPassword()).thenReturn("+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?".toCharArray());
         final SaltProvider saltProvider = mock(SaltProvider.class);
@@ -68,14 +70,14 @@ public class PbeSecretKeyProviderTest {
         when(configuration.algorithm()).thenReturn("PBKDF2WithHmacSHA1");
         when(configuration.iterationCount()).thenReturn(-1);
         when(configuration.keyLength()).thenReturn(-1);
-        provider.activate(configuration);
+        MethodUtils.invokeMethod(provider, true, "activate", configuration);
 
         exception.expect(IllegalArgumentException.class);
         provider.getSecretKey();
     }
 
     @Test
-    public void testComponentLifecycle() throws NoSuchAlgorithmException, IllegalAccessException {
+    public void testComponentLifecycle() throws Exception {
         final PasswordProvider passwordProvider = mock(PasswordProvider.class);
         when(passwordProvider.getPassword()).thenReturn("+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?".toCharArray());
         final SaltProvider saltProvider = mock(SaltProvider.class);
@@ -88,7 +90,7 @@ public class PbeSecretKeyProviderTest {
             when(configuration.algorithm()).thenReturn("PBKDF2WithHmacSHA1");
             when(configuration.iterationCount()).thenReturn(1024);
             when(configuration.keyLength()).thenReturn(128);
-            provider.activate(configuration);
+            MethodUtils.invokeMethod(provider, true, "activate", configuration);
             assertThat(provider.getSecretKey().getAlgorithm()).isEqualTo("PBKDF2WithHmacSHA1");
         }
         { // modified
@@ -96,7 +98,7 @@ public class PbeSecretKeyProviderTest {
             when(configuration.algorithm()).thenReturn("PBKDF2WithHmacSHA256");
             when(configuration.iterationCount()).thenReturn(2048);
             when(configuration.keyLength()).thenReturn(256);
-            provider.modified(configuration);
+            MethodUtils.invokeMethod(provider, true, "modified", configuration);
             assertThat(provider.getSecretKey().getAlgorithm()).isEqualTo("PBKDF2WithHmacSHA256");
         }
         { // deactivate
diff --git a/src/test/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProviderTest.java b/src/test/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProviderTest.java
index 99972c3..08c5293 100644
--- a/src/test/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProviderTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/internal/SecureRandomSaltProviderTest.java
@@ -21,6 +21,7 @@ package org.apache.sling.commons.crypto.internal;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -43,24 +44,24 @@ public class SecureRandomSaltProviderTest {
     }
 
     @Test
-    public void testComponentLifecycle() throws IOException, NoSuchAlgorithmException {
+    public void testComponentLifecycle() throws Exception {
         final SecureRandomSaltProvider provider = new SecureRandomSaltProvider();
         { // activate
             final SecureRandomSaltProviderConfiguration configuration = mock(SecureRandomSaltProviderConfiguration.class);
             when(configuration.algorithm()).thenReturn("SHA1PRNG");
             when(configuration.keyLength()).thenReturn(8);
-            provider.activate(configuration);
+            MethodUtils.invokeMethod(provider, true, "activate", configuration);
             assertThat(provider.getSalt()).hasLength(8);
         }
         { // modified
             final SecureRandomSaltProviderConfiguration configuration = mock(SecureRandomSaltProviderConfiguration.class);
             when(configuration.algorithm()).thenReturn("SHA1PRNG");
             when(configuration.keyLength()).thenReturn(16);
-            provider.modified(configuration);
+            MethodUtils.invokeMethod(provider, true, "modified", configuration);
             assertThat(provider.getSalt()).hasLength(16);
         }
         { // deactivate
-            provider.deactivate();
+            MethodUtils.invokeMethod(provider, true, "deactivate");
             assertThat(provider.getSalt()).hasLength(16);
         }
     }
diff --git a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrarTest.java b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrarTest.java
index 0775920..0952457 100644
--- a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrarTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomIvGeneratorRegistrarTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.commons.crypto.jasypt.internal;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Test;
 
 import static org.junit.Assert.fail;
@@ -28,7 +29,7 @@ public class JasyptRandomIvGeneratorRegistrarTest {
     public void testDeactivate() {
         final JasyptRandomIvGeneratorRegistrar registrar = new JasyptRandomIvGeneratorRegistrar();
         try {
-            registrar.deactivate();
+            MethodUtils.invokeMethod(registrar, true, "deactivate");
         } catch (Exception e) {
             final String message = String.format("Deactivating component should not throw exception: %s", e.getMessage());
             fail(message);
diff --git a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrarTest.java b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrarTest.java
index 02b4ef0..2a4bb0d 100644
--- a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrarTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptRandomSaltGeneratorRegistrarTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.commons.crypto.jasypt.internal;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Test;
 
 import static org.junit.Assert.fail;
@@ -28,7 +29,7 @@ public class JasyptRandomSaltGeneratorRegistrarTest {
     public void testDeactivate() {
         final JasyptRandomSaltGeneratorRegistrar registrar = new JasyptRandomSaltGeneratorRegistrar();
         try {
-            registrar.deactivate();
+            MethodUtils.invokeMethod(registrar, true, "deactivate");
         } catch (Exception e) {
             final String message = String.format("Deactivating component should not throw exception: %s", e.getMessage());
             fail(message);
diff --git a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoServiceTest.java b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoServiceTest.java
index b3f89eb..4b007ef 100644
--- a/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/jasypt/internal/JasyptStandardPbeStringCryptoServiceTest.java
@@ -22,6 +22,7 @@ import java.security.Provider;
 import java.security.Security;
 
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.apache.sling.commons.crypto.PasswordProvider;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.jasypt.iv.RandomIvGenerator;
@@ -39,7 +40,7 @@ public class JasyptStandardPbeStringCryptoServiceTest {
     private static final String MESSAGE = "Rudy, a Message to You";
 
     @Test
-    public void testComponentLifecycle() throws IllegalAccessException {
+    public void testComponentLifecycle() throws Exception {
         final PasswordProvider passwordProvider = mock(PasswordProvider.class);
         when(passwordProvider.getPassword()).thenReturn("+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?".toCharArray());
         final JasyptStandardPbeStringCryptoService service = new JasyptStandardPbeStringCryptoService();
@@ -51,7 +52,7 @@ public class JasyptStandardPbeStringCryptoServiceTest {
             when(configuration.keyObtentionIterations()).thenReturn(DEFAULT_KEY_OBTENTION_ITERATIONS);
             when(configuration.securityProviderName()).thenReturn(null);
             when(configuration.stringOutputType()).thenReturn(STRING_OUTPUT_TYPE_BASE64);
-            service.activate(configuration);
+            MethodUtils.invokeMethod(service, true, "activate", configuration);
             final String ciphertext = service.encrypt(MESSAGE);
             final String message = service.decrypt(ciphertext);
             assertThat(message).isEqualTo(MESSAGE);
@@ -62,13 +63,13 @@ public class JasyptStandardPbeStringCryptoServiceTest {
             when(configuration.keyObtentionIterations()).thenReturn(1);
             when(configuration.securityProviderName()).thenReturn("");
             when(configuration.stringOutputType()).thenReturn(STRING_OUTPUT_TYPE_HEXADECIMAL);
-            service.modified(configuration);
+            MethodUtils.invokeMethod(service, true, "modified", configuration);
             final String ciphertext = service.encrypt(MESSAGE);
             final String message = service.decrypt(ciphertext);
             assertThat(message).isEqualTo(MESSAGE);
         }
         { // deactivate
-            service.deactivate();
+            MethodUtils.invokeMethod(service, true, "deactivate");
             final String ciphertext = service.encrypt(MESSAGE);
             final String message = service.decrypt(ciphertext);
             assertThat(message).isEqualTo(MESSAGE);
@@ -76,7 +77,7 @@ public class JasyptStandardPbeStringCryptoServiceTest {
     }
 
     @Test
-    public void testProviderName() throws IllegalAccessException {
+    public void testProviderName() throws Exception {
         final Provider securityProvider = new BouncyCastleProvider();
         Security.addProvider(securityProvider);
         final PasswordProvider passwordProvider = mock(PasswordProvider.class);
@@ -90,14 +91,14 @@ public class JasyptStandardPbeStringCryptoServiceTest {
         when(configuration.keyObtentionIterations()).thenReturn(DEFAULT_KEY_OBTENTION_ITERATIONS);
         when(configuration.securityProviderName()).thenReturn("BC");
         when(configuration.stringOutputType()).thenReturn(STRING_OUTPUT_TYPE_BASE64);
-        service.activate(configuration);
+        MethodUtils.invokeMethod(service, true, "activate", configuration);
         final String ciphertext = service.encrypt(MESSAGE);
         final String message = service.decrypt(ciphertext);
         assertThat(message).isEqualTo(MESSAGE);
     }
 
     @Test
-    public void testProvider() throws IllegalAccessException {
+    public void testProvider() throws Exception {
         final Provider securityProvider = new BouncyCastleProvider();
         final PasswordProvider passwordProvider = mock(PasswordProvider.class);
         when(passwordProvider.getPassword()).thenReturn("+AQ?aDes!'DBMkrCi:FE6q\\sOn=Pbmn=PK8n=PK?".toCharArray());
@@ -111,7 +112,7 @@ public class JasyptStandardPbeStringCryptoServiceTest {
         when(configuration.keyObtentionIterations()).thenReturn(DEFAULT_KEY_OBTENTION_ITERATIONS);
         when(configuration.securityProviderName()).thenReturn(null);
         when(configuration.stringOutputType()).thenReturn(STRING_OUTPUT_TYPE_BASE64);
-        service.activate(configuration);
+        MethodUtils.invokeMethod(service, true, "activate", configuration);
         final String ciphertext = service.encrypt(MESSAGE);
         final String message = service.decrypt(ciphertext);
         assertThat(message).isEqualTo(MESSAGE);
diff --git a/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
index d4b7594..42bd6a5 100644
--- a/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
@@ -18,14 +18,13 @@
  */
 package org.apache.sling.commons.crypto.webconsole.internal;
 
-import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.reflect.MethodUtils;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 
@@ -38,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class EncryptWebConsolePluginTest {
 
     @Test
-    public void testGetWithNoCryptoServicesAvailable() throws ServletException, IOException {
+    public void testGetWithNoCryptoServicesAvailable() throws Exception {
         final BundleContext bundleContext = mock(BundleContext.class);
         final HttpServletRequest request = mock(HttpServletRequest.class);
         final StringWriter stringWriter = new StringWriter();
@@ -46,9 +45,9 @@ public class EncryptWebConsolePluginTest {
         final HttpServletResponse response = mock(HttpServletResponse.class);
         when(response.getWriter()).thenReturn(printWriter);
         final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
-        plugin.activate(bundleContext);
+        MethodUtils.invokeMethod(plugin, true, "activate", bundleContext);
         plugin.doGet(request, response);
-        plugin.deactivate();
+        MethodUtils.invokeMethod(plugin, true, "deactivate");
         assertThat(stringWriter.toString()).contains("<p>No crypto service available</p>");
     }
 
@@ -56,7 +55,7 @@ public class EncryptWebConsolePluginTest {
     public void testDeactivateWithNoServiceTracker() {
         final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
         try {
-            plugin.deactivate();
+            MethodUtils.invokeMethod(plugin, true, "deactivate");
         } catch (Exception e) {
             final String message = String.format("Deactivating component should not throw exception: %s", e.getMessage());
             fail(message);
@@ -64,40 +63,40 @@ public class EncryptWebConsolePluginTest {
     }
 
     @Test
-    public void testPostServiceIdParameterMissing() throws ServletException, IOException {
+    public void testPostServiceIdParameterMissing() throws Exception {
         final BundleContext bundleContext = mock(BundleContext.class);
         final HttpServletRequest request = mock(HttpServletRequest.class);
         when(request.getParameter("service-id")).thenReturn(null);
         when(request.getParameter("message")).thenReturn("");
         final HttpServletResponse response = mock(HttpServletResponse.class);
         final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
-        plugin.activate(bundleContext);
+        MethodUtils.invokeMethod(plugin, true, "activate", bundleContext);
         plugin.doPost(request, response);
         verify(response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter service-id is missing");
     }
 
     @Test
-    public void testPostMessageParameterMissing() throws IOException, ServletException {
+    public void testPostMessageParameterMissing() throws Exception {
         final BundleContext bundleContext = mock(BundleContext.class);
         final HttpServletRequest request = mock(HttpServletRequest.class);
         when(request.getParameter("service-id")).thenReturn("");
         when(request.getParameter("message")).thenReturn(null);
         final HttpServletResponse response = mock(HttpServletResponse.class);
         final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
-        plugin.activate(bundleContext);
+        MethodUtils.invokeMethod(plugin, true, "activate", bundleContext);
         plugin.doPost(request, response);
         verify(response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter message is missing");
     }
 
     @Test
-    public void testPostCryptoServiceNotAvailable() throws ServletException, IOException {
+    public void testPostCryptoServiceNotAvailable() throws Exception {
         final BundleContext bundleContext = mock(BundleContext.class);
         final HttpServletRequest request = mock(HttpServletRequest.class);
         when(request.getParameter("service-id")).thenReturn("0");
         when(request.getParameter("message")).thenReturn("");
         final HttpServletResponse response = mock(HttpServletResponse.class);
         final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
-        plugin.activate(bundleContext);
+        MethodUtils.invokeMethod(plugin, true, "activate", bundleContext);
         plugin.doPost(request, response);
         verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "Crypto service with service id 0 not found");
     }