Skip to content
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

Member Service 테스트 작성 #54

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package LeejuButU.BidCycle.member.service;

import LeejuButU.BidCycle.domain.member.domain.Member;
import LeejuButU.BidCycle.domain.member.repository.MemberRepository;
import LeejuButU.BidCycle.domain.member.service.MemberService;
import LeejuButU.BidCycle.fixture.Fixture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class MemberSeviceTest {

@Mock
private MemberRepository memberRepository;

private Member member;

@InjectMocks
private MemberService memberService;

@BeforeEach
void setUp() {
member = Fixture.generateMember("leeju");
}

@Test
@DisplayName("회원 가입 테스트")
public void joinTest(){

//given
when(memberRepository.existsById(anyLong())).thenReturn(false);
when(memberRepository.save(any())).thenReturn(member);

//when
Long memberId = memberService.join(member);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memberService.join() 이 실행되면서 멤버 레포지토리에서 existsById() 가 호출될 때, 지금 인자로 넘긴 member의 id 가 null이라서 anyLong() 에 맞게 long 타입 데이터가 안넘아가고 있어여


//then
verify(memberRepository, times(1)).save(member);
}

}