Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking a class which creates ThreadSafeClientConnManager object

I am unable to mock a class (using PowerMock's createMock method). This class is creating an object of ThreadSafeClientConnManager class in its constructor. I get exception at the line where I called createMock method passing my class name. Following is the exception stack trace. It is working fine if I run an integration test however. What could be the issue ?

[junit] Caused by: java.lang.IllegalStateException: Failure initializing default SSL context
[junit]     at org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext(SSLSocketFactory.java:211)
[junit]     at org.apache.http.conn.ssl.SSLSocketFactory.<init>(SSLSocketFactory.java:333)
[junit]     at org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory(SSLSocketFactory.java:165)
[junit]     at org.apache.http.impl.conn.SchemeRegistryFactory.createDefault(SchemeRegistryFactory.java:45)
[junit]     at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.<init>(ThreadSafeClientConnManager.java:98)
[junit]     at com.amazon.marketplace.payment.tsf.TSFClient.<init>(TSFClient.java:109)
[junit]     at com.amazon.marketplace.payment.tsf.TSFClient.<clinit>(TSFClient.java:95)
[junit] Caused by: java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: com.sun.net.ssl.internal.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
[junit]     at sun.security.jca.GetInstance.checkSuperClass(GetInstance.java:242)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:221)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:147)
[junit]     at javax.net.ssl.KeyManagerFactory.getInstance(KeyManagerFactory.java:121)
[junit]     at org.apache.http.conn.ssl.SSLSocketFactory.createSSLContext(SSLSocketFactory.java:184)
[junit]     at org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext(SSLSocketFactory.java:209)
like image 681
SnoopyMe Avatar asked Aug 27 '12 09:08

SnoopyMe


1 Answers

Do you think it's a system class loading issue? try referring to this link it might give you some pointers . http://code.google.com/p/powermock/wiki/MockSystem.

like image 80
Manisha Mahawar Avatar answered Oct 06 '22 01:10

Manisha Mahawar