Skip to content

Commit

Permalink
#30 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsuyeondev committed May 21, 2024
1 parent f35b4d2 commit a56169a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ public void validGoodsTest() throws Exception {
public void saveGoodsFailErrorTest() throws Exception {
GoodsManagementRequest goodsManagement = requestGoods();

//given(goodsService.save(goodsManagement.toServiceDto())).willThrow(new CustomException(GoodsErrorManagement.GOODS_SAVE_ERROR));
given(goodsService.save(any())).willThrow(new CustomException(GoodsErrorManagement.GOODS_SAVE_ERROR));

//when
ResultActions resultActions = mockMvc.perform(
post("http://localhost:8080/v1/goods")
.contentType(MediaType.APPLICATION_JSON).content(new ObjectMapper().writeValueAsString(goodsManagement)));
resultActions.andDo(print()).andExpect(jsonPath("errorCode").value("GOODS_SAVE_ERROR"));
resultActions.andExpect(jsonPath("errorMessage").value("상품 등록에 실패하였습니다 잠시 후에 시도해 주세요"));

}

@Test
Expand Down Expand Up @@ -151,21 +152,4 @@ private static GoodsManagementRequest requestValidGoods() {
.build();
}


@Test
@DisplayName("상품등록 시 내부오류로 상품등록이 실패했을 경우_커스텀 예외_CustomExceptionHandler 테스트")
public void saveGoodsFailErrorTes2t() throws Exception {
GoodsManagementRequest goodsManagement = requestGoods();
//테스트실패
//java.lang.NullPointerException: Cannot invoke "com.cosmetics.domain.goods.dto.GoodsManagement.toEntity()" because "goodsManagement" is null
when(goodsService.save(goodsManagement.toServiceDto())).thenThrow(CustomException.class);

mockMvc.perform(
post("http://localhost:8080/v1/goods")
.contentType(MediaType.APPLICATION_JSON).content(new ObjectMapper().writeValueAsString(goodsManagement)))
.andDo(print())
.andExpect(jsonPath("errorCode").value("GOODS_SAVE_ERROR"))
.andExpect(jsonPath("errorMessage").value("상품 등록에 실패하였습니다 잠시 후에 시도해 주세요"));
}

}

This file was deleted.

0 comments on commit a56169a

Please sign in to comment.