简体   繁体   中英

NoSuchAlgorithmException in SSLContext.getInstance

I am getting NoSuchAlgorithmException in the following code:

 @RunWith(PowerMockRunner.class)
 @PrepareForTest({CloudWatchHelper.class})
 class MyTest {
 ....
 final SSLContext sslcontext = SSLContext.getInstance("TLS");
 ...
 }

Stack trace:

[junit] class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
[junit] java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
[junit]     at sun.security.jca.GetInstance.checkSuperClass(GetInstance.java:260)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:237)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
[junit]     at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)

I want to know what is the reason behind NoSuchAlgorithmException .

将以下注释添加到我的测试类中为我解决了这个问题:

@PowerMockIgnore({ "javax.net.ssl.*", "javax.security.*" })

当我使用 powermock 时,抛出此异常,解决方法是在测试头上添加 @PowerMockIgnore({ "javax.net.ssl.*" }) 。

I realized that I got exception because of:

 @RunWith(PowerMockRunner.class)
 @PrepareForTest({CloudWatchHelper.class})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM