Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save SDiamante13/f8cf75cbb9587c16781e43bbf49b12a7 to your computer and use it in GitHub Desktop.
An example on how to setup what a mock returns using BDD syntax.
@Test
public void getCustomerById_returnsCorrectCustomer_whenGivenValidId() {
// Given
given(mockCustomerRepository.findById(123L))
.willReturn(new Customer(123, "Sam"));
// When
Customer result = customerService.getCustomerById(123);
// Then
assertThat(result.name).isEqualTo("Sam");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment