Skip to content

Commit

Permalink
메인 서비스 기능 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoochanhong committed Mar 19, 2023
1 parent ea142bc commit 57617d4
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.MemberManagementExample.service;

import com.example.MemberManagementExample.domain.Member;
import com.example.MemberManagementExample.repository.MemoryMemberRepository;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


class MemberServiceTest {

MemberService memberService;
MemoryMemberRepository memoryMemberRepository;

@BeforeEach
public void beforeEach() {
memoryMemberRepository = new MemoryMemberRepository();
memberService = new MemberService(memoryMemberRepository);
}

@AfterEach
public void afterEach() {
memoryMemberRepository.clearStore();
}

@Test
void 회원가입() {
//given
Member member = new Member();
member.setName("hello");

//when
Long saveId = memberService.join(member);

//then
Member findMember = memberService.findOne(saveId).get();
Assertions.assertThat(member.getName()).isEqualTo(findMember.getName());
}

@Test
void 중복_회원_예외() {
//given
Member member1 = new Member();
member1.setName("yoochanhong");

Member member2 = new Member();
member2.setName("yoochanhong");

//when
memberService.join(member1);
IllegalStateException e = org.junit.jupiter.api.Assertions.assertThrows(IllegalStateException.class, () -> memberService.join(member2));
Assertions.assertThat(e.getMessage()).isEqualTo("이미 존재하는 회원입니다.");
// try {
// memberService.join(member2);
// fail("예외가 발생하지 않았습니다.");
// } catch (IllegalStateException e) {
// Assertions.assertThat(e.getMessage()).isEqualTo("이미 존재하는 회원입니다.");
// }
//then
}

@Test
void findMembers() {
}

@Test
void findOne() {
}
}

0 comments on commit 57617d4

Please sign in to comment.