Skip to content

Commit 5459e20

Browse files
committed
Spring Boot tests
1 parent 5d632f4 commit 5459e20

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

springboot-examples/springboot-restapi-testing-all-layers/src/test/java/com/hellokoding/springboot/restful/product/ProductAPITest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void whenFindAll_thenReturnProductDTOList() throws Exception {
5656

5757
@Test
5858
public void whenFindById_thenReturnProductDTO() throws Exception {
59+
// given
5960
ProductDTO productDTO = ProductDTO.builder()
6061
.name("P1")
6162
.description("P1 desc")
@@ -65,6 +66,7 @@ public void whenFindById_thenReturnProductDTO() throws Exception {
6566
doReturn(Optional.of(new Product())).when(productService).findById(anyLong());
6667
doReturn(productDTO).when(productMapper).toProductDTO(any(Product.class));
6768

69+
// when + then
6870
this.mockMvc.perform(get("/api/v1/products/1"))
6971
.andExpect(status().isOk())
7072
.andExpect(jsonPath("$.name", is(productDTO.getName())));

springboot-examples/springboot-restapi-testing-all-layers/src/test/java/com/hellokoding/springboot/restful/product/ProductRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public void whenFindAll_thenReturnProductList() {
4949
List<Product> products = productRespository.findAll();
5050

5151
// then
52-
assertThat(products.size()).isEqualTo(1);
52+
assertThat(products).hasSize(1);
5353
}
5454
}

0 commit comments

Comments
 (0)