Last active
March 13, 2020 01:03
-
-
Save SDiamante13/1d6fda6f8ed76cdb6e8b26be732e8b0d to your computer and use it in GitHub Desktop.
An example of how to use argument captor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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