我正在尝试测试JavaMail api并使用SpringRunner和PowerMockRunner,但它失败了。
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringRunner.class)
@PowerMockIgnore(value = {"javax.management.*"})
@SpringBootTest
public class BaseITest {
@PrepareForTest(value = {MyStaticHelper.class})
@Test
public void testListFolders() {
// mock static method
// Use JavaMail API
}
}
我得到了这个例外:
javax.mail.MessagingException: java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$DefaultSSLContext not a SSLContext
如果我删除了@PowerMockIgnore(value = {" javax.management。*"}),那么我将收到此异常:
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/powermock/core/classloader/MockClassLoader) previously initiated loading for a different type with name "javax/management/MBeanServer"
使用的依赖版本是:
有人可以帮忙吗?
答案 0 :(得分:1)
它看起来像一个bug。
在我的案例中帮助的解决方案是缩小加载的配置。
尝试指定要加载的最小配置集:
@SpringBootTest(classes = SomeSpesificConfiguration.class)
答案 1 :(得分:0)
使用powermock-api-mockito2
试试@PowerMockIgnore(" javax.net.ssl。*") https://groups.google.com/forum/#!topic/powermock/v4nreP2AnOQ