-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...n/mutbooks/src/test/java/com/example/mutbooks/app/hashTag/service/HashTagServiceTest.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,63 @@ | ||
package com.example.mutbooks.app.hashTag.service; | ||
|
||
import com.example.mutbooks.app.hashTag.entity.PostHashTag; | ||
import com.example.mutbooks.app.keyword.service.KeywordService; | ||
import com.example.mutbooks.app.post.entity.Post; | ||
import com.example.mutbooks.app.post.service.PostService; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
class HashTagServiceTest { | ||
@Autowired | ||
private PostService postService; | ||
@Autowired | ||
private HashTagService hashTagService; | ||
@Autowired | ||
private KeywordService keywordService; | ||
|
||
@Test | ||
@DisplayName("1번 게시글에 해시태그 키워드 1개 등록하기") | ||
void t1() { | ||
// given | ||
Post post = postService.findById(1); | ||
String keywordContent1 = "판타지"; | ||
String keywordContent2 = "판타지"; | ||
String keywordContent3 = "소설"; | ||
// when | ||
hashTagService.save(post, keywordContent1); | ||
hashTagService.save(post, keywordContent2); | ||
hashTagService.save(post, keywordContent3); | ||
// then | ||
List<PostHashTag> hashTags = hashTagService.findByPostId(1); | ||
|
||
assertThat(hashTags.size()).isEqualTo(2); | ||
assertThat(hashTags.get(0).getPostKeyword().getContent()).isEqualTo("판타지"); | ||
assertThat(hashTags.get(1).getPostKeyword().getContent()).isEqualTo("소설"); | ||
} | ||
|
||
@Test | ||
@DisplayName("입력된 문자열에서 해시태그 추출해서 1번 게시글에 등록하기") | ||
void t2() { | ||
// given | ||
Post post = postService.findById(1); | ||
String keywords = "#판타지 #소설 # SF # 소설"; | ||
// when | ||
hashTagService.apply(post, keywords); | ||
// then | ||
List<PostHashTag> hashTags = hashTagService.findByPostId(1); | ||
|
||
assertThat(hashTags.size()).isEqualTo(3); | ||
assertThat(hashTags.get(0).getPostKeyword().getContent()).isEqualTo("판타지"); | ||
assertThat(hashTags.get(1).getPostKeyword().getContent()).isEqualTo("소설"); | ||
assertThat(hashTags.get(2).getPostKeyword().getContent()).isEqualTo("SF"); | ||
} | ||
} |