Created
March 6, 2020 02:50
-
-
Save SDiamante13/391e3271c88e99ea2620021ca8af13cf to your computer and use it in GitHub Desktop.
An example of how to use doReturn When for a spy.
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 getCustomerById_returnsCorrectCustomer_whenGivenValidId() { | |
| // Arrange | |
| doReturn(new Customer(123, "Sam")) | |
| .when(spyCustomerRepository).findById(123) | |
| // Act | |
| Customer result = customerService.getCustomerById(123); | |
| // Assert | |
| assertThat(result.name).isEqualTo("Sam"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment