com.thoughtworks.xstream.converters.ConversionException:无法调用

时间:2018-02-10 22:21:57

标签: apache-camel powermockito spring-camel

我有一种情况用PowerMockito测试SpringCamelContext unittest,我收到以下错误。有人知道如何解决它。如果我申请

@Rule
    public PowerMockRule rule = new PowerMockRule();

以下依赖项。

<dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4-rule</artifactId>
            <version>1.7.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-classloading-xstream</artifactId>
            <version>1.7.1</version>
            <scope>test</scope>
        </dependency>

然后我才得到以下错误:

 com.thoughtworks.xstream.converters.ConversionException: Could not call java.security.CodeSource.readObject() : null
    ---- Debugging information ----
    message             : Could not call java.security.CodeSource.readObject()
    cause-exception     : java.lang.RuntimeException
    cause-message       : null
    class               : java.security.CodeSource
    required-type       : java.security.CodeSource
    converter-type      : com.thoughtworks.xstream.converters.reflection.SerializableConverter
    path                : /org.powermock.modules.junit4.rule.PowerMockStatement$1/outer-class/fNext/next/next/target/template/camelContext/applicationContextClassLoader/parent/defaultDomain/codesource/java.security.CodeSource
    line number         : 18917
    class[1]            : java.security.ProtectionDomain
    converter-type[1]   : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
    class[2]            : sun.misc.Launcher$ExtClassLoader
    class[3]            : sun.misc.Launcher$AppClassLoader
    class[4]            : org.apache.camel.spring.SpringCamelContext
    class[5]            : org.apache.camel.impl.DefaultProducerTemplate
    class[6]            : com.narayan.dummy.test.drools.DroolsUnitTest
    class[7]            : org.junit.internal.runners.statements.InvokeMethod
    class[8]            : org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks
    class[9]            : org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks
    class[10]           : org.powermock.modules.junit4.rule.PowerMockStatement
    class[11]           : org.powermock.modules.junit4.rule.PowerMockStatement$1
    version             : 1.4.7

有人知道怎么解决吗????

1 个答案:

答案 0 :(得分:0)

为了解决这个问题。我用以下注释替换它而不是PowerMockRule。

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)

还删除了依赖项powermock-module-junit4-rule&amp;来自Pom.xml的powermock-classloading-xstream工作正常。