问题
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