有没有办法在java中模拟Class
实例
@Autowired
private ApplicationContext context;
public <T> T search(Class<? extends JpaSpecificationExecutor<ENTITY>>
specExecutor,
Class<? extends Converter<DTO, ENTITY>> objConverter) {
JpaSpecificationExecutor jpaSpecificationExecutor = context.getBean(specExecutor);
Converter converter = context.getBean(objConverter);
}
我必须对上述方法进行单元测试,我正在使用Mockito。
问题是,当我使用时:
Mockito.when(context.getBean(any(Class.class))).thenReturn(new MyJpaSpecificationExecutor());
上述内容不适用于context.getBean(objConverter);
// ClassCastException
Mockito
或PowerMockito
是否有办法实现此目标?