Skip to content

Instantly share code, notes, and snippets.

@SDiamante13
Last active March 6, 2020 02:15
Show Gist options
  • Select an option

  • Save SDiamante13/2607e721351a1b23f0b08a418c93556d to your computer and use it in GitHub Desktop.

Select an option

Save SDiamante13/2607e721351a1b23f0b08a418c93556d to your computer and use it in GitHub Desktop.
An example on how to setup what a mock returns.
@Test
public void getCustomerById_returnsCorrectCustomer_whenGivenValidId() {
// Arrange
when(mockCustomerRepository.findById(123))
.thenReturn(new Customer(123, "Sam"));
// 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