티스토리 뷰

0. 프로젝트 구조

 

1. SupplementsRepository.java 인터페이스로 변경

package mandykr.nutrient.repository;

import mandykr.nutrient.entity.Supplements;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SupplementsRepository extends JpaRepository<Supplements, Long> {

}

 

2. 테스트 코드 수정

package mandykr.nutrient;

import mandykr.nutrient.entity.Supplements;
import mandykr.nutrient.repository.SupplementsRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Commit;
import org.springframework.transaction.annotation.Transactional;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@Transactional
class SupplementsRepositoryTests {
   @Autowired
   SupplementsRepository supplementsRepository;

   @Test
   @Commit
   void save() {
      Supplements supplements = new Supplements();
      supplements.setName("빌베리 플러스");

      Supplements saveSupplements = supplementsRepository.save(supplements);
      Supplements findSupplements = supplementsRepository.findById(saveSupplements.getId()).get();

      assertThat(supplements.getName()).isEqualTo(findSupplements.getName());
   }

}

 

 

출처

https://www.inflearn.com/course/스프링부트-JPA-활용-1 실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발(김영한)

728x90