diff --git a/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/BoardContentTest.java b/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/BoardContentTest.java index 9ba14e1b..cc2640fa 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/BoardContentTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/BoardContentTest.java @@ -26,23 +26,23 @@ public void Contents_is_too_long() { //then assertThatThrownBy(() -> new Content(contentsString)) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } @DisplayName("Content 타입에 공백을 저장할 수 없다.") @Test public void Contents_is_Empty() { assertThatThrownBy(() -> new Content("")) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } @DisplayName("Content 타입에 null 은 허용 안된다.") @Test public void Contents_is_Null() { assertThatThrownBy(() -> new Content(null)) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/TitleTest.java b/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/TitleTest.java index f8ed47d8..fb5b4ac0 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/TitleTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/board/domain/valueObject/TitleTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.inhabas.api.auth.domain.error.businessException.InvalidInputException; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -30,23 +31,23 @@ public void Title_is_too_long() { //then assertThatThrownBy(() -> new Title(titleString)) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } @DisplayName("제목은 null 일 수 없습니다.") @Test public void Title_cannot_be_Null() { assertThatThrownBy(() -> new Title(null)) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } @DisplayName("제목은 빈 문자열일 수 없습니다.") @Test public void Title_cannot_be_Blank() { assertThatThrownBy(() -> new Title("")) - .isInstanceOf(InvalidInputException.class) - .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); + .isInstanceOf(InvalidInputException.class) + .hasMessage("입력값이 없거나, 타입이 유효하지 않습니다."); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/board/dto/SaveBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/board/dto/SaveBoardDtoTest.java index 9794dceb..23027651 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/board/dto/SaveBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/board/dto/SaveBoardDtoTest.java @@ -1,14 +1,16 @@ package com.inhabas.api.domain.board.dto; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import com.inhabas.api.domain.board.dto.SaveBoardDto; -import com.inhabas.api.domain.menu.domain.valueObject.MenuId; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Set; + import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; + +import com.inhabas.api.domain.menu.domain.valueObject.MenuId; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -40,7 +42,7 @@ public void SaveBoardDto_is_OK(){ Set> violations = validator.validate(saveBoardDto); // then - assertTrue(violations.isEmpty()); + assertThat(violations).isEmpty(); } @DisplayName("SaveBoardDto의 content 필드가 null 이면 validation 실패") @@ -53,8 +55,10 @@ public void Contents_is_null() { Set> violations = validator.validate(saveBoardDto); // then - assertEquals(1, violations.size()); - assertEquals("본문을 입력하세요.", violations.iterator().next().getMessage()); + assertThat(violations).hasSize(1); + assertThat(violations.iterator().next().getMessage()) + .as("violations 컬렉션의 첫 번째 요소의 메시지가 \"본문을 입력하세요.\"와 동일해야 합니다.") + .isEqualTo("본문을 입력하세요."); } @DisplayName("게시글의 제목이 100자 이상을 넘긴 경우 validation 통과하지 못함.") @@ -70,8 +74,10 @@ public void Title_is_too_long() { Set> violations = validator.validate(saveBoardDto); // then - assertEquals(1, violations.size()); - assertEquals("제목은 최대 100자입니다.", violations.iterator().next().getMessage()); + assertThat(violations).hasSize(1); + assertThat(violations.iterator().next().getMessage()) + .as("violations 컬렉션의 첫 번째 요소의 메시지가 \"제목은 최대 100자입니다.\"와 동일해야 합니다.") + .isEqualTo("제목은 최대 100자입니다."); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/board/dto/UpdateBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/board/dto/UpdateBoardDtoTest.java index 2701d64e..441896f3 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/board/dto/UpdateBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/board/dto/UpdateBoardDtoTest.java @@ -1,12 +1,14 @@ package com.inhabas.api.domain.board.dto; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Set; + import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -38,7 +40,7 @@ public void UpdateBoardDto_is_OK() { Set> violations = validator.validate(updateBoardDto); // then - assertEquals(0, violations.size()); + assertThat(violations).hasSize(0); } @DisplayName("본문에 공백이 입력되었을 경우 테스트를 통과하지 못함.") @@ -51,7 +53,9 @@ public void Contents_is_empty() { Set> violations = validator.validate(updateBoardDto); // then - assertEquals(1, violations.size()); - assertEquals("본문을 입력하세요", violations.iterator().next().getMessage()); + assertThat(violations).hasSize(1); + assertThat(violations.iterator().next().getMessage()) + .as("violations 컬렉션의 첫 번째 요소의 메시지가 \"본문을 입력하세요.\"와 동일해야 합니다.") + .isEqualTo("본문을 입력하세요."); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/board/usecase/BoardServiceTest.java b/resource-server/src/test/java/com/inhabas/api/domain/board/usecase/BoardServiceTest.java index 3dca5bca..514e6432 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/board/usecase/BoardServiceTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/board/usecase/BoardServiceTest.java @@ -1,5 +1,20 @@ package com.inhabas.api.domain.board.usecase; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.*; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.domain.board.BoardCannotModifiableException; import com.inhabas.api.domain.board.domain.NormalBoard; @@ -8,39 +23,22 @@ import com.inhabas.api.domain.board.dto.UpdateBoardDto; import com.inhabas.api.domain.board.repository.NormalBoardRepository; import com.inhabas.api.domain.menu.domain.valueObject.MenuId; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import org.assertj.core.api.Assertions; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(MockitoExtension.class) public class BoardServiceTest { - @InjectMocks - BoardServiceImpl boardService; + @InjectMocks BoardServiceImpl boardService; - @Mock - NormalBoardRepository boardRepository; + @Mock NormalBoardRepository boardRepository; private MockMvc mockMvc; @@ -52,7 +50,7 @@ void setUp() { @DisplayName("게시판을 성공적으로 생성한다.") @Test public void createBoard() { - //given + // given SaveBoardDto saveBoardDto = new SaveBoardDto("title", "content", new MenuId(1)); NormalBoard normalBoard = new NormalBoard("title", "content"); given(boardRepository.save(any())).willReturn(normalBoard); @@ -67,15 +65,27 @@ public void createBoard() { @DisplayName("게시판의 목록을 조회한다.") @Test public void getBoardList() { - //given + // given PageRequest pageable = PageRequest.of(0, 10, Sort.Direction.ASC, "created"); BoardDto boardDto1 = - new BoardDto(1, "title", "content", "mingyeom", - new MenuId(1), LocalDateTime.now(), LocalDateTime.now()); + new BoardDto( + 1, + "title", + "content", + "mingyeom", + new MenuId(1), + LocalDateTime.now(), + LocalDateTime.now()); BoardDto boardDto2 = - new BoardDto(2, "title", "content", "minji", - new MenuId(1), LocalDateTime.now(), LocalDateTime.now()); + new BoardDto( + 2, + "title", + "content", + "minji", + new MenuId(1), + LocalDateTime.now(), + LocalDateTime.now()); List results = new ArrayList<>(); results.add(boardDto1); @@ -84,21 +94,20 @@ public void getBoardList() { given(boardRepository.findAllByMenuId(any(), any())).willReturn(expectedBoardDto); - //when + // when Page returnedBoardList = boardService.getBoardList(new MenuId(1), pageable); - //then + // then then(boardRepository).should(times(1)).findAllByMenuId(any(), any()); - assertThat(returnedBoardList).isEqualTo(expectedBoardDto); + Assertions.assertThat(returnedBoardList).isEqualTo(expectedBoardDto); } @DisplayName("게시글 단일 조회에 성공한다.") @Test public void getDetailBoard() { - //given + // given BoardDto boardDto = - new BoardDto(1, "title", "content", "김민겸", - new MenuId(1), LocalDateTime.now(), null); + new BoardDto(1, "title", "content", "김민겸", new MenuId(1), LocalDateTime.now(), null); given(boardRepository.findDtoById(any())).willReturn(Optional.of(boardDto)); // when @@ -111,7 +120,7 @@ public void getDetailBoard() { @DisplayName("게시글을 성공적으로 삭제한다.") @Test public void deleteBoard() { - //given + // given StudentId writer = new StudentId("12201863"); NormalBoard board = new NormalBoard("Title", "Content").writtenBy(writer); given(boardRepository.findById(anyInt())).willReturn(Optional.of(board)); @@ -127,12 +136,11 @@ public void deleteBoard() { @DisplayName("게시글을 수정한다.") @Test public void updateBoard() { - //given + // given StudentId memberId = new StudentId("12201863"); - NormalBoard savedNormalBoard = new NormalBoard("Origin Title", - "Origin Content").writtenBy(memberId); - NormalBoard updatedNormalBoard = new NormalBoard("Title", "Content").writtenBy( - memberId); + NormalBoard savedNormalBoard = + new NormalBoard("Origin Title", "Origin Content").writtenBy(memberId); + NormalBoard updatedNormalBoard = new NormalBoard("Title", "Content").writtenBy(memberId); given(boardRepository.findById(anyInt())).willReturn(Optional.of(savedNormalBoard)); given(boardRepository.save(any())).willReturn(updatedNormalBoard); @@ -149,28 +157,31 @@ public void updateBoard() { @DisplayName("작성자가 아니면 게시글 수정에 실패한다.") @Test public void failToUpdateBoard() { - //given + // given StudentId badUser = new StudentId("44444444"); StudentId originWriter = new StudentId("12201863"); NormalBoard board = new NormalBoard("Title", "Content").writtenBy(originWriter); given(boardRepository.findById(anyInt())).willReturn(Optional.of(board)); // when - Assertions.assertThrows(BoardCannotModifiableException.class, - () -> boardService.update(badUser, new UpdateBoardDto(1, "수정된 제목", "수정된 내용"))); + Assertions.assertThatThrownBy( + () -> boardService.update(badUser, new UpdateBoardDto(1, "수정된 제목", "수정된 내용"))) + .isInstanceOf(BoardCannotModifiableException.class) + .hasMessage("다른 작성자가 작성한 글은 수정할 수 없습니다!"); } @DisplayName("작성자가 아니면 게시글 삭제에 실패한다.") @Test public void failToDeleteBoard() { - //given + // given StudentId badUser = new StudentId("44444444"); StudentId originWriter = new StudentId("12201863"); NormalBoard board = new NormalBoard("Title", "Content").writtenBy(originWriter); given(boardRepository.findById(anyInt())).willReturn(Optional.of(board)); // when - Assertions.assertThrows(BoardCannotModifiableException.class, - () -> boardService.delete(badUser, 1)); + Assertions.assertThatThrownBy(() -> boardService.delete(badUser, 1)) + .isInstanceOf(BoardCannotModifiableException.class) + .hasMessage("다른 작성자가 작성한 글은 수정할 수 없습니다!"); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetApplicationProcessorTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetApplicationProcessorTest.java index c6bc9950..262356e3 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetApplicationProcessorTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetApplicationProcessorTest.java @@ -1,12 +1,16 @@ package com.inhabas.api.domain.budget.usecase; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import java.time.LocalDateTime; +import java.util.Optional; + +import org.springframework.test.util.ReflectionTestUtils; + import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.domain.budget.domain.BudgetHistory; import com.inhabas.api.domain.budget.domain.BudgetSupportApplication; @@ -15,154 +19,158 @@ import com.inhabas.api.domain.budget.dto.BudgetApplicationStatusChangeRequest; import com.inhabas.api.domain.budget.repository.BudgetApplicationRepository; import com.inhabas.api.domain.budget.repository.BudgetHistoryRepository; -import java.time.LocalDateTime; -import java.util.Optional; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import org.assertj.core.api.Assertions; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.test.util.ReflectionTestUtils; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(MockitoExtension.class) public class BudgetApplicationProcessorTest { - @InjectMocks - private BudgetApplicationProcessorImpl processor; + @InjectMocks private BudgetApplicationProcessorImpl processor; - @Mock - private BudgetApplicationRepository applicationRepository; - @Mock - private BudgetHistoryRepository historyRepository; + @Mock private BudgetApplicationRepository applicationRepository; + @Mock private BudgetHistoryRepository historyRepository; @DisplayName("대기중인 요청을 승인한다.") @Test public void waitingToApproveTest() { - //given - BudgetSupportApplication application = BudgetSupportApplication.builder() - .title("title") - .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) - .details("details") - .outcome(10000) - .applicationWriter(new StudentId("12171652")) - .account("기업 1234 홍길동") - .build(); + // given + BudgetSupportApplication application = + BudgetSupportApplication.builder() + .title("title") + .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) + .details("details") + .outcome(10000) + .applicationWriter(new StudentId("12171652")) + .account("기업 1234 홍길동") + .build(); given(applicationRepository.findById(anyInt())).willReturn(Optional.of(application)); - //when + // when BudgetApplicationStatusChangeRequest request = - new BudgetApplicationStatusChangeRequest("APPROVED", null); + new BudgetApplicationStatusChangeRequest("APPROVED", null); processor.process(1, request, new StudentId("18165249")); - //then + // then then(applicationRepository).should(times(1)).findById(anyInt()); - ApplicationStatus status = (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); - assertThat(status).isEqualTo(ApplicationStatus.APPROVED); + ApplicationStatus status = + (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); + Assertions.assertThat(status).isEqualTo(ApplicationStatus.APPROVED); } @DisplayName("대기중인 요청을 거절한다.") @Test public void waitingToDenyTest() { - //given - BudgetSupportApplication application = BudgetSupportApplication.builder() - .title("title") - .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) - .details("details") - .outcome(10000) - .applicationWriter(new StudentId("12171652")) - .account("기업 1234 홍길동") - .build(); + // given + BudgetSupportApplication application = + BudgetSupportApplication.builder() + .title("title") + .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) + .details("details") + .outcome(10000) + .applicationWriter(new StudentId("12171652")) + .account("기업 1234 홍길동") + .build(); given(applicationRepository.findById(anyInt())).willReturn(Optional.of(application)); - //when + // when BudgetApplicationStatusChangeRequest request = - new BudgetApplicationStatusChangeRequest("DENIED", "중복 요청"); + new BudgetApplicationStatusChangeRequest("DENIED", "중복 요청"); processor.process(1, request, new StudentId("18165249")); - //then + // then then(applicationRepository).should(times(1)).findById(anyInt()); - ApplicationStatus status = (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); - assertThat(status).isEqualTo(ApplicationStatus.DENIED); + ApplicationStatus status = + (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); + Assertions.assertThat(status).isEqualTo(ApplicationStatus.DENIED); } @DisplayName("대기중인 요청을 거절할 때, 거절 사유는 필수이다.") @Test public void rejectReasonIsNecessaryToDenyTest() { - //given - BudgetSupportApplication application = BudgetSupportApplication.builder() - .title("title") - .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) - .details("details") - .outcome(10000) - .applicationWriter(new StudentId("12171652")) - .account("기업 1234 홍길동") - .build(); + // given + BudgetSupportApplication application = + BudgetSupportApplication.builder() + .title("title") + .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) + .details("details") + .outcome(10000) + .applicationWriter(new StudentId("12171652")) + .account("기업 1234 홍길동") + .build(); given(applicationRepository.findById(anyInt())).willReturn(Optional.of(application)); - //when + // when BudgetApplicationStatusChangeRequest request = - new BudgetApplicationStatusChangeRequest("DENIED", null); + new BudgetApplicationStatusChangeRequest("DENIED", null); - //then - Assertions.assertThrows(IllegalArgumentException.class, - () -> processor.process(1, request, new StudentId("18165249"))); + // then + Assertions.assertThatThrownBy(() -> processor.process(1, request, new StudentId("18165249"))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); then(applicationRepository).should(times(1)).findById(anyInt()); } - @DisplayName("대기중인 요청을 완료처리한다.") @Test public void waitingToProcessTest() { - //given - BudgetSupportApplication application = BudgetSupportApplication.builder() - .title("title") - .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) - .details("details") - .outcome(10000) - .applicationWriter(new StudentId("12171652")) - .account("기업 1234 홍길동") - .build(); + // given + BudgetSupportApplication application = + BudgetSupportApplication.builder() + .title("title") + .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) + .details("details") + .outcome(10000) + .applicationWriter(new StudentId("12171652")) + .account("기업 1234 홍길동") + .build(); given(applicationRepository.findById(anyInt())).willReturn(Optional.of(application)); given(historyRepository.save(any(BudgetHistory.class))).willReturn(null); - //when + // when BudgetApplicationStatusChangeRequest request = - new BudgetApplicationStatusChangeRequest("PROCESSED", null); + new BudgetApplicationStatusChangeRequest("PROCESSED", null); processor.process(1, request, new StudentId("18165249")); - //then + // then then(applicationRepository).should(times(1)).findById(anyInt()); then(historyRepository).should(times(1)).save(any(BudgetHistory.class)); - ApplicationStatus status = (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); - assertThat(status).isEqualTo(ApplicationStatus.PROCESSED); + ApplicationStatus status = + (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); + Assertions.assertThat(status).isEqualTo(ApplicationStatus.PROCESSED); } @DisplayName("거절했던 신청이 수정된 뒤에 승인한다.") @Test public void deniedToApprovedTest() { - //given - BudgetSupportApplication application = BudgetSupportApplication.builder() - .title("title") - .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) - .details("details") - .outcome(10000) - .applicationWriter(new StudentId("12171652")) - .account("기업 1234 홍길동") - .build(); + // given + BudgetSupportApplication application = + BudgetSupportApplication.builder() + .title("title") + .dateUsed(LocalDateTime.of(2020, 1, 1, 1, 1, 1)) + .details("details") + .outcome(10000) + .applicationWriter(new StudentId("12171652")) + .account("기업 1234 홍길동") + .build(); ReflectionTestUtils.setField(application, "status", ApplicationStatus.DENIED); ReflectionTestUtils.setField(application, "rejectReason", new RejectReason("계좌번호 미기재")); given(applicationRepository.findById(anyInt())).willReturn(Optional.of(application)); - //when + // when BudgetApplicationStatusChangeRequest request = - new BudgetApplicationStatusChangeRequest("APPROVED", null); + new BudgetApplicationStatusChangeRequest("APPROVED", null); processor.process(1, request, new StudentId("18165249")); - //then + // then then(applicationRepository).should(times(1)).findById(anyInt()); - ApplicationStatus status = (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); - assertThat(status).isEqualTo(ApplicationStatus.APPROVED); + ApplicationStatus status = + (ApplicationStatus) ReflectionTestUtils.getField(application, "status"); + Assertions.assertThat(status).isEqualTo(ApplicationStatus.APPROVED); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetHistoryServiceTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetHistoryServiceTest.java index 8c24d384..c62d0f40 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetHistoryServiceTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/usecase/BudgetHistoryServiceTest.java @@ -1,84 +1,91 @@ package com.inhabas.api.domain.budget.usecase; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.time.LocalDateTime; +import java.util.Optional; + +import org.springframework.data.domain.Pageable; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.test.util.ReflectionTestUtils; + import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; -import com.inhabas.api.domain.budget.HistoryCannotModifiableException; import com.inhabas.api.domain.budget.BudgetHistoryNotFoundException; +import com.inhabas.api.domain.budget.HistoryCannotModifiableException; import com.inhabas.api.domain.budget.domain.BudgetHistory; import com.inhabas.api.domain.budget.dto.BudgetHistoryCreateForm; import com.inhabas.api.domain.budget.dto.BudgetHistoryDetailDto; import com.inhabas.api.domain.budget.dto.BudgetHistoryModifyForm; import com.inhabas.api.domain.budget.repository.BudgetHistoryRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import org.assertj.core.api.Assertions; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Pageable; -import org.springframework.security.access.AccessDeniedException; -import org.springframework.test.util.ReflectionTestUtils; - -import java.time.LocalDateTime; -import java.util.Optional; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(MockitoExtension.class) public class BudgetHistoryServiceTest { - @InjectMocks - private BudgetHistoryServiceImpl budgetHistoryService; + @InjectMocks private BudgetHistoryServiceImpl budgetHistoryService; - @Mock - private BudgetHistoryRepository repository; + @Mock private BudgetHistoryRepository repository; @DisplayName("총무가 회계내역을 추가한다.") @Test public void createBudgetHistoryTest() { - //given - BudgetHistoryCreateForm form = new BudgetHistoryCreateForm( - LocalDateTime.of(2000, 1, 1, 1, 1, 1), - "서버운영비", "aws 작년 서버비용", "12345678", 0, 500000); + // given + BudgetHistoryCreateForm form = + new BudgetHistoryCreateForm( + LocalDateTime.of(2000, 1, 1, 1, 1, 1), "서버운영비", "aws 작년 서버비용", "12345678", 0, 500000); StudentId cfo = new StudentId("12171652"); given(repository.save(any(BudgetHistory.class))).willReturn(null); - //when + // when budgetHistoryService.createNewHistory(form, cfo); - //then + // then then(repository).should(times(1)).save(any(BudgetHistory.class)); } @DisplayName("총무가 회계내역을 수정한다.") @Test public void modifyBudgetHistoryTest() { - //when + // when StudentId CFO = new StudentId("12171652"); - BudgetHistory history = BudgetHistory.builder() - .title("서버 운영비") - .details("작년 aws 운영 비용") - .income(0) - .outcome(500000) - .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) - .personReceived(new StudentId("10982942")) - .personInCharge(CFO) - .build(); + BudgetHistory history = + BudgetHistory.builder() + .title("서버 운영비") + .details("작년 aws 운영 비용") + .income(0) + .outcome(500000) + .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) + .personReceived(new StudentId("10982942")) + .personInCharge(CFO) + .build(); ReflectionTestUtils.setField(history, "id", 1); given(repository.findById(any())).willReturn(Optional.of(history)); - //when - BudgetHistoryModifyForm form = new BudgetHistoryModifyForm( - LocalDateTime.of(2000, 1, 1, 1, 1, 1), - "서버운영비", "aws 작년 서버비용", "12345678", 0, 500000, 1); + // when + BudgetHistoryModifyForm form = + new BudgetHistoryModifyForm( + LocalDateTime.of(2000, 1, 1, 1, 1, 1), + "서버운영비", + "aws 작년 서버비용", + "12345678", + 0, + 500000, + 1); budgetHistoryService.modifyHistory(form, CFO); - //then + // then then(repository).should(times(1)).findById(any()); then(repository).should(times(1)).save(any(BudgetHistory.class)); } @@ -86,65 +93,84 @@ public void modifyBudgetHistoryTest() { @DisplayName("총무는 이전의 다른 총무가 작성한 내역을 수정할 수 없다.") @Test public void cannotModifyBudgetHistoryOfOtherCFO() { - //given + // given StudentId previousCFO = new StudentId("12171652"); StudentId currentCFO = new StudentId("99999999"); - BudgetHistory history = BudgetHistory.builder() - .title("서버 운영비") - .details("작년 aws 운영 비용") - .income(0) - .outcome(500000) - .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) - .personReceived(new StudentId("10982942")) - .personInCharge(previousCFO) - .build(); + BudgetHistory history = + BudgetHistory.builder() + .title("서버 운영비") + .details("작년 aws 운영 비용") + .income(0) + .outcome(500000) + .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) + .personReceived(new StudentId("10982942")) + .personInCharge(previousCFO) + .build(); ReflectionTestUtils.setField(history, "id", 1); given(repository.findById(any())).willReturn(Optional.of(history)); - //when - BudgetHistoryModifyForm form = new BudgetHistoryModifyForm( - LocalDateTime.of(2000, 1, 1, 1, 1, 1), - "서버운영비", "aws 작년 서버비용", "12345678", 0, 500000, 1); - Assertions.assertThrows(AccessDeniedException.class, - () -> budgetHistoryService.modifyHistory(form, currentCFO)); + // when + BudgetHistoryModifyForm form = + new BudgetHistoryModifyForm( + LocalDateTime.of(2000, 1, 1, 1, 1, 1), + "서버운영비", + "aws 작년 서버비용", + "12345678", + 0, + 500000, + 1); + + Assertions.assertThatThrownBy(() -> budgetHistoryService.modifyHistory(form, currentCFO)) + .isInstanceOf(AccessDeniedException.class) + .hasMessage("다른 담당자가 작성한 내역은 수정할 수 없습니다!"); } @DisplayName("수정 시도할 때 히스토리 내역이 존재하지 않으면 오류를 던진다.") @Test public void raiseNotFoundExceptionWhenModifyingTest() { - //given + // given given(repository.findById(any())).willReturn(Optional.empty()); - //when - BudgetHistoryModifyForm form = new BudgetHistoryModifyForm( - LocalDateTime.of(2000, 1, 1, 1, 1, 1), - "서버운영비", "aws 작년 서버비용", "12345678", 0, 500000, 1); - Assertions.assertThrows(BudgetHistoryNotFoundException.class, - () -> budgetHistoryService.modifyHistory(form, new StudentId("12171652"))); + // when + BudgetHistoryModifyForm form = + new BudgetHistoryModifyForm( + LocalDateTime.of(2000, 1, 1, 1, 1, 1), + "서버운영비", + "aws 작년 서버비용", + "12345678", + 0, + 500000, + 1); + + Assertions.assertThatThrownBy( + () -> budgetHistoryService.modifyHistory(form, new StudentId("12171652"))) + .isInstanceOf(BudgetHistoryNotFoundException.class) + .hasMessage("cannot find such budget history!"); } @DisplayName("총무가 회계 내역을 삭제한다.") @Test public void deleteBudgetHistoryTest() { - //given + // given StudentId CFO = new StudentId("12171652"); Integer historyId = 1; - BudgetHistory history = BudgetHistory.builder() - .title("서버 운영비") - .details("작년 aws 운영 비용") - .income(0) - .outcome(500000) - .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) - .personReceived(new StudentId("10982942")) - .personInCharge(CFO) - .build(); + BudgetHistory history = + BudgetHistory.builder() + .title("서버 운영비") + .details("작년 aws 운영 비용") + .income(0) + .outcome(500000) + .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) + .personReceived(new StudentId("10982942")) + .personInCharge(CFO) + .build(); ReflectionTestUtils.setField(history, "id", historyId); given(repository.findById(any())).willReturn(Optional.of(history)); - //when + // when budgetHistoryService.deleteHistory(historyId, CFO); - //then + // then then(repository).should(times(1)).findById(anyInt()); then(repository).should(times(1)).deleteById(anyInt()); } @@ -152,83 +178,88 @@ public void deleteBudgetHistoryTest() { @DisplayName("이전의 다른 담당자가 작성했던 기록은 삭제할 수 없다.") @Test public void cannotDeleteBudgetHistoryTest() { - //given + // given StudentId previousCFO = new StudentId("12171652"); StudentId currentCFO = new StudentId("99999999"); Integer historyId = 1; - BudgetHistory history = BudgetHistory.builder() - .title("서버 운영비") - .details("작년 aws 운영 비용") - .income(0) - .outcome(500000) - .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) - .personReceived(new StudentId("10982942")) - .personInCharge(previousCFO) - .build(); + BudgetHistory history = + BudgetHistory.builder() + .title("서버 운영비") + .details("작년 aws 운영 비용") + .income(0) + .outcome(500000) + .dateUsed(LocalDateTime.of(2000, 1, 1, 1, 1, 1)) + .personReceived(new StudentId("10982942")) + .personInCharge(previousCFO) + .build(); ReflectionTestUtils.setField(history, "id", historyId); given(repository.findById(any())).willReturn(Optional.of(history)); - //when - Assertions.assertThrows(HistoryCannotModifiableException.class, - () -> budgetHistoryService.deleteHistory(historyId, currentCFO)); + // when + Assertions.assertThatThrownBy(() -> budgetHistoryService.deleteHistory(historyId, currentCFO)) + .isInstanceOf(HistoryCannotModifiableException.class) + .hasMessage("다른 담당자가 작성한 내역은 수정할 수 없습니다!"); - //then + // then then(repository).should(times(1)).findById(anyInt()); } @DisplayName("존재하지 않는 기록을 삭제하려고 하면 예외를 던진다.") @Test public void raiseNotFoundExceptionWhenDeletingTest() { - //given + // given given(repository.findById(any())).willReturn(Optional.empty()); - //when - Assertions.assertThrows(BudgetHistoryNotFoundException.class, - () -> budgetHistoryService.deleteHistory(1, new StudentId("12171652"))); + // when + Assertions.assertThatThrownBy( + () -> budgetHistoryService.deleteHistory(1, new StudentId("12171652"))) + .isInstanceOf(BudgetHistoryNotFoundException.class) + .hasMessage("cannot find such budget history!"); - //then + // then then(repository).should(times(1)).findById(anyInt()); } @DisplayName("회계내역을 한 페이지를 출력한다.") @Test public void getListOfBudgetHistoryTest() { - //given + // given given(repository.search(any(), any())).willReturn(null); - //when + // when budgetHistoryService.searchHistoryList(null, Pageable.ofSize(15)); - //then + // then then(repository).should(times(1)).search(any(), any()); } @DisplayName("회계내역을 id 로 조회한다.") @Test public void getOneBudgetHistoryTest() { - //given + // given given(repository.findDtoById(anyInt())) - .willReturn(Optional.of(new BudgetHistoryDetailDto( - null, null, null, null, null, null, - null, null, null, null, - null, null, null))); + .willReturn( + Optional.of( + new BudgetHistoryDetailDto( + null, null, null, null, null, null, null, null, null, null, null, null, null))); - //when + // when budgetHistoryService.getHistory(2); - //then + // then then(repository).should(times(1)).findDtoById(anyInt()); } @DisplayName("id 에 해당하는 회계내역이 없는 경우, NotFoundException을 던진다.") @Test public void cannotFindBudgetHistoryFindById() { - //given + // given given(repository.findDtoById(anyInt())).willReturn(Optional.empty()); - //when - Assertions.assertThrows(BudgetHistoryNotFoundException.class, - () -> budgetHistoryService.getHistory(2)); + // when + Assertions.assertThatThrownBy(() -> budgetHistoryService.getHistory(2)) + .isInstanceOf(BudgetHistoryNotFoundException.class) + .hasMessage("cannot find such budget history!"); then(repository).should(times(1)).findDtoById(anyInt()); } @@ -236,13 +267,13 @@ public void cannotFindBudgetHistoryFindById() { @DisplayName("기록이 존재하는 년도를 모두 가져온다.") @Test public void fetchAllYearOfHistoryTest() { - //given + // given given(repository.findAllYear()).willReturn(null); - //when + // when budgetHistoryService.getAllYearOfHistory(); - //then + // then then(repository).should(times(1)).findAllYear(); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/AccountTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/AccountTest.java index 9b25952a..ce586c5f 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/AccountTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/AccountTest.java @@ -1,12 +1,13 @@ package com.inhabas.api.domain.budget.valueObject; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import com.inhabas.api.domain.budget.domain.valueObject.Account; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class AccountTest { @DisplayName("Account 타입에 문자열을 저장한다.") @@ -29,8 +30,9 @@ public void tooLongAccountTest() { String accountString = "지금이문장은10자임".repeat(10); //then - assertThrows(IllegalArgumentException.class, - () -> new Account(accountString)); + assertThatThrownBy(() -> new Account(accountString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("계좌정보는 null 이어도 됩니다.") diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/ApplicantAccountTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/ApplicantAccountTest.java index 67abb45e..7c633d5e 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/ApplicantAccountTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/ApplicantAccountTest.java @@ -1,12 +1,13 @@ package com.inhabas.api.domain.budget.valueObject; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import com.inhabas.api.domain.budget.domain.valueObject.ApplicantAccount; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class ApplicantAccountTest { @DisplayName("Account 타입에 문자열을 저장한다.") @@ -29,21 +30,24 @@ public void tooLongApplicantAccountTest() { String accountString = "지금이문장은10자임".repeat(10); //then - assertThrows(IllegalArgumentException.class, - () -> new ApplicantAccount(accountString)); + assertThatThrownBy(() -> new ApplicantAccount(accountString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("계좌정보는 null 일 수 없습니다.") @Test public void applicantAccountCannotBeNull() { - assertThrows(IllegalArgumentException.class, - () -> new ApplicantAccount(null)); + assertThatThrownBy(() -> new ApplicantAccount(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("계좌정보는 빈 문자열일 수 없습니다.") @Test public void applicantAccountCannotBeNullBlank() { - assertThrows(IllegalArgumentException.class, - () -> new ApplicantAccount("\t")); + assertThatThrownBy(() -> new ApplicantAccount("\t")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/DetailTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/DetailTest.java index 73d0b303..ff6ada45 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/DetailTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/DetailTest.java @@ -1,12 +1,11 @@ package com.inhabas.api.domain.budget.valueObject; import com.inhabas.api.domain.budget.domain.valueObject.Details; +import org.assertj.core.api.Assertions; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class DetailTest { @DisplayName("Details 타입에 문자열을 저장한다.") @@ -19,7 +18,7 @@ public void normalDetailsTest() { Details details = new Details(detailsString); //then - assertThat(details.getValue()).isEqualTo("예산 내역 상세 내용입니다."); + Assertions.assertThat(details.getValue()).isEqualTo("예산 내역 상세 내용입니다."); } @DisplayName("Details 타입에 너무 긴 문자열을 저장한다. 300자 이상") @@ -29,21 +28,26 @@ public void tooLongDetailsTest() { String detailsString = "지금이문장은10자임".repeat(30); //then - assertThrows(IllegalArgumentException.class, - () -> new Details(detailsString)); + Assertions.assertThatThrownBy(() -> new Details(detailsString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("예산 내역 제목은 null 일 수 없습니다.") @Test public void detailsCannotBeNullTest() { - assertThrows(IllegalArgumentException.class, - () -> new Details(null)); + + Assertions.assertThatThrownBy(() -> new Details(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("예산 상세내역 은 빈 문자열일 수 없습니다.") @Test public void detailsCannotBeBlankTest() { - assertThrows(IllegalArgumentException.class, - () -> new Details("\t")); + + Assertions.assertThatThrownBy(() -> new Details("\t")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/PriceTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/PriceTest.java index 0603be24..3981fa69 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/PriceTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/PriceTest.java @@ -1,12 +1,11 @@ package com.inhabas.api.domain.budget.valueObject; import com.inhabas.api.domain.budget.domain.valueObject.Price; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class PriceTest { @DisplayName("가격을 생성한다.") @@ -19,7 +18,7 @@ public void normalPriceTest() { Price priceObj = new Price(price); //then - assertThat(priceObj.getValue()).isEqualTo(10000); + Assertions.assertThat(priceObj.getValue()).isEqualTo(10000); } @DisplayName("가격은 0 이 될 수 있다.") @@ -32,7 +31,7 @@ public void zeroPriceTest() { Price priceObj = new Price(price); //then - assertThat(priceObj.getValue()).isEqualTo(0); + Assertions.assertThat(priceObj.getValue()).isEqualTo(0); } @DisplayName("음수 가격은 생성될 수 없다.") @@ -42,7 +41,8 @@ public void minusPriceCannotBeProducedTest() { Integer minusPrice = -10000; //when - Assertions.assertThrows(IllegalArgumentException.class, - ()->new Price(minusPrice)); + Assertions.assertThatThrownBy(()->new Price(minusPrice)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/RejectReasonTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/RejectReasonTest.java index 2a62bd39..33c82d1c 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/RejectReasonTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/RejectReasonTest.java @@ -1,11 +1,10 @@ package com.inhabas.api.domain.budget.valueObject; +import com.inhabas.api.domain.budget.domain.valueObject.Price; import com.inhabas.api.domain.budget.domain.valueObject.RejectReason; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.assertj.core.api.Assertions; public class RejectReasonTest { @@ -19,7 +18,7 @@ public void normalRejectReasonTest() { RejectReason rejectReason = new RejectReason(rejectString); //then - assertThat(rejectReason.getValue()).isEqualTo("거부이유입니다."); + Assertions.assertThat(rejectReason.getValue()).isEqualTo("거부이유입니다."); } @DisplayName("RejectReason 타입에 너무 긴 문자열을 저장한다. 200자 이상") @@ -29,21 +28,26 @@ public void tooLongRejectReasonTest() { String rejectString = "지금이문장은10자임".repeat(20); //then - assertThrows(IllegalArgumentException.class, - () -> new RejectReason(rejectString)); + Assertions.assertThatThrownBy(() -> new RejectReason(rejectString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("거부이유는 null 일 수 없습니다.") @Test public void rejectReasonCannotBeNullTest() { - assertThrows(IllegalArgumentException.class, - () -> new RejectReason(null)); + + Assertions.assertThatThrownBy(() -> new RejectReason(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("거부이유는 빈 문자열일 수 없습니다.") @Test public void rejectReasonCannotBeBlankTest() { - assertThrows(IllegalArgumentException.class, - () -> new RejectReason("\t")); + + Assertions.assertThatThrownBy(() -> new RejectReason("\t")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/TitleTest.java b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/TitleTest.java index 49aaa045..5f98166a 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/TitleTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/budget/valueObject/TitleTest.java @@ -1,12 +1,11 @@ package com.inhabas.api.domain.budget.valueObject; import com.inhabas.api.domain.budget.domain.valueObject.Title; +import org.assertj.core.api.Assertions; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TitleTest { @DisplayName("Title 타입에 제목을 저장한다.") @@ -19,7 +18,7 @@ public void Title_is_OK() { Title title = new Title(titleString); //then - assertThat(title.getValue()).isEqualTo("예산 내역 제목입니다."); + Assertions.assertThat(title.getValue()).isEqualTo("예산 내역 제목입니다."); } @DisplayName("Title 타입에 너무 긴 제목을 저장한다. 100자 이상") @@ -29,21 +28,24 @@ public void Title_is_too_long() { String titleString = "지금이문장은10자임".repeat(10); //then - assertThrows(IllegalArgumentException.class, - () -> new Title(titleString)); + Assertions.assertThatThrownBy(() -> new Title(titleString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("예산 내역 제목은 null 일 수 없습니다.") @Test public void Title_cannot_be_Null() { - assertThrows(IllegalArgumentException.class, - () -> new Title(null)); + Assertions.assertThatThrownBy(() -> new Title(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("예산 내역 제목은 빈 문자열일 수 없습니다.") @Test public void Title_cannot_be_Blank() { - assertThrows(IllegalArgumentException.class, - () -> new Title("\t")); + Assertions.assertThatThrownBy(() -> new Title("\t")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubHistoryDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubHistoryDtoTest.java index 651c2d27..e32c036f 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubHistoryDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubHistoryDtoTest.java @@ -43,7 +43,7 @@ void NotNull_Test() { Set> violations = validator.validate(saveClubHistoryDto); //then - Assertions.assertThat(violations.size()).isEqualTo(1); + Assertions.assertThat(violations).hasSize(1); } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/club/usecase/ClubHistoryServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/club/usecase/ClubHistoryServiceImplTest.java index ade445e2..9ee0b1b7 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/club/usecase/ClubHistoryServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/club/usecase/ClubHistoryServiceImplTest.java @@ -20,13 +20,12 @@ import org.springframework.data.domain.Sort; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Transactional; +import org.assertj.core.api.Assertions; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -66,7 +65,7 @@ void writeClubHistory_Success() { // then then(memberRepository).should().findById(memberId); then(clubHistoryRepository).should().save(any(ClubHistory.class)); - assertThat(resultId).isEqualTo(1L); + Assertions.assertThat(resultId).isEqualTo(1L); } @DisplayName("동아리 연혁 생성 작성자가 존재하지 않을 시 Member nof found") @@ -78,7 +77,7 @@ void writeClubHistory_Member_Not_Found() { given(memberRepository.findById(any())).willReturn(Optional.empty()); // then - assertThatThrownBy(() -> clubHistoryService.writeClubHistory(1L, saveClubHistoryDto)) + Assertions.assertThatThrownBy(() -> clubHistoryService.writeClubHistory(1L, saveClubHistoryDto)) .isInstanceOf(MemberNotFoundException.class) .hasMessage("존재 하지 않는 유저입니다."); @@ -101,7 +100,7 @@ void findClubHistory_Success() { //then then(clubHistoryRepository).should().findById(any()); - assertThat(clubHistoryDto).as("clubHistoryDto's title and content are equal to clubHistory") + Assertions.assertThat(clubHistoryDto).as("클럽 히스토리Dto의 title과 content는 클럽 히스토리와 동일해야 합니다.") .extracting("title", "content") .containsExactly(clubHistory.getTitle().getValue(), clubHistory.getContent().getValue()); @@ -114,7 +113,7 @@ void findClubHistory_Not_Found() { given(clubHistoryRepository.findById(any())).willReturn(Optional.empty()); //then - assertThatThrownBy(() -> clubHistoryService.findClubHistory(any())) + Assertions.assertThatThrownBy(() -> clubHistoryService.findClubHistory(any())) .isInstanceOf(NotFoundException.class) .hasMessage("데이터가 존재하지 않습니다."); @@ -140,7 +139,7 @@ void getClubHistories_Success() { //then then(clubHistoryRepository).should().findAll(sort); - assertThat(clubHistoryDtoList) + Assertions.assertThat(clubHistoryDtoList) .hasSize(1) .extracting("title", "content") .contains(tuple(clubHistory.getTitle().getValue(), clubHistory.getContent().getValue())); diff --git a/resource-server/src/test/java/com/inhabas/api/domain/comment/domain/valueObject/CommentContentTest.java b/resource-server/src/test/java/com/inhabas/api/domain/comment/domain/valueObject/CommentContentTest.java index 47a29703..3776ac99 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/comment/domain/valueObject/CommentContentTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/comment/domain/valueObject/CommentContentTest.java @@ -1,10 +1,8 @@ package com.inhabas.api.domain.comment.domain.valueObject; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.assertj.core.api.Assertions; public class CommentContentTest { @@ -18,7 +16,7 @@ public void Contents_is_saved_well() { Contents contents = new Contents(contentsString); //then - assertThat(contents.getValue()).isEqualTo(contentsString); + Assertions.assertThat(contents.getValue()).isEqualTo(contentsString); } @DisplayName("Content 타입에 너무 긴 내용을 입력한다. 500자 이상") @@ -28,24 +26,24 @@ public void Contents_is_too_long() { String contentsString = "지금이문장은10자임".repeat(500); //then - assertThrows(IllegalArgumentException.class, - () -> new Contents(contentsString) - ); + Assertions.assertThatThrownBy(() -> new Contents(contentsString)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("Content 타입에 null 은 안된다.") @Test public void Contents_is_Null() { - assertThrows(IllegalArgumentException.class, - () -> new Contents(null) - ); + Assertions.assertThatThrownBy(() -> new Contents(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } @DisplayName("Content 타입에 공백댓글은 저장할 수 없다.") @Test public void Contents_is_Blank() { - assertThrows(IllegalArgumentException.class, - () -> new Contents(" ") - ); + Assertions.assertThatThrownBy(() -> new Contents(" ")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(null); } }