Skip to content

Commit

Permalink
test : Member Service 테스트 작성 (#53)
Browse files Browse the repository at this point in the history
* 회원가입 테스트 작성
  • Loading branch information
ezeun committed Apr 28, 2024
1 parent f906d02 commit 96e0679
Showing 1 changed file with 55 additions and 0 deletions.
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);

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

}

0 comments on commit 96e0679

Please sign in to comment.