Skip to content

Commit

Permalink
test: 키워드별 추천 포스트 엔티티 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Aug 10, 2023
1 parent f0edbca commit 4498cc5
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package wooteco.prolog.roadmap.domain;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

class RecommendedPostTest {

@Test
@DisplayName("삭제 기능 테스트")
void remove() {
//given
final RecommendedPost recommendedPost = new RecommendedPost(1L, "https://example.com", null);
final Keyword keyword = Keyword.createKeyword("이름", "설명", 1, 1, 1L, null);
recommendedPost.addKeyword(keyword);

//when
final Keyword before = recommendedPost.getKeyword();
recommendedPost.remove();
final Keyword after = recommendedPost.getKeyword();

//then
Assertions.assertAll(
() -> assertThat(before).isNotNull(),
() -> assertThat(after).isNull()
);

}

@Test
@DisplayName("소속 키워드를 추가한다")
void addKeyword() {
//given
final RecommendedPost post = new RecommendedPost("http://연어");
final Keyword keyword = Keyword.createKeyword("name", "description", 1, 1, 1L, null);

//when
post.addKeyword(keyword);

//then
assertSoftly(soft -> {
assertThat(post.getKeyword()).isEqualTo(keyword);
assertThat(keyword.getRecommendedPosts()).containsExactly(post);
});
}
}

0 comments on commit 4498cc5

Please sign in to comment.