junit.framework.AssertionFailedError:发生异常:java.lang.ClassCastException:

时间:2015-09-03 21:12:00

标签: mockito powermockito

获取错误 junit.framework.AssertionFailedError:发生异常:java.lang.ClassCastException:us.ny.state.ij.safeact.ask.persistency.impl.CchResponsePersistenceImpl $$ EnhancerByMockitoWithCGLIB $$ d62edc51与

不兼容

这里是存根

private PartnerPersistenceImpl mockPartnerPersistenceImpl;

@Before
public void setUp() throws Exception {
    mockPartnerPersistenceImpl = mock(PartnerPersistenceImpl.class);

}
PowerMockito.doReturn(mockPartnerPersistenceImpl).when(PersistenceFactory.class,"getService",any(RecordTypeEnum.class),any(EntityManager.class));

service.processRequest("DUmmy data");

The return type of PersistenceFactory method is
public static ADRBasePersistenceImpl<?, Long> getService(){}

在服务类中,我们将类型转换为不同的类以返回

PartnerPersistenceImpl parnerPeristenceImpl =(PartnerPersistenceImpl)PersistenceFactory.getService(RecordTypeEnum.SELLERPARTNER,entityManager);

我不知道为什么mockito不接受演员?

0 个答案:

没有答案