This repository was archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
#59 회원 단위테스트 추가 #124
Open
0hun
wants to merge
1
commit into
develop
Choose a base branch
from
issue/59
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
#59 회원 단위테스트 추가 #124
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
@Mapper | ||
public interface AccountMapper { | ||
|
||
Account findById(long id); | ||
|
||
void addAccount(Account account); | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -101,4 +101,8 @@ | |
AND status != 'DELETE' | ||
</update> | ||
|
||
<delete id="deleteAccountAll"> | ||
DELETE FROM account; | ||
</delete> | ||
|
||
</mapper> |
This file contains hidden or 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
111 changes: 0 additions & 111 deletions
111
src/test/java/com/younghun/hibusgo/controller/AccountControllerTest.java
This file was deleted.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
src/test/java/com/younghun/hibusgo/service/AccountServiceTest.java
This file contains hidden or 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,138 @@ | ||
package com.younghun.hibusgo.service; | ||
|
||
import com.younghun.hibusgo.aop.LoginCheck.UserLevel; | ||
import com.younghun.hibusgo.domain.Account; | ||
import com.younghun.hibusgo.domain.DataStatus; | ||
import com.younghun.hibusgo.mapper.AccountMapper; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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 org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.BDDMockito.then; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AccountServiceTest { | ||
|
||
@InjectMocks | ||
private AccountService accountService; | ||
|
||
@Mock | ||
private AccountMapper accountMapper; | ||
|
||
@Mock | ||
private PasswordEncoder passwordEncoder; | ||
|
||
Account account; | ||
|
||
final String userId = "[email protected]"; | ||
final String password = "younghun123!"; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
account = Account.builder() | ||
.userId("[email protected]") | ||
.password("younghun123!") | ||
.name("younghun") | ||
.phoneNumber("010-6769-5355") | ||
.status(DataStatus.DEFAULT) | ||
.userLevel(UserLevel.USER) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void 아이디로_회원_조회() throws Exception { | ||
//given | ||
given(accountMapper.findById(1L)).willReturn(account); | ||
|
||
//when | ||
final Account addedAccount = accountService.findById(1L); | ||
|
||
//then | ||
assertEquals(account.getId(), addedAccount.getId()); | ||
} | ||
|
||
@Test | ||
public void 아이디로_회원_존재_확인() throws Exception { | ||
//given | ||
given(accountMapper.existsById(1L)).willReturn(true); | ||
|
||
//when | ||
final boolean existsById = accountService.existsById(1L); | ||
|
||
//then | ||
assertTrue(existsById); | ||
} | ||
|
||
@Test | ||
public void 회원_추가() throws Exception{ | ||
//when | ||
accountService.addAccount(account); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서는 그럼 메소드명도 시나리오를 설명하는 형식으로 바뀌게 되겠죠~ (ex. 회원을 추가할때는 비밀번호를 암호화해서 insert 시킨다 등) |
||
|
||
//then | ||
then(accountMapper) | ||
.should() | ||
.addAccount(any(Account.class)); | ||
|
||
} | ||
|
||
@Test | ||
public void 아이디_비밀번호로_회원_조회() throws Exception{ | ||
//given | ||
String encodePassword = passwordEncoder.encode(password); | ||
given(accountMapper.findByUserIdAndPassword(userId, encodePassword)) | ||
.willReturn(account); | ||
|
||
//when | ||
final Optional<Account> addedAccount = accountService.findByUserIdAndPassword(userId, password); | ||
|
||
//then | ||
assertEquals(userId, addedAccount.get().getUserId()); | ||
} | ||
|
||
@Test | ||
public void 회원_삭제() throws Exception{ | ||
//when | ||
accountService.deleteAccount(1L); | ||
|
||
//then | ||
then(accountMapper) | ||
.should() | ||
.deleteAccount(anyLong()); | ||
} | ||
|
||
@Test | ||
public void 비밀번호_수정() throws Exception{ | ||
//given | ||
String encodePassword = passwordEncoder.encode(password); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
//when | ||
accountService.updatePassword(1L, password); | ||
|
||
//then | ||
then(accountMapper) | ||
.should() | ||
.updatePassword(1L, encodePassword); | ||
} | ||
|
||
@Test | ||
public void 회원정보_수정() throws Exception{ | ||
//when | ||
accountService.updateAccountInfo(account); | ||
|
||
//then | ||
then(accountMapper) | ||
.should() | ||
.updateAccountInfo(account); | ||
} | ||
|
||
} |
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.
여기선 메소드명이 한글로 되어있는데 이것보다는 junit5에서 지원하는 테스트의 이름을 지을 수 있는 기능을 사용해보세요~