Skip to content

Commit 394a2d2

Browse files
committed
test(community): CommunityBoard id로 조회 테스트 수정 및 예외 추가
1 parent 493d688 commit 394a2d2

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/test/java/com/somemore/community/repository/CommunityRepositoryTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class CommunityRepositoryTest extends IntegrationTestSupport {
1919
@Autowired
2020
private CommunityBoardRepository communityBoardRepository;
2121

22-
@DisplayName("커뮤니티 id로 커뮤니티 상세 정보를 조회할 수 있다. (Repository)")
22+
@DisplayName("커뮤니티 게시글 id로 커뮤니티 상세 정보를 조회할 수 있다. (Repository)")
2323
@Test
24-
void findById() {
24+
void getCommunityBoardById() {
2525
//given
2626
CommunityBoard communityBoard = CommunityBoard.builder()
2727
.title("테스트 커뮤니티 게시글 제목")
@@ -33,7 +33,7 @@ void findById() {
3333
communityBoardRepository.save(communityBoard);
3434

3535
//when
36-
Optional<CommunityBoard> foundCommunityBoard = communityBoardRepository.findById(communityBoard.getId());
36+
Optional<CommunityBoard> foundCommunityBoard = communityBoardRepository.getCommunityBoardWithId(communityBoard.getId());
3737

3838
//then
3939
assertThat(foundCommunityBoard).isNotNull();
@@ -43,6 +43,27 @@ void findById() {
4343
assertThat(foundCommunityBoard.get().getWriterId()).isEqualTo(communityBoard.getWriterId());
4444
}
4545

46+
@DisplayName("삭제된 커뮤니티 id로 커뮤니티 상세 정보를 조회할 때 예외를 반환할 수 있다. (Repository)")
47+
@Test
48+
void getCommunityBoardByDeletedId() {
49+
//given
50+
CommunityBoard communityBoard = CommunityBoard.builder()
51+
.title("테스트 커뮤니티 게시글 제목")
52+
.content("테스트 커뮤니티 게시글 내용")
53+
.imgUrl("http://community.example.com/123")
54+
.writerId(UUID.randomUUID())
55+
.build();
56+
57+
communityBoardRepository.save(communityBoard);
58+
communityBoardRepository.deleteAllInBatch();
59+
60+
//when
61+
Optional<CommunityBoard> foundCommunityBoard = communityBoardRepository.getCommunityBoardWithId(communityBoard.getId());
62+
63+
//then
64+
assertThat(foundCommunityBoard).isEmpty();
65+
}
66+
4667
@DisplayName("저장된 전체 커뮤니티 게시글을 목록으로 조회할 수 있다. (Repository)")
4768
@Test
4869
void getCommunityBoards() {

src/test/java/com/somemore/community/service/command/CreateCommunityBoardServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void createCommunityWithDto() {
4141
Long communityId = createCommunityBoardService.createCommunityBoard(dto, writerId, imgUrl);
4242

4343
//then
44-
Optional<CommunityBoard> communityBoard = communityBoardRepository.findById(communityId);
44+
Optional<CommunityBoard> communityBoard = communityBoardRepository.getCommunityBoardWithId(communityId);
4545

4646
assertThat(communityBoard).isPresent();
4747
assertThat(communityBoard.get().getId()).isEqualTo(communityId);
@@ -67,7 +67,7 @@ void createCommunityWithoutImgUrl() {
6767
Long communityId = createCommunityBoardService.createCommunityBoard(dto, writerId, imgUrl);
6868

6969
//then
70-
Optional<CommunityBoard> communityBoard = communityBoardRepository.findById(communityId);
70+
Optional<CommunityBoard> communityBoard = communityBoardRepository.getCommunityBoardWithId(communityId);
7171

7272
assertThat(communityBoard).isPresent();
7373
assertThat(communityBoard.get().getId()).isEqualTo(communityId);

0 commit comments

Comments
 (0)