使用 PowerMockRunner 而不是使用 MockitoJUnitRunner 的 EncryptionInitializationException
EncryptionInitializationException using PowerMockRunner and not with MockitoJUnitRunner
当我使用 MockitoJunitRunner 测试以下功能时,它按预期工作正常。但是当我 运行 使用 PowerMockRunner 进行相同的测试时,我得到以下异常:
org.jasypt.exceptions.EncryptionInitializationException:
java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available
functionToBeTested() {
Encryptor.encrypt(this.getIgvToken(), "IGVKEY123");
}
我想知道为什么我使用 PowerMockRunner 时会抛出异常。这是我的依赖项:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
</dependency>
测试中除class外还添加注解@PrepareForTest({Encryptor.class})
.
我正面临着确切的问题,但不幸的是,这个解决方案无法帮助我。它通过在我的 class 中添加 @PowerMockIgnore ("javax.crypto.*")
解决,如下 link:
SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests
当我使用 MockitoJunitRunner 测试以下功能时,它按预期工作正常。但是当我 运行 使用 PowerMockRunner 进行相同的测试时,我得到以下异常:
org.jasypt.exceptions.EncryptionInitializationException:
java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available
functionToBeTested() {
Encryptor.encrypt(this.getIgvToken(), "IGVKEY123");
}
我想知道为什么我使用 PowerMockRunner 时会抛出异常。这是我的依赖项:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
</dependency>
测试中除class外还添加注解@PrepareForTest({Encryptor.class})
.
我正面临着确切的问题,但不幸的是,这个解决方案无法帮助我。它通过在我的 class 中添加 @PowerMockIgnore ("javax.crypto.*")
解决,如下 link:
SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests