2017-06-29 197 views
0

我想使用PowerMockito對使用CORBA的第三方庫的項目進行一些測試。我試圖通過找到問題的根源來跳過這個例外。我沒有成功找到關於這件事的信息。PowerMockito和CORBA衝突

這是我不能使它工作的最簡單的代碼:

Java類

@RunWith(PowerMockRunner.class) 
public class ORBTest { 

    @Test 
    public void initORB() throws Exception { 
     ORB.init(); 
    }  
} 

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.test</groupId> 
    <artifactId>test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <dependencies>  
     <dependency> 
      <groupId>org.powermock</groupId> 
      <artifactId>powermock-module-junit4</artifactId> 
      <version>1.6.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.powermock</groupId> 
      <artifactId>powermock-api-mockito2</artifactId> 
      <version>1.6.6</version> 
     </dependency> 
    </dependencies> 
</project> 

Log.error

java.lang.LinkageError: loader constraint violation: 
when resolving method "sun.corba.EncapsInputStreamFactory.newEncapsInputStream(Lorg/omg/CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, com/sun/corba/se/impl/ior/ObjectKeyFactoryImpl, and the class loader (instance of <bootloader>) for resolved class, sun/corba/EncapsInputStreamFactory, have different Class objects for the type /CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream; used in the signature 
    at com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl.create(ObjectKeyFactoryImpl.java:222) 
    at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.<init>(BootstrapResolverImpl.java:59) 
    at com.sun.corba.se.spi.resolver.ResolverDefault.makeBootstrapResolver(ResolverDefault.java:75) 
    at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.initializeNaming(ORBConfiguratorImpl.java:419) 
    at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.configure(ORBConfiguratorImpl.java:151) 
    at com.sun.corba.se.impl.orb.ORBImpl.postInit(ORBImpl.java:483) 
    at com.sun.corba.se.impl.orb.ORBImpl.set_parameters(ORBImpl.java:527) 
    at com.sun.corba.se.impl.orb.ORBSingleton.getFullORB(ORBSingleton.java:453) 
    at com.sun.corba.se.impl.orb.ORBSingleton.getORBData(ORBSingleton.java:632) 
    at com.sun.corba.se.spi.orb.ORB.getLogger(ORB.java:477) 
    at com.sun.corba.se.spi.orb.ORB.getLogWrapper(ORB.java:523) 
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.get(ORBUtilSystemException.java:54) 
    at com.sun.corba.se.spi.orb.ORB.<init>(ORB.java:281) 
    at com.sun.corba.se.impl.orb.ORBSingleton.<init>(ORBSingleton.java:135) 
    at org.omg.CORBA.ORB.init(ORB.java:292) 
    at org.test.test.MockitoTest.test(MockitoTest.java:34) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310) 
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89) 
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282) 
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87) 
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:202) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:144) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:118) 
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) 
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) 
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120) 
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121) 
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) 
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 

如果有人,我會感激在這裏可以給我一些啓示,因爲你不知道該怎麼改變才能完成這項工作。

回答

2

錯誤這樣

java.lang.LinkageError: loader constraint violation: when resolving method ... previously initiated loading for a different type with name...

一般可以通過添加包含到@PowerMockIgnore一個方法類或包來解決。

在你的情況,我建議你嘗試添加測試 @PowerMockIgnore("org.omg.CORBA.ORB")

Javadoc

+0

@JCalcines完成。請檢查。 –