java.lang.IllegalStateException:无法转换类

时间:2015-09-22 20:03:19

标签: java mockito powermockito

<testcase time="0.593" classname="org.apache.maven.surefire.junit4.JUnit4Provider" name="facade.FacadeBeanTest">
    <error message="Failed to transform class with name BusinessServiceImpl. Reason: NameKeyList" type="java.lang.IllegalStateException">java.lang.IllegalStateException: Failed to transform class with name BusinessServiceImpl. Reason: NameKeyList
    at javassist.ClassPool.get(ClassPool.java:450)
    at javassist.bytecode.Descriptor.toCtClass(Descriptor.java:592)
    at javassist.bytecode.Descriptor.getReturnType(Descriptor.java:489)
    at javassist.CtBehavior.getReturnType0(CtBehavior.java:306)
    at javassist.CtMethod.getReturnType(CtMethod.java:217)
    at org.powermock.core.transformers.impl.MainMockTransformer.modifyMethod(MainMockTransformer.java:172)
    at org.powermock.core.transformers.impl.MainMockTransformer.allowMockingOfStaticAndFinalAndNativeMethods(MainMockTransformer.java:142)
    at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:65)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:215)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:147)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
    at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:351)
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
    at java.lang.Class.getAnnotations(Class.java:3050)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.classAnnotations(PowerMockJUnit44RunnerDelegateImpl.java:163)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getDescription(PowerMockJUnit44RunnerDelegateImpl.java:155)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getDescription(JUnit4TestSuiteChunkerImpl.java:171)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.getDescription(AbstractCommonPowerMockRunner.java:47)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:51)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
    </error>
</testcase>

@Test
public void createRegistrationTest() {
    try {
        RegistrationResponse response = facadeBeanTest.createAegistration(RegistrationFacadeMock.getCreateRegistrationRequest());
        Assert.assertEquals(true, response.isRegistrationSuccessful());
    } catch (Exception e) {
        Assert.fail("Exception occured : " + e);
    }

}

测试用例返回成功并返回预期结果。当我构建一个项目时,在testsuite xml和构建中获取异常失败。 任何想法,我错过了任何版本的mockit或powermock吗?

的pom.xml

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>1.10.8</version>
    <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-module-junit4</artifactId>
   <version>1.5.1</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-api-mockito</artifactId>
   <version>1.5.1</version>
   <scope>test</scope>
</dependency>

在BsuinessServiceImpl.java下有很多方法,只有在调试方法中调用createRegistration()并返回成功

public createRegistration(){
ammoRegistrationPeristenceImpl.create(ammoRegistrationPO);
}

protected NameKeyList generateNameKeys(Name name) throws Exception {
try {
    return searchUtil.getRemote().getNameKeys(name);
} catch (RemoteException e) {

}
}

0 个答案:

没有答案