Skip to content

Commit

Permalink
refactor: jpa 레포지토리 저장 테스트 메서드에서 엔티티 매니저 사용하는 코드 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
swonny committed Oct 15, 2023
1 parent 0514d3e commit 3cdb019
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class JpaBidRepositoryTest extends JpaBidRepositoryFixture {
final Bid actual = bidRepository.save(bid);

// then
em.flush();
em.clear();

assertThat(actual.getId()).isPositive();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture {
EntityManager em;

@Autowired
JpaChatRoomRepository chatRoomRepository;
JpaChatRoomRepository jpaChatRoomRepository;

@Test
void 채팅방을_저장한다() {
// given
final ChatRoom chatRoom = new ChatRoom(경매, 구매자);

// when
chatRoomRepository.save(chatRoom);
jpaChatRoomRepository.save(chatRoom);

// then
em.flush();
em.clear();

assertThat(chatRoom.getId()).isPositive();
}

@Test
void 지정한_아이디에_대한_채팅방을_조회한다() {
// when
final Optional<ChatRoom> actual = chatRoomRepository.findById(채팅방.getId());
final Optional<ChatRoom> actual = jpaChatRoomRepository.findById(채팅방.getId());

// then
assertThat(actual).contains(채팅방);
Expand All @@ -56,7 +53,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture {
@Test
void 지정한_경매_아이디가_포함된_채팅방의_아이디를_조회한다() {
// when
final Optional<Long> actual = chatRoomRepository.findChatRoomIdByAuctionId(경매.getId());
final Optional<Long> actual = jpaChatRoomRepository.findChatRoomIdByAuctionId(경매.getId());

// then
assertThat(actual).contains(채팅방.getId());
Expand All @@ -65,7 +62,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture {
@Test
void 지정한_경매_아이디가_포함된_채팅방이_존재한다면_참을_반환한다() {
// when
final boolean actual = chatRoomRepository.existsByAuctionId(경매.getId());
final boolean actual = jpaChatRoomRepository.existsByAuctionId(경매.getId());

// then
assertThat(actual).isTrue();
Expand All @@ -74,7 +71,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture {
@Test
void 지정한_경매_아이디가_포함된_채팅방이_존재하지_않는다면_거짓을_반환한다() {
// when
final boolean actual = chatRoomRepository.existsByAuctionId(존재하지_않는_채팅방_아이디);
final boolean actual = jpaChatRoomRepository.existsByAuctionId(존재하지_않는_채팅방_아이디);

// then
assertThat(actual).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class JpaMessageRepositoryTest extends JpaMessageRepositoryFixture {
// when
final Message actual = messageRepository.save(메시지);

em.flush();
em.clear();

// then
assertThat(actual.getId()).isPositive();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
EntityManager em;

@Autowired
JpaReviewRepository reviewRepository;
JpaReviewRepository jpaReviewRepository;

@Test
void 평가를_저장한다() {
// when
reviewRepository.save(저장하려는_평가);
jpaReviewRepository.save(저장하려는_평가);

// then
em.flush();
em.clear();

assertThat(저장하려는_평가.getId()).isPositive();
}

@Test
void 지정한_경매_아이디와_작성자_아이디를_포함하는_평가가_존재하면_참을_반환한다() {
// when
final boolean actual = reviewRepository.existsByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId());
final boolean actual = jpaReviewRepository.existsByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId());

// then
assertThat(actual).isTrue();
Expand All @@ -55,7 +52,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
@Test
void 지정한_채팅방_아이디를_포함하는_평가가_존재하지_않는다면_거짓을_반환한다() {
// when
final boolean actual = reviewRepository.existsByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId());
final boolean actual = jpaReviewRepository.existsByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId());

// then
assertThat(actual).isFalse();
Expand All @@ -64,7 +61,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
@Test
void 지정한_아이디가_평가_대상_아이디에_해당하는_평가_목록을_최신순으로_조회한다() {
// when
final List<Review> actual = reviewRepository.findAllByTargetId(구매자.getId());
final List<Review> actual = jpaReviewRepository.findAllByTargetId(구매자.getId());

// then
SoftAssertions.assertSoftly(softAssertions -> {
Expand All @@ -78,7 +75,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
void 지정한_경매_아이디와_작성자_아이디가_해당하는_평가가_존재한다면_optional에_넣어_반환한다() {
// when
final Optional<Review> actual =
reviewRepository.findByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId());
jpaReviewRepository.findByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId());

// then
assertThat(actual).contains(구매자가_판매자1에게_받은_평가);
Expand All @@ -88,7 +85,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
void 지정한_경매_아이디와_작성자_아이디가_해당하는_평가가_존재하지_않는다면_빈_optional을_반환한다() {
// when
final Optional<Review> actual =
reviewRepository.findByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId());
jpaReviewRepository.findByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId());

// then
assertThat(actual).isEmpty();
Expand All @@ -97,7 +94,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture {
@Test
void 지정한_평가_아이디보다_아이디가_큰_평가_목록을_조회한다() {
// when
final List<Review> actual = reviewRepository.findAllByIdGreaterThan(구매자가_판매자1에게_받은_평가.getId());
final List<Review> actual = jpaReviewRepository.findAllByIdGreaterThan(구매자가_판매자1에게_받은_평가.getId());

// then
SoftAssertions.assertSoftly(softAssertions -> {
Expand Down

0 comments on commit 3cdb019

Please sign in to comment.