У меня есть служба, которая использует другую услугу, которую я хочу издеваться.Смазочные услуги с весенним ботинком и Spock
@Service
public class CustomerService {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private PatientRepository patientRepository;
@Autowired
private MyHelper myHelper;
public Office createOfficeAccount(Office commonOffice) throws Exception {
// this line calls another service via http, I want to mock it:
Account newAccount = myHelper.createAccount(officeAccount);
return customerRepository.save(customer);
}
Вот мой тестовый класс:
class KillBillCustomerServiceTest extends BaseSpecification {
@Autowired
private CustomerService customerService = Mock(CustomerService)
@Autowired
private PatientRepository patientRepository = Mock(PatientRepository)
@Autowired
private MyHelper kbHelper = Mock(MyHelper)
def setup() {
customerService.setPatientRepository(patientRepository)
customerService.setMyHelper(kbHelper)
}
def "create new Account from Common Office"() {
def commonOffice = createOfficeForTests()
CustomerService customerService = new CustomerService (myHelper: kbHelper)
when:
kbHelper.createAccount(commonOffice) >> new Account() // want to mock it, but it is still calling the actual class to try and make the network call
}
Мой вопрос, как я дразнить мой класс MyHelper так, что он на самом деле не попытаться сделать реальный вызов, но вместо этого просто возвращает окурок объект?
проверить его http://www.baeldung.com/injecting-mocks-in-spring – Dongqing
, который для Mockito и я не Я не считаю его чем-то другим, чем то, что я делаю выше. – sonoerin