当我使用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>
答案 0 :(得分:1)
我遇到了确切的问题但不幸的是这个解决方案无法帮助我。它通过在我的课程中添加val graph = GraphDSL.create() { implicit builder =>
import GraphDSL.Implicits._
val intSource = Source(1 to 10)
val printSink = Sink.foreach[String](s => println(s))
val yourMapper: Int => Future[String] = (i: Int) => Future(i.toString)
val yourFlow = Flow[Int].mapAsync[String](2)(yourMapper)
intSource ~> yourFlow ~> printSink
ClosedShape
}
来解决,如以下链接中所示:
SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests
答案 1 :(得分:0)
除了测试中的课程外,还要添加注释@PrepareForTest({Encryptor.class})
。