java trustmanager,当TrustManagerFactory不是TrustManagerFactory(Java)时

I am trying to add some additional JUnit test to an existing App-Server (TomCat) product. I have run into an issue with the (existing and fielded) custom TrustManager. This thing works fine in production, but during JUnit, gives exception.

The customized TrustManager merely loads a keystore from a path, and implicitly trusts our own public certs. For some reason, using this in JUnits causes an exception on the following line:

TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("PKIX");

Exception:

java.security.NoSuchAlgorithmException: class configured for TrustManagerFactory: com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory

This exception takes place regardless of what Provider/Algorithm combinations are used ("SunX509", .getDefaultAlgorithm(), et al.).

Any insight will be greatly appreciated.

解决方案

Well, looks like PowerMock messes up with SSL issues and thus, you run into loading a wrong factory. The solution for that is to use an annotation on the test class:

@PowerMockIgnore("javax.net.ssl.*")