package com.study.hello.repository;
import static org.assertj.core.api.Assertions.*;
import com.study.hello.domain.Member;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
class MemoryMemberRepositoryTest {
MemoryMemberRepository repository = new MemoryMemberRepository();
// 테스트 한 블럭 끝날 때마다 데이터삭제
@AfterEach
public void afterEach() {
repository.clearStore();
}
@Test
public void save() {
// 테스트를 위한 객체 생성
Member member = new Member();
member.setName("spring");
// 생성한 객체 저장
repository.save(member);
// 테스트하고 싶은 메서드
Member result = repository.findById(member.getId()).get();
// 내가 원하는 값이 나왔는지
assertThat(member).isEqualTo(result);
}
@Test
public void findByName() {
Member member1 = new Member();
member1.setName("spring1");
repository.save(member1);
Member member2 = new Member();
member2.setName("spring2");
repository.save(member2);
Member result = repository.findByName("spring1").get();
assertThat(result).isEqualTo(member1);
}
@Test
public void findAll() {
Member member1 = new Member();
member1.setName("spring1");
repository.save(member1);
Member member2 = new Member();
member2.setName("spring2");
repository.save(member2);
List<Member> result = repository.findAll();
assertThat(result.size()).isEqualTo(2);
}
}