Mockito Argument Captor Nedir? Nerede Kullanırız? — Java

//Service
private final CustomerRepository customerRepository;

public CustomerService(CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
}

public void createCustomer() {
final Customer customer = new Customer();
customer.setFirstName("Mehmet");
customer.setLastName("Demircan");

customerRepository.save(customer);
}
@InjectMocks
private CustomerService customerService;
@Mock
private CustomerRepository customerRepository;
@Test
public void it_should_create_customer() {
// When
customerService.createCustomer();

// Then
ArgumentCaptor<Customer> argumentCaptor = ArgumentCaptor.forClass(Customer.class);

verify(customerRepository).save(argumentCaptor.capture());
Customer value = argumentCaptor.getValue();
assertThat(value.getFirstName()).isEqualTo("Mehmet");
assertThat(value.getLastName()).isEqualTo("Demircan");
}

--

--

Software Engineer — https://www.linkedin.com/in/mehmetnuridemircan/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store