Skip to content

Instantly share code, notes, and snippets.

@SDiamante13
Last active March 13, 2020 01:03
Show Gist options
  • Select an option

  • Save SDiamante13/1d6fda6f8ed76cdb6e8b26be732e8b0d to your computer and use it in GitHub Desktop.

Select an option

Save SDiamante13/1d6fda6f8ed76cdb6e8b26be732e8b0d to your computer and use it in GitHub Desktop.
An example of how to use argument captor.
@Test
public void saveCustomer_savesTheCustomerToTheDatabase() {
// Arrange
ArgumentCaptor<Customer> argumentCaptor = ArgumentCaptor.forClass(Customer.class);
Customer customer = new Customer(123, "Sam");
// Act
Customer result = customerService.saveCustomer(customer);
// Assert
verify(mockCustomerRepository, times(1))
.save(argumentCaptor.capture());
assertThat(argumentCaptor.getValue())
.isEqualToIgnoringGivenFields(customer, "timeStamp");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment