Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 게시글 쓰기 단위 테스트 코드 구현 #263

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.ssafy.ssafsound.domain.board.repository;

import java.util.List;

import com.ssafy.ssafsound.domain.board.domain.Board;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BoardRepository extends JpaRepository<Board, Long> {
List<Board> findAllByUsedBoardTrue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BoardService {

@Transactional(readOnly = true)
public GetBoardResDto findBoards() {
List<Board> boards = boardRepository.findAll();
List<Board> boards = boardRepository.findAllByUsedBoardTrue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 생각했을때는 True없이

boardRepository.findAllByUsedBoard();

메서드 네이밍이 여기까지만 와도 이해가 잘 되는 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견 감사합니다.
메서드 네이밍 규칙에 True를 사용한 이유는 UsedBoard = True라는 조건을 걸어주기 위해서입니다!

return GetBoardResDto.from(boards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ssafy.ssafsound.domain.board.domain.Board;
import com.ssafy.ssafsound.domain.board.dto.GetBoardResDto;
import com.ssafy.ssafsound.domain.board.repository.BoardRepository;
import com.ssafy.ssafsound.domain.post.dto.GetPostResDto;
import com.ssafy.ssafsound.global.util.fixture.BoardFixture;

import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -32,25 +33,23 @@ class BoardServiceTest {

@Test
@DisplayName("게시판 목록 조회가 성공적으로 수행됩니다.")
void Given_Nothing_When_FindBoards_Then_Success() {
void Given_Empty_When_FindBoards_Then_Success() {
Board freeBoard = boardFixture.getFreeBoard();
Board jobBoard = boardFixture.getJobBoard();

List<Board> boards = List.of(freeBoard, jobBoard);

// given
given(boardRepository.findAll()).willReturn(boards);
given(boardRepository.findAllByUsedBoardTrue()).willReturn(boards);

// when
GetBoardResDto getBoardResDto = boardService.findBoards();
GetBoardResDto response = boardService.findBoards();

// then
assertThat(getBoardResDto.getBoards())
.hasSize(2)
.extracting("title")
.containsExactly(freeBoard.getTitle(), jobBoard.getTitle());
assertThat(response).usingRecursiveComparison()
.isEqualTo(GetBoardResDto.from(boards));

// verify
verify(boardRepository).findAll();
verify(boardRepository).findAllByUsedBoardTrue();
}
}