PowerMockito tests moved from JDK 1.6 to JDK 1.7 are getting constraint violations

牧云@^-^@ 提交于 2019-12-11 07:38:32

问题


We have some tests that had been working fine with JDK 1.6. We're now moving to JDK 1.7. These tests work fine in Eclipse. When we run these tests from our Ant build, we're seeing errors like this:

junit.framework.TestListener: addError(<testmethodname>, loader constraint violation:
when resolving overridden method 
"com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object;"
the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class,
com/sun/xml/bind/v2/runtime/unmarshaller/UnmarshallerImpl, and its superclass loader (instance of <bootloader>),
have different Class objects for the type
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object; used in the signature)

We were using PowerMockito 1.5 when we first saw this. I just tried upgrading to 1.5.4 and all the relevant dependencies, and that resulted in no change.

This shows the class annotations we're using:

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*" })
@PrepareForTest(<classundertest>.class)
public class <classundertest>Test extends MockServiceBase {

What might be the problem here?


回答1:


Last night I finally found the workaround for this. The key was to add additional package masks to the “@PowerMockIgnore” annotation. Just about the first thing I tried was adding "com.sun.xml.". I had thought that didn’t make any difference, but I think it simply fixed the tests that referred to that package. The remaining references were to “com.sun.org.”, and I didn’t realize that. When I finally also added “com.sun.org.*”, it fixed the remaining tests.



来源:https://stackoverflow.com/questions/21516065/powermockito-tests-moved-from-jdk-1-6-to-jdk-1-7-are-getting-constraint-violatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!