-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#54] refactor: UserQueryService 단위 테스트 작성
- Loading branch information
Showing
5 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
7 changes: 3 additions & 4 deletions
7
src/main/java/com/study/realworld/domain/user/api/UserCommandApi.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
7 changes: 7 additions & 0 deletions
7
src/test/java/com/study/realworld/domain/user/api/UserCommandApiTest.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,7 @@ | ||
package com.study.realworld.domain.user.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class UserCommandApiTest { | ||
|
||
} |
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
49 changes: 49 additions & 0 deletions
49
src/test/java/com/study/realworld/domain/user/application/UserQueryServiceTest.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,49 @@ | ||
package com.study.realworld.domain.user.application; | ||
|
||
import com.study.realworld.domain.user.domain.persist.User; | ||
import com.study.realworld.domain.user.domain.persist.UserRepository; | ||
import com.study.realworld.domain.user.error.exception.EmailNotFoundException; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.study.realworld.domain.user.domain.persist.UserTest.testUser; | ||
import static com.study.realworld.domain.user.domain.vo.util.UserVOFixture.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.willReturn; | ||
|
||
@DisplayName("유저 쿼리 서비스(UserQueryService)") | ||
@ExtendWith({MockitoExtension.class}) | ||
class UserQueryServiceTest { | ||
|
||
@Mock | ||
private UserRepository userRepository; | ||
|
||
@InjectMocks | ||
private UserQueryService userQueryService; | ||
|
||
@Test | ||
void 이메일로_유저를_찾는다() { | ||
final User entity = testUser(USER_EMAIL, USER_NAME, USER_PASSWORD, USER_BIO, USER_IMAGE); | ||
willReturn(Optional.of(entity)).given(userRepository).findByUserEmail(any()); | ||
|
||
final User user = userQueryService.findByMemberEmail(entity.userEmail()); | ||
assertThat(user).isEqualTo(entity); | ||
} | ||
|
||
@Test | ||
void 부적절한_이메일로는_유저를_찾을_수_없다() { | ||
willReturn(Optional.empty()).given(userRepository).findByUserEmail(any()); | ||
|
||
assertThatThrownBy(() -> userQueryService.findByMemberEmail(INVALID_USER_EMAIL)) | ||
.isExactlyInstanceOf(EmailNotFoundException.class) | ||
.hasMessage(String.format("이메일 : [ %s ] 를 찾을 수 없습니다.", INVALID_USER_EMAIL.value())); | ||
} | ||
} |
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