Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mockito - Getting Exception while mocking Java types, Namespaces

Getting java.lang.IllegalAccessError while mocking

my Class constructor looks like.

public Acct(java.lang.Class _javaType,
    javax.xml.namespace.Qname _xmlType,
    com.ibm.ws.webservices.engine.description.TypeDesc _typeDesc){
super(_javaType,_xmlType,_typeDesc);
}

i tried mocking like this.

public class AcctTest extends PowerMockito{
@Test
public void testMethod(){
        java.lang.Class jType = PowerMock.mock(java.lang.Class.class);
    javax.xml.namespace.Qname xml = PowerMock.mock(javax.xml.namespace.Qname.class);
    com.ibm.ws.webservices.engine.description.TypeDesc Desc = PowerMock.mock(com.ibm.ws.webservices.engine.description.TypeDesc.class);
//Object creation to access constructor
}
}

Exception: java.lang.IllegalAccessError: java.lang.Class at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

Looks like it is not able to access predefined java types. thanks can someone please guide, how to mock such objects?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just avoid mocking Class.

 java.lang.Class jType = java.lang.Class.class;

This would be enough.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...