diff --git a/api/src/test/java/org/badminton/api/application/member/MemberFacadeTest.java b/api/src/test/java/org/badminton/api/application/member/MemberFacadeTest.java index 31f76244..28274b04 100644 --- a/api/src/test/java/org/badminton/api/application/member/MemberFacadeTest.java +++ b/api/src/test/java/org/badminton/api/application/member/MemberFacadeTest.java @@ -1,12 +1,14 @@ package org.badminton.api.application.member; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; - import org.badminton.api.interfaces.match.dto.MatchResultResponse; import org.badminton.domain.common.enums.MatchStatus; import org.badminton.domain.common.enums.MatchType; @@ -34,141 +36,142 @@ class MemberFacadeTest { - @Mock - private MemberService memberService; - - @Mock - private LeagueRecordService leagueRecordService; + @Mock + private MemberService memberService; - @Mock - private ClubMemberService clubMemberService; + @Mock + private LeagueRecordService leagueRecordService; - @Mock - private MatchResultService matchResultService; + @Mock + private ClubMemberService clubMemberService; - @InjectMocks - private MemberFacade memberFacade; + @Mock + private MatchResultService matchResultService; - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - } + @InjectMocks + private MemberFacade memberFacade; - @Test - @DisplayName("회원 마이페이지 조회 API 테스트") - void getMemberMyPageInfoTest() { - String memberToken = "testToken"; + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } - List clubMemberMyPageInfos = new ArrayList<>(); - when(clubMemberService.getClubMembers(memberToken)).thenReturn(clubMemberMyPageInfos); + @Test + @DisplayName("회원 마이페이지 조회 API 테스트") + void getMemberMyPageInfoTest() { + String memberToken = "testToken"; - LeagueRecord leagueRecord = mock(LeagueRecord.class); - when(leagueRecordService.getLeagueRecord(memberToken)).thenReturn(leagueRecord); + List clubMemberMyPageInfos = new ArrayList<>(); + when(clubMemberService.getClubMembers(memberToken)).thenReturn(clubMemberMyPageInfos); - LeagueRecordInfo leagueRecordInfo = LeagueRecordInfo.from(leagueRecord); - MemberMyPageInfo expectedInfo = new MemberMyPageInfo("testToken", "김철수", "abcd@naver.com", "www.naver.com", - Member.MemberTier.BRONZE, 3, 2, 1, 6, null); - when(memberService.getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos)).thenReturn( - expectedInfo); + LeagueRecord leagueRecord = mock(LeagueRecord.class); + when(leagueRecordService.getLeagueRecord(memberToken)).thenReturn(leagueRecord); - MemberMyPageInfo result = memberFacade.getMemberMyPageInfo(memberToken); + LeagueRecordInfo leagueRecordInfo = LeagueRecordInfo.from(leagueRecord); + MemberMyPageInfo expectedInfo = new MemberMyPageInfo("testToken", "김철수", "abcd@naver.com", "www.naver.com", + Member.MemberTier.BRONZE, 3, 2, 1, 6, null); + when(memberService.getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos)).thenReturn( + expectedInfo); - assertNotNull(result); - assertEquals(expectedInfo, result); + MemberMyPageInfo result = memberFacade.getMemberMyPageInfo(memberToken); - verify(clubMemberService).getClubMembers(memberToken); - verify(leagueRecordService).getLeagueRecord(memberToken); - verify(memberService).getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos); - } + assertNotNull(result); + assertEquals(expectedInfo, result); - @Test - @DisplayName("회원 정보 간단 조회 API 테스트") - void getSimpleMemberTest() { - String memberToken = "testToken"; - SimpleMemberInfo expectedInfo = new SimpleMemberInfo(null, "김철수", "abcd@naver.com", Member.MemberTier.BRONZE, - "www.naver.com"); + verify(clubMemberService).getClubMembers(memberToken); + verify(leagueRecordService).getLeagueRecord(memberToken); + verify(memberService).getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos); + } - when(memberService.getSimpleMember(memberToken)).thenReturn(expectedInfo); + @Test + @DisplayName("회원 정보 간단 조회 API 테스트") + void getSimpleMemberTest() { + String memberToken = "testToken"; + SimpleMemberInfo expectedInfo = new SimpleMemberInfo(null, "member_token_1", "김철수", "abcd@naver.com", + Member.MemberTier.BRONZE, + "www.naver.com"); - SimpleMemberInfo result = memberFacade.getSimpleMember(memberToken); + when(memberService.getSimpleMember(memberToken)).thenReturn(expectedInfo); - assertNotNull(result); - assertEquals(expectedInfo, result); + SimpleMemberInfo result = memberFacade.getSimpleMember(memberToken); - verify(memberService).getSimpleMember(memberToken); - } + assertNotNull(result); + assertEquals(expectedInfo, result); - @Test - @DisplayName("회원 정보 업데이트 API 테스트") - void updateProfileTest() { - String memberToken = "testToken"; - String imageUrl = "image_url"; - String name = "name"; - MemberUpdateInfo expectedInfo = new MemberUpdateInfo("testToken", null, "김철수", "abc@naver.com", "providerId", - "profileImage"); + verify(memberService).getSimpleMember(memberToken); + } - when(memberService.updateProfile(memberToken, imageUrl, name)).thenReturn(expectedInfo); + @Test + @DisplayName("회원 정보 업데이트 API 테스트") + void updateProfileTest() { + String memberToken = "testToken"; + String imageUrl = "image_url"; + String name = "name"; + MemberUpdateInfo expectedInfo = new MemberUpdateInfo("testToken", null, "김철수", "abc@naver.com", "providerId", + "profileImage"); - MemberUpdateInfo result = memberFacade.updateProfile(memberToken, imageUrl, name); + when(memberService.updateProfile(memberToken, imageUrl, name)).thenReturn(expectedInfo); - assertNotNull(result); - assertEquals(expectedInfo, result); + MemberUpdateInfo result = memberFacade.updateProfile(memberToken, imageUrl, name); - verify(memberService).updateProfile(memberToken, imageUrl, name); - } + assertNotNull(result); + assertEquals(expectedInfo, result); - @Test - @DisplayName("회원이 가입되어 있는 동호회 조회 API 테스트") - void getMyClubsTest() { - String memberToken = "testToken"; - List expectedClubs = new ArrayList<>(); + verify(memberService).updateProfile(memberToken, imageUrl, name); + } - when(clubMemberService.getClubsByMemberToken(memberToken)).thenReturn(expectedClubs); + @Test + @DisplayName("회원이 가입되어 있는 동호회 조회 API 테스트") + void getMyClubsTest() { + String memberToken = "testToken"; + List expectedClubs = new ArrayList<>(); - List result = memberFacade.getMyClubs(memberToken); + when(clubMemberService.getClubsByMemberToken(memberToken)).thenReturn(expectedClubs); - assertNotNull(result); - assertEquals(expectedClubs, result); + List result = memberFacade.getMyClubs(memberToken); - verify(clubMemberService).getClubsByMemberToken(memberToken); - } + assertNotNull(result); + assertEquals(expectedClubs, result); - @Test - @DisplayName("회원 매치 전적 조회 API 테스트") - void getMemberMatchResultsTest() { - String memberToken = "testToken"; - int page = 0; - int size = 10; + verify(clubMemberService).getClubsByMemberToken(memberToken); + } - // Mock ClubMemberMyPageInfo - ClubMemberMyPageInfo clubMember = mock(ClubMemberMyPageInfo.class); - when(clubMember.clubMemberId()).thenReturn(1L); // 반환 타입은 Long - when(clubMemberService.getClubMembers(memberToken)).thenReturn( - List.of(clubMember)); // 반환 타입은 List + @Test + @DisplayName("회원 매치 전적 조회 API 테스트") + void getMemberMatchResultsTest() { + String memberToken = "testToken"; + int page = 0; + int size = 10; - // Mock MatchResultInfo - MatchResultInfo matchResult = mock(MatchResultInfo.class); - when(matchResult.matchId()).thenReturn(1L); - when(matchResult.leagueId()).thenReturn(10L); - when(matchResult.matchType()).thenReturn(MatchType.SINGLES); - when(matchResult.singlesMatch()).thenReturn(mock(SinglesMatchResultInfo.class)); - when(matchResult.matchStatus()).thenReturn(MatchStatus.FINISHED); - when(matchResult.leagueAt()).thenReturn(LocalDateTime.now()); - - // MatchResultService의 동작 설정 - when(matchResultService.getAllMatchResultsByClubMember(1L)).thenReturn(List.of(matchResult)); + // Mock ClubMemberMyPageInfo + ClubMemberMyPageInfo clubMember = mock(ClubMemberMyPageInfo.class); + when(clubMember.clubMemberId()).thenReturn(1L); // 반환 타입은 Long + when(clubMemberService.getClubMembers(memberToken)).thenReturn( + List.of(clubMember)); // 반환 타입은 List + + // Mock MatchResultInfo + MatchResultInfo matchResult = mock(MatchResultInfo.class); + when(matchResult.matchId()).thenReturn(1L); + when(matchResult.leagueId()).thenReturn(10L); + when(matchResult.matchType()).thenReturn(MatchType.SINGLES); + when(matchResult.singlesMatch()).thenReturn(mock(SinglesMatchResultInfo.class)); + when(matchResult.matchStatus()).thenReturn(MatchStatus.FINISHED); + when(matchResult.leagueAt()).thenReturn(LocalDateTime.now()); + + // MatchResultService의 동작 설정 + when(matchResultService.getAllMatchResultsByClubMember(1L)).thenReturn(List.of(matchResult)); - // Perform the test - Page result = memberFacade.getMemberMatchResults(memberToken, page, size); + // Perform the test + Page result = memberFacade.getMemberMatchResults(memberToken, page, size); - // Assertions - assertNotNull(result); - assertEquals(1, result.getContent().size()); - assertEquals(matchResult.matchId(), result.getContent().get(0).matchId()); - - // Verify 호출 확인 - verify(clubMemberService).getClubMembers(memberToken); - verify(matchResultService).getAllMatchResultsByClubMember(1L); - } + // Assertions + assertNotNull(result); + assertEquals(1, result.getContent().size()); + assertEquals(matchResult.matchId(), result.getContent().get(0).matchId()); + + // Verify 호출 확인 + verify(clubMemberService).getClubMembers(memberToken); + verify(matchResultService).getAllMatchResultsByClubMember(1L); + } }