From 1648f8e2893ebc1ab39317520dd7bbe9329558e8 Mon Sep 17 00:00:00 2001 From: jjuny7712 Date: Wed, 18 Oct 2023 10:06:21 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=9C=A0=ED=9A=A8=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20memberId=EA=B0=80=20=EC=A3=BC=EC=96=B4?= =?UTF-8?q?=EC=A1=8C=EB=8B=A4=EB=A9=B4=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=EC=97=90=20=EC=98=88=EC=99=B8=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=ED=95=98=EB=8A=94=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostServiceTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/ssafy/ssafsound/domain/post/service/PostServiceTest.java b/src/test/java/com/ssafy/ssafsound/domain/post/service/PostServiceTest.java index 2476b4ca..da0f975f 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/post/service/PostServiceTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/post/service/PostServiceTest.java @@ -1,5 +1,6 @@ package com.ssafy.ssafsound.domain.post.service; +import static com.ssafy.ssafsound.domain.member.domain.QMember.*; import static com.ssafy.ssafsound.global.util.fixture.PostFixture.*; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -549,13 +550,28 @@ void Given_InvalidBoardId_When_writePost_Then_ThrowException() { @DisplayName("유효하지 않은 memberId가 주어졌다면 게시글 쓰기에 예외를 발생합니다.") void Given_InvalidMemberId_When_writePost_Then_ThrowException() { // given + Board board = boardFixture.getFreeBoard(); + Long memberId = 100L; + Post post = POST_FIXTURE1; - // when + PostPostWriteReqDto postPostWriteReqDto = PostPostWriteReqDto.builder() + .title(post.getTitle()) + .content(post.getContent()) + .anonymity(post.getAnonymity()) + .images(List.of()) + .build(); - // then + given(boardRepository.findById(board.getId())).willReturn(Optional.of(board)); + given(memberRepository.findById(memberId)).willReturn(Optional.empty()); - // verify + // when, then + MemberException exception = assertThrows(MemberException.class, + () -> postService.writePost(board.getId(), memberId, postPostWriteReqDto)); + assertEquals(MemberErrorInfo.MEMBER_NOT_FOUND_BY_ID, exception.getInfo()); + // verify + verify(boardRepository, times(1)).findById(board.getId()); + verify(memberRepository, times(1)).findById(memberId); } @Test