This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
[#30] Owner 테스트 코드 작성 #33
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.delfood.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.delfood.dto.OwnerDTO; | ||
import com.delfood.mapper.OwnerMapper; | ||
import com.delfood.utils.SHA256Util; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class OwnerServiceTest { | ||
|
||
@InjectMocks // 의존성 주입이 필요한 mock에 설정, @Mock으로 등록된 객체를 주입시켜준다. | ||
OwnerService service; | ||
|
||
@Mock // mock 생성 | ||
OwnerMapper mapper; | ||
|
||
/** | ||
* 회원가입 성공 테스트. | ||
*/ | ||
@Test | ||
public void signUp_success() { | ||
OwnerDTO ownerInfo = OwnerDTO.builder() | ||
.id("ljy2134") | ||
.password(SHA256Util.encryptSHA256("2134")) | ||
.name("이진영") | ||
.mail("asdf@naver.com") | ||
.tel("010-3333-3333") | ||
.build(); | ||
|
||
given(mapper.insertOwner(ownerInfo)).willReturn(1); | ||
service.signUp(ownerInfo); | ||
} | ||
|
||
/** | ||
* 회원가입 실패 테스트. | ||
*/ | ||
@Test(expected = RuntimeException.class) | ||
public void signUp_fail() { | ||
OwnerDTO ownerInfo = OwnerDTO.builder() | ||
.id("ljy2134") | ||
.password(SHA256Util.encryptSHA256("2134")) | ||
.name("이진영") | ||
.mail("asdf@naver.com") | ||
.tel("010-3333-3333") | ||
.build(); | ||
|
||
given(mapper.insertOwner(ownerInfo)).willReturn(0); | ||
service.signUp(ownerInfo); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌더 적용하신 아이디어 좋습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
질문있습니다! 빌더를 적용한 경우 기본 생성자를 생성할 수 없게 변하던데, 이 경우 문제는 없는건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기본생성자는 없어도 됩니다. 사실 구현의 자유인게 어차피 null을 넣을거라면 기본생성자나 빌더나 역할은 비슷하니까요