我是 Spring Boot 和 Mockito 的新手,在我的服务测试中模拟存储库调用时遇到问题。
我有一个“删除”服务方法调用,如下所示,我尝试通过模拟存储库调用来使用 Mockito 进行测试:
public interface IEntityTypeService {
public EntityType getById(long id);
public EntityType getByName(String name);
public List<EntityType> getAll();
public void update(EntityType entityType);
public void delete(long id);
public boolean add(EntityType entityType);
}
@Service
public class EntityTypeServiceImpl implements IEntityTypeService {
@Autowired
private EntityTypeRepository entityTypeRepository;
@Override
public void delete(long id) {
entityTypeRepository.delete(getById(id));
}
@Override
public EntityType getById(long id) {
return entityTypeRepository.findById(id).get();
}
....implementation of other methods from the interface
}
Run Code Online (Sandbox Code Playgroud)
我的存储库如下所示:
@RepositoryRestResource
public interface EntityTypeRepository extends LookupObjectRepository<EntityType> …Run Code Online (Sandbox Code Playgroud)