From 0f240ba1dc2914866c0a85efca88f9dba4e080e6 Mon Sep 17 00:00:00 2001 From: SJ70 Date: Fri, 19 Jul 2024 13:00:17 +0900 Subject: [PATCH] =?UTF-8?q?fix=20&=20test:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit orElse -> orElseGet --- .../java/com/j9/bestmoments/service/MemberService.java | 5 ++--- .../com/j9/bestmoments/service/MemberServiceTest.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) 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