-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemberServiceTest.java
64 lines (50 loc) · 1.91 KB
/
MemberServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package hello.hellospring.service;
import hello.hellospring.domain.Member;
import hello.hellospring.repository.MemoryMemberRepository;
import org.assertj.core.api.AbstractBigDecimalAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ClassBasedNavigableIterableAssert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.ClassBasedNavigableIterableAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
class MemberServiceTest {
MemberService memberService = new MemberService();
@AfterEach //메서드가 끝날때마다 실행되는것 save, find등이 끝날 때 마다 store를 비워준다.
public void afterEach() {
MemoryMemberRepository repository;
repository.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
public void 중복_회원_제외(){
//given
Member member1 =new Member();
member1.setName("spring");
Member member2 = new Member();
member2.setName("spring");
//when
memberService.join(member1);
IllegalStateException e = assertThrows(IllegalStateException.class, ()-> memberService.join(member2));
assertThat(e.getMessage()).isEqualTo("이미 존재하는 회원입니다.");
// memberService.join(member1); //예외를 터지게 한다.
/*
try {
memberService.join(member2);
fail();
}catch (IllegalStateException e) {
assertThat(e.getMessage()).isEqualTo("이미존재하는 회원입니다.");
}
*/
}
}