1

我有一个用 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

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

4

1 回答 1

1

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

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

还从 Pom.xml 中删除了依赖项 powermock-module-junit4-rule 和 powermock-classloading-xstream 并且它可以工作。

于 2018-02-18T12:00:27.073 回答