Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0a580d4
refactor: NoticeFixture -> NoticeTestFixture 이름 변경 및 디렉토리 변경
jj0526 Nov 5, 2025
4c65525
test: CommentTestFixture 추가
jj0526 Nov 5, 2025
facba80
test: 부모 댓글이 없는 공지사항 댓글 작성 테스트 추가
jj0526 Nov 5, 2025
8fc3045
refactor: Notice 생성시 comments 초기화하도록 수정
jj0526 Nov 5, 2025
e222177
refactor: NoticeCommentUsecaseImpl 테스트에서 @Mock -> @InjectMocks 변경
jj0526 Nov 5, 2025
bb68f68
test: 공지사항 댓글 수정 시 작성자와 수정 요청자가 다를 경우 예외 발생 테스트 추가
jj0526 Nov 5, 2025
9924556
test: CommentTestFixture의 createComment 메소드 파라미터에 id 추가
jj0526 Nov 5, 2025
b5cadb9
test: 테스트에서 commentId 상수 분리
jj0526 Nov 11, 2025
85c5431
test: 부모 댓글이 있는 경우 공지사항 댓글 작성 테스트 추가
jj0526 Nov 11, 2025
f8a7347
style: 미사용 코드 정리
jj0526 Nov 11, 2025
a6722a0
test: 게시글 픽스쳐 추가
jj0526 Nov 11, 2025
93260ab
test: 교육 게시글 저장 및 권한 없는 사용자의 게시글 생성 예외 처리 테스트 추가
jj0526 Nov 11, 2025
35c89c4
test: 게시글 픽스쳐 createEducationPost와 createResponseAll추가
jj0526 Nov 11, 2025
e63fb11
test: 파트와 주차 조건으로 게시글 목록 조회 성공 테스트 추가
jj0526 Nov 11, 2025
850be7c
test: PostTestFixture.createEducationPost 파라미터에 User 추가 및 관리자 교육 게시글 …
jj0526 Nov 11, 2025
ad03511
test: 스터디가 없을 시 예외가 발생하는지 검증하는 테스트 추가
jj0526 Nov 11, 2025
6f690e9
test: 본인이 속하지 않은 교육 자료를 검색하면 빈 리스트 반환 검증하는 테스트 추가
jj0526 Nov 11, 2025
2224e67
test: 파일 픽스쳐 추가
jj0526 Nov 11, 2025
c81fb5e
test: 파일이 존재하는 경우 checkFileExistsByPost() 반환이 true인지 검증하는 테스트 추가
jj0526 Nov 11, 2025
3e1fe9a
test: 파일 및 공지사항 테스트 픽스쳐 추가
jj0526 Nov 11, 2025
596883a
test: FileTestFixture.createFile()의 Post 파라미터 제거
jj0526 Nov 11, 2025
81df671
test: 공지사항 수정 테스트 추가 및 공지사항 엔티티 update() 호출 시 수정 여부 검증 추가
jj0526 Nov 11, 2025
f0432d7
test: 유저 픽스처 createAdmin()에 누락된 id 빌더 추가
jj0526 Nov 11, 2025
e15b3ef
style: 불필요한 개행 제거
jj0526 Nov 30, 2025
561e00f
style: 불필요한 verify 구문 제거
jj0526 Nov 30, 2025
08eff0c
test: given 설정 내 실제 메서드 호출 제거
jj0526 Nov 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import leets.weeth.domain.board.application.dto.NoticeDTO;
import leets.weeth.domain.board.application.mapper.NoticeMapper;
import leets.weeth.domain.board.domain.entity.Notice;
import leets.weeth.domain.board.domain.test.fixture.NoticeFixture;
import leets.weeth.domain.board.domain.service.NoticeUpdateService;
import leets.weeth.domain.board.test.fixture.NoticeTestFixture;
import leets.weeth.domain.board.domain.service.NoticeFindService;
import leets.weeth.domain.file.application.dto.request.FileSaveRequest;
import leets.weeth.domain.file.application.mapper.FileMapper;
import leets.weeth.domain.file.domain.entity.File;
import leets.weeth.domain.file.domain.service.FileDeleteService;
import leets.weeth.domain.file.domain.service.FileGetService;
import leets.weeth.domain.file.domain.service.FileSaveService;
import leets.weeth.domain.file.test.fixture.FileTestFixture;
import leets.weeth.domain.user.domain.entity.User;
import leets.weeth.domain.user.domain.entity.enums.Department;
import leets.weeth.domain.user.domain.entity.enums.Position;
import leets.weeth.domain.user.domain.entity.enums.Role;
import org.junit.jupiter.api.Disabled;
import leets.weeth.domain.user.test.fixture.UserTestFixture;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -29,17 +36,18 @@
@ExtendWith(MockitoExtension.class)
class NoticeUsecaseImplTest {

@Mock
private NoticeFindService noticeFindService;
@InjectMocks private NoticeUsecaseImpl noticeUsecase;

@Mock
private FileGetService fileGetService;
@Mock private NoticeFindService noticeFindService;
@Mock private NoticeUpdateService noticeUpdateService;

@InjectMocks
private NoticeUsecaseImpl noticeUsecase;
@Mock private FileSaveService fileSaveService;
@Mock private FileGetService fileGetService;
@Mock private FileDeleteService fileDeleteService;

@Mock private NoticeMapper noticeMapper;
@Mock private FileMapper fileMapper;

@Mock
private NoticeMapper noticeMapper;

@Test
void 공지사항이_최신순으로_정렬되는지() {
Expand All @@ -54,7 +62,7 @@ class NoticeUsecaseImplTest {

List<Notice> notices = new ArrayList<>();
for(int i = 0; i<5; i++){
Notice notice = NoticeFixture.createNotice("공지" + i, user);
Notice notice = NoticeTestFixture.createNotice("공지" + i, user);
ReflectionTestUtils.setField(notice, "id", (long) i + 1);
notices.add(notice);
}
Expand Down Expand Up @@ -98,7 +106,6 @@ class NoticeUsecaseImplTest {
assertThat(noticeResponses.hasNext()).isTrue();

verify(noticeFindService, times(1)).findRecentNotices(pageable);

}

@Test
Expand All @@ -114,12 +121,12 @@ class NoticeUsecaseImplTest {

List<Notice> notices = new ArrayList<>();
for(int i = 0; i<3; i++){
Notice notice = NoticeFixture.createNotice("공지" + i, user);
Notice notice = NoticeTestFixture.createNotice("공지" + i, user);
ReflectionTestUtils.setField(notice, "id", (long) i + 1);
notices.add(notice);
}
for(int i = 3; i<6; i++){
Notice notice = NoticeFixture.createNotice("검색" + i, user);
Notice notice = NoticeTestFixture.createNotice("검색" + i, user);
ReflectionTestUtils.setField(notice, "id", (long) i + 1);
notices.add(notice);
}
Expand Down Expand Up @@ -182,13 +189,60 @@ class NoticeUsecaseImplTest {
verify(noticeFindService, times(1)).search("검색", pageable);
}

@Disabled("TODO: update 기능 테스트 구현 필요")
@Test
void update() {
@DisplayName("공지사항 수정 시 기존 파일 삭제 후 새 파일로 업데이트된다")
void update_replacesOldFilesWithNewFiles() {
// given
Long noticeId = 1L;
Long userId = 1L;

User user = UserTestFixture.createActiveUser1(userId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

유저 Fixture 가져와서 사용해주셨네요 ! 굳👍🏻

Notice notice = NoticeTestFixture.createNotice(noticeId, "기존 제목", user);

File oldFile = FileTestFixture.createFile(1L, "old.pdf", "https://example.com/old.pdf", notice);
List<File> oldFiles = List.of(oldFile);

NoticeDTO.Update dto = new NoticeDTO.Update("수정된 제목", "수정된 내용",
List.of(new FileSaveRequest("new.pdf", "https://example.com/new.pdf")));

File newFile = FileTestFixture.createFile(2L, "new.pdf", "https://example.com/new.pdf", notice);
List<File> newFiles = List.of(newFile);

NoticeDTO.SaveResponse expectedResponse = new NoticeDTO.SaveResponse(noticeId);

given(noticeFindService.find(noticeId)).willReturn(notice);
given(fileGetService.findAllByNotice(noticeId)).willReturn(oldFiles);
given(fileMapper.toFileList(dto.files(), notice)).willReturn(newFiles);
given(noticeMapper.toSaveResponse(notice)).willReturn(expectedResponse);

// when
NoticeDTO.SaveResponse response = noticeUsecase.update(noticeId, dto, userId);

// then
assertThat(response).isEqualTo(expectedResponse);

verify(noticeFindService).find(noticeId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

호출 여부까지는 전부 검증해줄 필요는 없을 것 같아욤

verify(fileGetService).findAllByNotice(noticeId);
verify(fileDeleteService).delete(oldFiles);
verify(fileMapper).toFileList(dto.files(), notice);
verify(fileSaveService).save(newFiles);
verify(noticeUpdateService).update(notice, dto);
}

@Disabled("TODO: delete 기능 테스트 구현 필요")
@Test
void delete() {
@DisplayName("공지사항 엔티티 update() 호출 시 제목과 내용이 변경된다")
void update_updatesTitleAndContent() {
// given
Long userId = 1L;
User user = UserTestFixture.createActiveUser1(userId);
Notice notice = NoticeTestFixture.createNotice(1L, "기존 제목", user);
NoticeDTO.Update dto = new NoticeDTO.Update("수정된 제목", "수정된 내용", List.of());

// when
notice.update(dto);

// then
assertThat(notice.getTitle()).isEqualTo(dto.title());
assertThat(notice.getContent()).isEqualTo(dto.content());
}
}
Copy link
Collaborator

@seokjun01 seokjun01 Nov 11, 2025

Choose a reason for hiding this comment

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

given 단계에서 중복되는 객체설정은 (user, notice) , setUp() 메소드로 뺴놓아도 좋을 것 같아용
지금은 두 번 밖에 없지만! 추후에 검증이 추가된다면 고려해봐도 좋을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

좋은 피드백 감사합니다! 하지만 이 테스트 클래스엔는 setUp()으로 공통 초기화 하는 것이 메소드마다 여러개의 Notice가 필요한지 단일 Notice가 필요한지가 달라서 사용하기에는 부적합한거같습니다!

Loading