-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: topic service -> facade 테스트 코드 리펙토링
- describe context it 패턴 적용 - topicServiceTest -> topicFacadeTest로 변경 - facade pattern에 맞게 수정
- Loading branch information
Showing
3 changed files
with
138 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/test/java/com/genius/gitget/admin/topic/service/TopicFacadeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.genius.gitget.admin.topic.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.genius.gitget.global.util.exception.BusinessException; | ||
import com.genius.gitget.topic.domain.Topic; | ||
import com.genius.gitget.topic.dto.TopicCreateRequest; | ||
import com.genius.gitget.topic.dto.TopicDetailResponse; | ||
import com.genius.gitget.topic.dto.TopicUpdateRequest; | ||
import com.genius.gitget.topic.serviceFacade.TopicFacade; | ||
import jakarta.transaction.Transactional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.Rollback; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
@Rollback | ||
public class TopicFacadeTest { | ||
Topic topicA, topicB; | ||
String fileType; | ||
|
||
@Autowired | ||
TopicFacade topicFacade; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
topicA = Topic.builder() | ||
.title("1일 1알고리즘") | ||
.description("하루에 한 문제씩 문제를 해결합니다.") | ||
.tags("BE, FE, CS") | ||
.pointPerPerson(100) | ||
.build(); | ||
|
||
topicB = Topic.builder() | ||
.title("1일 2알고리즘") | ||
.description("하루에 한 문제씩 문제를 해결합니다.") | ||
.tags("BE, FE, CS") | ||
.pointPerPerson(300) | ||
.build(); | ||
|
||
fileType = "topic"; | ||
} | ||
|
||
private TopicCreateRequest getTopicCreateRequest() { | ||
return TopicCreateRequest.builder() | ||
.title(topicA.getTitle()) | ||
.description(topicA.getDescription()) | ||
.tags(topicA.getTags()) | ||
.pointPerPerson(topicA.getPointPerPerson()) | ||
.notice(topicA.getNotice()) | ||
.build(); | ||
} | ||
|
||
@Nested | ||
@DisplayName("토픽 생성 메서드는") | ||
class Describe_topic_create { | ||
|
||
@Nested | ||
@DisplayName("topicCreateRequestDto가 들어오면") | ||
class Context_with_a_topicCreateRequestDto { | ||
|
||
@Test | ||
@DisplayName("토픽을 생성한다.") | ||
public void it_returns_2XX_if_the_topic_was_created_successfully() { | ||
TopicCreateRequest topicCreateRequest = getTopicCreateRequest(); | ||
|
||
Long savedTopicId = topicFacade.create(topicCreateRequest); | ||
|
||
TopicDetailResponse topicById = topicFacade.findOne(savedTopicId); | ||
|
||
Assertions.assertThat(topicById.title()).isEqualTo(topicCreateRequest.title()); | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("토픽 수정 메서드는") | ||
class Describe_topic_update { | ||
|
||
@Nested | ||
@DisplayName("TopicUpdateRequestDto가 들어오면") | ||
class Context_with_a_TopicUpdateRequestDto { | ||
|
||
@Test | ||
@DisplayName("토픽 내용을 수정한다.") | ||
public void it_returns_2XX_if_the_topic_is_modified() { | ||
TopicCreateRequest topicCreateRequest = getTopicCreateRequest(); | ||
Long savedTopicId = topicFacade.create(topicCreateRequest); | ||
|
||
TopicUpdateRequest topicUpdateRequest = TopicUpdateRequest.builder() | ||
.title("1일 5커밋") | ||
.description(topicA.getDescription()) | ||
.tags(topicA.getTags()) | ||
.pointPerPerson(topicA.getPointPerPerson()) | ||
.notice(topicA.getNotice()).build(); | ||
|
||
topicFacade.update(savedTopicId, topicUpdateRequest); | ||
|
||
TopicDetailResponse findTopic = topicFacade.findOne(savedTopicId); | ||
Assertions.assertThat(findTopic.title()).isEqualTo("1일 5커밋"); | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("토픽 삭제 메서드는") | ||
class Describe_topic_delete { | ||
|
||
@Nested | ||
@DisplayName("삭제할 토픽 Id가 주어질 때") | ||
class Context_with_a_TopicUpdateRequestDto { | ||
|
||
@Test | ||
@DisplayName("해당 토픽을 삭제한다.") | ||
public void it_returns_2XX_if_the_topic_is_successfully_deleted() throws Exception { | ||
TopicCreateRequest topicCreateRequest = getTopicCreateRequest(); | ||
Long savedTopicId = topicFacade.create(topicCreateRequest); | ||
|
||
topicFacade.delete(savedTopicId); | ||
|
||
try { | ||
topicFacade.findOne(savedTopicId); | ||
} catch (BusinessException e) { | ||
assertEquals("해당 토픽을 찾을 수 없습니다.", e.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} |
113 changes: 0 additions & 113 deletions
113
src/test/java/com/genius/gitget/admin/topic/service/TopicServiceTest.java
This file was deleted.
Oops, something went wrong.