-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea142bc
commit 57617d4
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...tExample/src/test/java/com/example/MemberManagementExample/service/MemberServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |