Skip to content

Commit

Permalink
refactor: 테스트 코드 간결화 및 가독성 증진
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Aug 10, 2023
1 parent 0137acb commit 10839e5
Showing 1 changed file with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import wooteco.prolog.session.domain.Session;
import wooteco.prolog.session.domain.repository.SessionRepository;

import java.util.Optional;

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

Expand Down Expand Up @@ -53,44 +51,40 @@ public void removeAll() {
@DisplayName("추천 포스트 생성 테스트")
void create() {
//given
final RecommendedRequest request = new RecommendedRequest("https//:example.com");
final RecommendedRequest request = new RecommendedRequest("https://example.com");

//when
Long recommendedPostId = recommendedPostService.create(keyword.getId(), request);

final Keyword persistedKeyword = keywordRepository.findById(keyword.getId()).get();
final RecommendedPost persistedPost = recommendedPostRepository.findById(recommendedPostId).get();
recommendedPostService.create(keyword.getId(), request);

//then
assertSoftly(softAssertions -> {
assertThat(persistedPost.getUrl()).isEqualTo(request.getUrl());
assertThat(persistedKeyword.getRecommendedPosts()).containsExactly(persistedPost);
});
assertThat(recommendedPostRepository.findAll()).hasSize(1);
}

@Test
@DisplayName("추천 포스트 수정 테스트")
void update() {
//given
final RecommendedRequest request = new RecommendedRequest("https//:example.com");
Long recommendedPostId = recommendedPostService.create(keyword.getId(), request);
String newUrl = "https//:example222.com";
final RecommendedUpdateRequest updateRrequest = new RecommendedUpdateRequest(newUrl);
final Long recommendedPostId = recommendedPostService.create(
keyword.getId(),
new RecommendedRequest("https://example.com"));

final String newUrl = "https://new.com";
final RecommendedUpdateRequest updateRequest = new RecommendedUpdateRequest(newUrl);

//when
recommendedPostService.update(recommendedPostId, updateRrequest);
Optional<RecommendedPost> actual = recommendedPostRepository.findById(recommendedPostId);
recommendedPostService.update(recommendedPostId, updateRequest);

//then
assertThat(actual.get().getUrl()).isEqualTo(newUrl);
final RecommendedPost post = recommendedPostRepository.findById(recommendedPostId).get();
assertThat(post.getUrl()).isEqualTo(newUrl);
}

@Test
@DisplayName("추천 포스트 삭제 테스트")
void delete() {
//given
final RecommendedRequest request = new RecommendedRequest("https://example.com");
Long recommendedPostId = recommendedPostService.create(keyword.getId(), request);
final Long recommendedPostId = recommendedPostService.create(keyword.getId(), request);

//when
recommendedPostService.delete(recommendedPostId);
Expand Down

0 comments on commit 10839e5

Please sign in to comment.