From 88c85a132fa882900a7dd9b0914998cd4e682cb5 Mon Sep 17 00:00:00 2001 From: elyudwo Date: Sun, 10 Dec 2023 19:54:48 +0900 Subject: [PATCH] =?UTF-8?q?[Test]=20:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=EC=95=8A=EB=8A=94=20=EB=8B=A8=EC=9C=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/StudyPostServiceTest.java | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/test/java/kr/co/studyhubinu/studyhubserver/user/service/StudyPostServiceTest.java diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/StudyPostServiceTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/StudyPostServiceTest.java deleted file mode 100644 index 334aa7b4..00000000 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/StudyPostServiceTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package kr.co.studyhubinu.studyhubserver.user.service; - -import kr.co.studyhubinu.studyhubserver.study.enums.StudyWayType; -import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostEntity; -import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostValidator; -import kr.co.studyhubinu.studyhubserver.studypost.dto.data.StudyPostInfo; -import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; -import kr.co.studyhubinu.studyhubserver.studypost.service.StudyPostService; -import kr.co.studyhubinu.studyhubserver.support.fixture.StudyPostEntityFixture; -import kr.co.studyhubinu.studyhubserver.support.fixture.UserEntityFixture; -import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; -import kr.co.studyhubinu.studyhubserver.user.enums.GenderType; -import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; -import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.*; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.*; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -public class StudyPostServiceTest { - @InjectMocks - private StudyPostService studyPostService; - @Mock - private StudyPostRepository studyPostRepository; - @Mock - private UserRepository userRepository; - @Mock - private StudyPostValidator studyPostValidator; - - @Test - @DisplayName("스터디 포스트 생성 성공") - void createPost_success() { - // given - Long userId = 1L; - Long postId = 2L; - StudyPostInfo info = StudyPostInfo.builder() - .userId(userId) - .title("정보처리기사") - .content("열심히 하실분만") - .chatUrl("example.com") - .major(MajorType.COMPUTER_SCIENCE_ENGINEERING) - .studyPerson(4) - .penalty(100000) - .penaltyWay("지각비") - .gender(GenderType.MALE) - .studyWay(StudyWayType.MIX) - .studyStartDate(LocalDate.of(2023, 10, 25)) - .studyEndDate(LocalDate.of(2023, 12, 25)) - .build(); - UserEntity user1 = UserEntityFixture.DONGWOO.UserEntity_생성(userId); - StudyPostEntity post1 = StudyPostEntityFixture.SQLD.studyPostEntity_생성(postId); - - BDDMockito.given(userRepository.findById(info.getUserId())).willReturn(Optional.of(user1)); - BDDMockito.given(studyPostRepository.save(any())).willReturn(post1); - - ArgumentCaptor captor = ArgumentCaptor.forClass(StudyPostEntity.class); - - // when - Long createdPostId = studyPostService.createPost(info); - - // then - verify(studyPostRepository, times(1)) - .save(captor.capture()); - StudyPostEntity capturedStudyPost = captor.getValue(); - assertEquals("정보처리기사", capturedStudyPost.getTitle()); - - assertNotNull(createdPostId); - - } -}