class MemoryMemberRepositoryTest
{
MemoryMemberRepository repository = new MemoryMemberRepository();
@AfterEach // ๊ฐ ํจ์ ๋๋ ๋ ๋ง๋ค ์คํํ๋ผ
public void afterEach()
{
repository.clearStore(); // repository ํจํค์ง์ ์๋ clearStore ๋งค์๋ ์ด์ฉํด๋ผ
// clearStore()๋ Store ๋ด์ key-value ์๋ค์ ์ง์ฐ๋ ๋งค์๋
}
@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); //assertThat์ ๋น๊ต ๋งค์๋. ๊ฐ์ฒด ๋ฉค๋ฒ์ ๋ฆฌ์กฐํธ๊ฐ ์๋ก ๊ฐ๋
}
@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();
//findbyName ๋งค์๋๋ spring1์ด๋ ๊ฐ์ ์ด๋ฆ์ ๊ฐ์ง ๊ฐ์ฒด๋ฅผ ๋ฝ์์ ๋ณด์ฌ์ค๋ค. -> ๊ทธ๊ฑธ ์กฐํํจ
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(); //findAll()์ store์ ์ ์ฅ๋ value์ list๋ฅผ ๋ณด์ฌ์ค๋ค.
//์ฌ๊ธฐ์ value๊ฐ์ Member์ด๋ค.
assertThat(result.size()).isEqualTo(2); //๊ฐ์ฒด 2๊ฐ ๋ฃ์๋๋ฐ, value ๊ฐ๋ 2๊ฐ์ธ์ง ํ์ธ
}
0