From 62d79251a747e9a608b3fddcef096a20c7031ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=B0=EC=9E=AC?= Date: Tue, 30 Nov 2021 17:33:36 +0900 Subject: [PATCH] =?UTF-8?q?[#54]=20test:=20ArticleSlugConverter=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/converter/ArticleSlugConverter.java | 4 +-- .../domain/follow/api/FollowCommandApi.java | 8 +++--- ...ice.java => FollowUserCommandService.java} | 2 +- .../converter/ArticleSlugConverterTest.java | 26 ++++++++++++++++--- ...java => FollowUserCommandServiceTest.java} | 10 +++---- 5 files changed, 35 insertions(+), 15 deletions(-) rename src/main/java/com/study/realworld/domain/follow/application/{FollowCommandService.java => FollowUserCommandService.java} (98%) rename src/test/java/com/study/realworld/domain/follow/application/{FollowCommandServiceTest.java => FollowUserCommandServiceTest.java} (91%) diff --git a/src/main/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverter.java b/src/main/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverter.java index 7bd6b863..aa94c236 100644 --- a/src/main/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverter.java +++ b/src/main/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverter.java @@ -11,7 +11,7 @@ public class ArticleSlugConverter { private static final Logger logger = LoggerFactory.getLogger(ArticleSlugConverter.class); @Component - public class StringToArticleSlugConverter implements Converter { + public static class StringToArticleSlugConverter implements Converter { @Override public ArticleSlug convert(final String source) { logger.info("StringToArticleSlugConverter : " + source); @@ -20,7 +20,7 @@ public ArticleSlug convert(final String source) { } @Component - public class ArticleSlugToStringConverter implements Converter { + public static class ArticleSlugToStringConverter implements Converter { @Override public String convert(final ArticleSlug source) { logger.info("ArticleSlugToStringConverter : " + source.toString()); diff --git a/src/main/java/com/study/realworld/domain/follow/api/FollowCommandApi.java b/src/main/java/com/study/realworld/domain/follow/api/FollowCommandApi.java index 0444c5bf..5922a6a7 100644 --- a/src/main/java/com/study/realworld/domain/follow/api/FollowCommandApi.java +++ b/src/main/java/com/study/realworld/domain/follow/api/FollowCommandApi.java @@ -1,6 +1,6 @@ package com.study.realworld.domain.follow.api; -import com.study.realworld.domain.follow.application.FollowCommandService; +import com.study.realworld.domain.follow.application.FollowUserCommandService; import com.study.realworld.domain.follow.dto.FollowResponse; import com.study.realworld.domain.follow.dto.UnFollowResponse; import com.study.realworld.domain.user.domain.vo.UserName; @@ -16,19 +16,19 @@ @RestController public class FollowCommandApi { - private final FollowCommandService followCommandService; + private final FollowUserCommandService followUserCommandService; @PostMapping("/profiles/{username}/follow") public ResponseEntity profile2(@AuthenticationPrincipal final Long userId, @PathVariable final String username) { - final FollowResponse followResponse = followCommandService.follow(userId, UserName.from(username)); + final FollowResponse followResponse = followUserCommandService.follow(userId, UserName.from(username)); return ResponseEntity.ok().body(followResponse); } @DeleteMapping("/profiles/{username}/follow") public ResponseEntity profile(@AuthenticationPrincipal final Long userId, @PathVariable final String username) { - final UnFollowResponse unfollowResponse = followCommandService.unfollow(userId, UserName.from(username)); + final UnFollowResponse unfollowResponse = followUserCommandService.unfollow(userId, UserName.from(username)); return ResponseEntity.ok().body(unfollowResponse); } } diff --git a/src/main/java/com/study/realworld/domain/follow/application/FollowCommandService.java b/src/main/java/com/study/realworld/domain/follow/application/FollowUserCommandService.java similarity index 98% rename from src/main/java/com/study/realworld/domain/follow/application/FollowCommandService.java rename to src/main/java/com/study/realworld/domain/follow/application/FollowUserCommandService.java index 53af9189..4512f3d3 100644 --- a/src/main/java/com/study/realworld/domain/follow/application/FollowCommandService.java +++ b/src/main/java/com/study/realworld/domain/follow/application/FollowUserCommandService.java @@ -16,7 +16,7 @@ @RequiredArgsConstructor @Transactional @Service -public class FollowCommandService { +public class FollowUserCommandService { private final UserQueryService userQueryService; private final FollowRepository followRepository; diff --git a/src/test/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverterTest.java b/src/test/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverterTest.java index 769180ac..aca43869 100644 --- a/src/test/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverterTest.java +++ b/src/test/java/com/study/realworld/domain/article/api/converter/ArticleSlugConverterTest.java @@ -1,13 +1,33 @@ package com.study.realworld.domain.article.api.converter; +import com.study.realworld.domain.article.api.converter.ArticleSlugConverter.ArticleSlugToStringConverter; +import com.study.realworld.domain.article.api.converter.ArticleSlugConverter.StringToArticleSlugConverter; +import com.study.realworld.domain.article.domain.vo.ArticleSlug; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.assertj.core.api.Assertions.assertThat; @DisplayName("게시글 슬러그 컨버터(ArticleSlugConverter)") class ArticleSlugConverterTest { - @Test - void test() { + @ParameterizedTest(name = "입력값 : {0}") + @ValueSource(strings = {"a", "ab", "abc"}) + void 문자열을_객체로_변환할_수_있다(String slugString) { + final StringToArticleSlugConverter converter = new StringToArticleSlugConverter(); + final ArticleSlug articleSlug = converter.convert(slugString); + + assertThat(articleSlug.articleSlug()).isEqualTo(slugString); + } + + @ParameterizedTest(name = "입력값 : {0}") + @ValueSource(strings = {"a", "ab", "abc"}) + void 객체를_문자열로_변환할_수_있다(String slugString) { + final ArticleSlug articleSlug = ArticleSlug.from(slugString); + final ArticleSlugToStringConverter converter = new ArticleSlugToStringConverter(); + final String actual = converter.convert(articleSlug); + assertThat(actual).isEqualTo(slugString); } } diff --git a/src/test/java/com/study/realworld/domain/follow/application/FollowCommandServiceTest.java b/src/test/java/com/study/realworld/domain/follow/application/FollowUserCommandServiceTest.java similarity index 91% rename from src/test/java/com/study/realworld/domain/follow/application/FollowCommandServiceTest.java rename to src/test/java/com/study/realworld/domain/follow/application/FollowUserCommandServiceTest.java index 99b7c944..da90c128 100644 --- a/src/test/java/com/study/realworld/domain/follow/application/FollowCommandServiceTest.java +++ b/src/test/java/com/study/realworld/domain/follow/application/FollowUserCommandServiceTest.java @@ -26,7 +26,7 @@ @DisplayName("팔로우 커멘드 서비스(FollowCommandService)") @ExtendWith(MockitoExtension.class) -class FollowCommandServiceTest { +class FollowUserCommandServiceTest { @Mock private UserQueryService userQueryService; @@ -35,7 +35,7 @@ class FollowCommandServiceTest { private FollowRepository followRepository; @InjectMocks - private FollowCommandService followCommandService; + private FollowUserCommandService followUserCommandService; @Test void 팔로워_아이덴티티와_팔로위_이름을_입력하면_팔로우_할_수_있다() { @@ -48,7 +48,7 @@ class FollowCommandServiceTest { willReturn(false).given(followRepository).existsByFolloweeAndFollower(any(), any()); willReturn(follow).given(followRepository).save(any()); - final FollowResponse followResponse = followCommandService.follow(1L, followee.userName()); + final FollowResponse followResponse = followUserCommandService.follow(1L, followee.userName()); assertAll( () -> assertThat(followResponse.userName()).isEqualTo(followee.userName()), () -> assertThat(followResponse.userBio()).isEqualTo(followee.userBio()), @@ -66,7 +66,7 @@ class FollowCommandServiceTest { willReturn(followee).given(userQueryService).findByUserName(any()); willReturn(true).given(followRepository).existsByFolloweeAndFollower(any(), any()); - assertThatThrownBy(() -> followCommandService.follow(1L, followee.userName())) + assertThatThrownBy(() -> followUserCommandService.follow(1L, followee.userName())) .isExactlyInstanceOf(DuplicatedFollowException.class) .hasMessage("팔로우 정보가 이미 있습니다"); } @@ -81,7 +81,7 @@ class FollowCommandServiceTest { willReturn(followee).given(userQueryService).findByUserName(any()); willReturn(Optional.of(follow)).given(followRepository).findByFolloweeAndFollower(any(), any()); - final UnFollowResponse unFollowResponse = followCommandService.unfollow(1L, followee.userName()); + final UnFollowResponse unFollowResponse = followUserCommandService.unfollow(1L, followee.userName()); assertAll( () -> assertThat(unFollowResponse.userName()).isEqualTo(followee.userName()), () -> assertThat(unFollowResponse.userBio()).isEqualTo(followee.userBio()),