-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[리팩토링] Post, Service 코드 개선 및 테스트 코드 추가 #129
Open
tape22
wants to merge
9
commits into
develop
Choose a base branch
from
feature/test2
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
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
27d1153
Test : 댓글 Service 테스트 코드 작성중
ybell1028 899be5d
Test : 댓글 Service 테스트 코드 작성완료
ybell1028 b92fe48
Add : DBUnit 설정 추가
ybell1028 24772fd
Test : UserRepositoryTest 코드 추가
ybell1028 d9c0211
Fix : userIdx Sequence 초기화 메소드 추가, 테스트 실패 이슈 해결
ybell1028 ad4d613
Test : CommentRepositoryTest 작성
ybell1028 7cb411b
Test : LikeRepositoryTest 작성
ybell1028 08b55ac
Chore: 회고글 목록 조회 시 예외처리 추가
tape22 6cb3aba
Refactor: PostController @CurrentUser로 변경, ResponseEntity 빌더 타입 리팩토링
tape22 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
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
73 changes: 68 additions & 5 deletions
73
src/test/java/com/yapp18/retrospect/domain/user/UserRepositoryTest.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 |
---|---|---|
@@ -1,27 +1,90 @@ | ||
package com.yapp18.retrospect.domain.user; | ||
|
||
import com.github.springtestdbunit.annotation.DatabaseSetup; | ||
import com.github.springtestdbunit.annotation.ExpectedDatabase; | ||
import com.github.springtestdbunit.assertion.DatabaseAssertionMode; | ||
import com.yapp18.retrospect.annotation.RetrospectDataTest; | ||
import com.yapp18.retrospect.common.EntityCreator; | ||
import com.yapp18.retrospect.config.ErrorInfo; | ||
import com.yapp18.retrospect.web.advice.EntityNullException; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RetrospectDataTest | ||
@DatabaseSetup({ | ||
"classpath:dbunit/entity/user.xml" | ||
}) | ||
public class UserRepositoryTest { | ||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@Autowired | ||
EntityManager entityManager; | ||
|
||
private final long USER_IDX = 1L; | ||
|
||
@Test | ||
@DatabaseSetup({ | ||
"classpath:dbunit/User/빈_사용자_테이블.xml" | ||
}) | ||
@ExpectedDatabase(value = "classpath:dbunit/User/사용자_한명_존재.xml", | ||
assertionMode= DatabaseAssertionMode.NON_STRICT) | ||
public void 사용자_정보_등록(){ | ||
User user = EntityCreator.createUserEntity(); | ||
|
||
userRepository.save(user); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup({ | ||
"classpath:dbunit/User/사용자_한명_존재.xml" | ||
}) | ||
public void 사용자_정보_조회(){ | ||
User expected = EntityCreator.createUserEntity(); | ||
|
||
User user = userRepository.findById(1L) | ||
.orElseThrow(() -> new EntityNullException(ErrorInfo.USER_NULL)); | ||
|
||
assertThat(user.getUserIdx()).isEqualTo(expected.getUserIdx()); | ||
assertThat(user.getEmail()).isEqualTo(expected.getEmail()); | ||
assertThat(user.getName()).isEqualTo(expected.getName()); | ||
assertThat(user.getNickname()).isEqualTo(expected.getNickname()); | ||
assertThat(user.getProfile()).isEqualTo(expected.getProfile()); | ||
assertThat(user.getJob()).isEqualTo(expected.getJob()); | ||
assertThat(user.getIntro()).isEqualTo(expected.getIntro()); | ||
assertThat(user.getProvider()).isEqualTo(expected.getProvider()); | ||
assertThat(user.getProviderId()).isEqualTo(expected.getProviderId()); | ||
assertThat(user.getRole()).isEqualTo(expected.getRole()); | ||
} | ||
|
||
@Test | ||
public void 멤버_조회(){ | ||
@DatabaseSetup({ | ||
"classpath:dbunit/User/사용자_한명_존재.xml" | ||
}) | ||
@ExpectedDatabase(value = "classpath:dbunit/User/수정된_사용자_정보.xml", | ||
assertionMode= DatabaseAssertionMode.NON_STRICT) | ||
public void 사용자_정보_수정(){ | ||
User user = userRepository.findById(1L) | ||
.orElseThrow(() -> new EntityNullException(ErrorInfo.USER_NULL)); | ||
|
||
assertThat(user.getUserIdx()).isEqualTo(1L); | ||
user.updateProfile("수정된이름", "수정된닉네임", "수정된프로필URL", "수정된직업", "수정된자기소개"); | ||
|
||
entityManager.flush(); // flush 연산을 통해 데이터베이스에 강제 반영 | ||
} | ||
|
||
@Test | ||
@DatabaseSetup({ | ||
"classpath:dbunit/User/사용자_한명_존재.xml" | ||
}) | ||
@ExpectedDatabase(value = "classpath:dbunit/User/빈_사용자_테이블.xml", | ||
assertionMode= DatabaseAssertionMode.NON_STRICT) | ||
public void 사용자_정보_삭제(){ | ||
User user = userRepository.findById(USER_IDX) | ||
.orElseThrow(() -> new EntityNullException(ErrorInfo.USER_NULL)); | ||
|
||
userRepository.delete(user); | ||
|
||
entityManager.flush(); // flush 연산을 통해 데이터베이스에 강제 반영 | ||
} | ||
} |
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,4 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<dataset> | ||
<user_tb/> | ||
</dataset> |
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,25 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
|
||
<dataset> | ||
<user_tb USER_IDX="1" | ||
EMAIL="[email protected]" | ||
NAME="테스트이름" | ||
NICKNAME="테스트닉네임" | ||
PROFILE="프로필URL" | ||
JOB="테스트직업" | ||
INTRO="테스트자기소개" | ||
PROVIDER="kakao" | ||
PROVIDER_ID="1" | ||
ROLE="MEMBER"/> | ||
|
||
<user_tb USER_IDX="2" | ||
EMAIL="[email protected]" | ||
NAME="테스트이름2" | ||
NICKNAME="테스트닉네임2" | ||
PROFILE="프로필URL2" | ||
JOB="테스트직업2" | ||
INTRO="테스트자기소개2" | ||
PROVIDER="google" | ||
PROVIDER_ID="2" | ||
ROLE="MEMBER"/> | ||
</dataset> |
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,14 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
|
||
<dataset> | ||
<user_tb USER_IDX="1" | ||
EMAIL="[email protected]" | ||
NAME="테스트이름" | ||
NICKNAME="테스트닉네임" | ||
PROFILE="프로필URL" | ||
JOB="테스트직업" | ||
INTRO="테스트자기소개" | ||
PROVIDER="kakao" | ||
PROVIDER_ID="1" | ||
ROLE="MEMBER"/> | ||
</dataset> |
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,14 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
|
||
<dataset> | ||
<user_tb USER_IDX="1" | ||
EMAIL="[email protected]" | ||
NAME="수정된이름" | ||
NICKNAME="수정된닉네임" | ||
PROFILE="수정된프로필URL" | ||
JOB="수정된직업" | ||
INTRO="수정된자기소개" | ||
PROVIDER="kakao" | ||
PROVIDER_ID="1" | ||
ROLE="MEMBER"/> | ||
</dataset> |
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.
import static org.junit.jupiter.api.Assertions.assertEquals;
assertEquals(user.getUserIdx(), expected.getUserIdx());
-> 요거 쓰면 훨씬 간결하고 깔끔하게 비교할 수 있음
만약 boolean 값을 비교하고 싶다면 assertTrue(예상값); 이런 식으로도 활용 가능!
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.
코드가 짧아지는것도 좋지만 기댓값, 예상값이 뚜렷하게 보여서 실수도 미연에 방지할 수 있고 가독성이 더 높은 Aseertj(AssertThat)를 이용함!
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.
오호 나는 오히려 assertEquals가 가독성이 좋다고 생각했는데 그런 차이가 있었구먼👍
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.
https://itcoin.tistory.com/500
대충 이러이러한 장점이 있다네여