Skip to content

Commit

Permalink
fix & test: 중복 가입 오류 해결
Browse files Browse the repository at this point in the history
orElse -> orElseGet
  • Loading branch information
SJ70 committed Jul 19, 2024
1 parent 705c371 commit 0f240ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/j9/bestmoments/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public Member findById(UUID id) {

@Transactional
public Member findOrSaveByOAuthInfo(OAuthUserInfoDto oAuth2UserInfo) {
Member member = memberRepository.findByOauthProviderAndOauthId(oAuth2UserInfo.provider(), oAuth2UserInfo.id())
.orElse(this.create(oAuth2UserInfo));
return memberRepository.save(member);
return memberRepository.findByOauthProviderAndOauthId(oAuth2UserInfo.provider(), oAuth2UserInfo.id())
.orElseGet(() -> memberRepository.save(this.create(oAuth2UserInfo)));
}

private Member create(OAuthUserInfoDto oAuthUserInfoDto) {
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/com/j9/bestmoments/service/MemberServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ void findOrSaveByOAuthInfo_Find() {
null,
null
);
Member foundMember = memberService.findOrSaveByOAuthInfo(dto);
Assertions.assertEquals(member1, foundMember);
Page<Member> previousMembers = memberService.findAll(PageRequest.of(0, 100));

memberService.findOrSaveByOAuthInfo(dto);
Page<Member> currentMembers = memberService.findAll(PageRequest.of(0, 100));

long previousMembersCount = previousMembers.stream().count();
long currentMembersCount = currentMembers.stream().count();
Assertions.assertEquals(previousMembersCount, currentMembersCount);
}

@Test
Expand Down

0 comments on commit 0f240ba

Please sign in to comment.