Skip to content

Instantly share code, notes, and snippets.

@atesibrahim
Created June 30, 2022 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atesibrahim/e58a833a486049fc122aa4b68452ea43 to your computer and use it in GitHub Desktop.
Save atesibrahim/e58a833a486049fc122aa4b68452ea43 to your computer and use it in GitHub Desktop.
@Test
public void it_should_test_when_product_id_is_valid() throws Exception {
//given
ProductRequest productRequest = ProductRequest.builder().id(1).build();
ArgumentCaptor<ProductRequest> argumentCaptor = ArgumentCaptor.forClass(ProductRequest.class);
//when
ResultActions result = mockMvc.perform(post("/products")
.content(objectMapper.writeValueAsString(productRequest))
.contentType(MediaType.APPLICATION_JSON));
//then
verify(productService).dispense(argumentCaptor.capture());
result.andExpect(status().isOk());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment