diff --git a/src/main/java/com/j9/bestmoments/service/MemberService.java b/src/main/java/com/j9/bestmoments/service/MemberService.java index ec3e1fb..e7bf71e 100644 --- a/src/main/java/com/j9/bestmoments/service/MemberService.java +++ b/src/main/java/com/j9/bestmoments/service/MemberService.java @@ -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) { diff --git a/src/test/java/com/j9/bestmoments/service/MemberServiceTest.java b/src/test/java/com/j9/bestmoments/service/MemberServiceTest.java index 62f8fb8..6e3c2f9 100644 --- a/src/test/java/com/j9/bestmoments/service/MemberServiceTest.java +++ b/src/test/java/com/j9/bestmoments/service/MemberServiceTest.java @@ -83,8 +83,14 @@ void findOrSaveByOAuthInfo_Find() { null, null ); - Member foundMember = memberService.findOrSaveByOAuthInfo(dto); - Assertions.assertEquals(member1, foundMember); + Page previousMembers = memberService.findAll(PageRequest.of(0, 100)); + + memberService.findOrSaveByOAuthInfo(dto); + Page currentMembers = memberService.findAll(PageRequest.of(0, 100)); + + long previousMembersCount = previousMembers.stream().count(); + long currentMembersCount = currentMembers.stream().count(); + Assertions.assertEquals(previousMembersCount, currentMembersCount); } @Test