Skip to content

Commit

Permalink
[feature/Inhabas#234] service, repository 테스트 구현 완료ㅛ
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 committed Feb 23, 2024
1 parent 51c8209 commit 4effd25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public List<ContestBoardDto> findAllByTypeAndFieldAndSearch(
eqContestType(contestType)
.and(eqContestField(contestFieldId))
.and(
titleLike(search)
.or(contentLike(search))
.or(writerNameLike(search))
.or(associationLike(search))
.or(topicLike(search)));
likeTitle(search)
.or(likeContent(search))
.or(likeWriterName(search))
.or(likeAssociation(search))
.or(likeTopic(search)));

OrderSpecifier<?> orderBy = getOrderBy(sortBy);

Expand Down Expand Up @@ -118,27 +118,23 @@ private BooleanExpression eqContestField(Long contestFieldId) {
return contestBoard.contestField.id.eq(contestFieldId);
}

private BooleanExpression titleLike(String search) {
return hasText(search) ? contestBoard.title.value.containsIgnoreCase(search) : null;
private BooleanExpression likeTitle(String search) {
return contestBoard.title.value.like("%" + search + "%");
}

private BooleanExpression contentLike(String search) {
return hasText(search) ? contestBoard.content.value.containsIgnoreCase(search) : null;
private BooleanExpression likeContent(String search) {
return contestBoard.content.value.like("%" + search + "%");
}

private BooleanExpression writerNameLike(String search) {
return hasText(search) ? contestBoard.writer.name.value.containsIgnoreCase(search) : null;
private BooleanExpression likeWriterName(String search) {
return contestBoard.writer.name.value.like("%" + search + "%");
}

private BooleanExpression associationLike(String search) {
return hasText(search) ? contestBoard.association.value.containsIgnoreCase(search) : null;
private BooleanExpression likeAssociation(String search) {
return contestBoard.association.value.like("%" + search + "%");
}

private BooleanExpression topicLike(String search) {
return hasText(search) ? contestBoard.topic.value.containsIgnoreCase(search) : null;
}

private Boolean hasText(String text) {
return text != null && !text.trim().isEmpty();
private BooleanExpression likeTopic(String search) {
return contestBoard.association.value.like("%" + search + "%");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.inhabas.api.domain.contest.dto.ContestBoardDto;
import com.inhabas.api.domain.contest.dto.SaveContestBoardDto;
import com.inhabas.api.domain.contest.repository.ContestBoardRepository;
import com.inhabas.api.domain.contest.repository.ContestFieldRepository;
import com.inhabas.api.domain.file.dto.FileDownloadDto;
import com.inhabas.api.domain.file.usecase.S3Service;
import com.inhabas.api.domain.member.domain.entity.MemberTest;
Expand All @@ -49,6 +50,8 @@ public class ContestBoardServiceImplTest {

@Mock private ContestBoardRepository contestBoardRepository;

@Mock private ContestFieldRepository contestFieldRepository;

@Mock private MemberRepository memberRepository;

@Mock private MenuRepository menuRepository;
Expand Down Expand Up @@ -125,9 +128,12 @@ void getContestBoard() {
void writeContestBoard() {
// given
Member member = MemberTest.chiefMember();

ContestField contestField = ContestField.builder().name("빅데이터").build();
ReflectionTestUtils.setField(contestField, "id", 1L);
SaveContestBoardDto saveContestBoardDto =
SaveContestBoardDto.builder()
.contestFieldId(1L)
.contestFieldId(contestField.getId())
.title("테스트 제목")
.content("테스트 내용")
.association("(주) 아이바스")
Expand All @@ -137,7 +143,6 @@ void writeContestBoard() {
.files(null)
.build();

ContestField contestField = ContestField.builder().name("빅데이터").build();
Menu menu = getContestMenu(getContestMenuGroup());
ContestBoard contestBoard =
ContestBoard.builder()
Expand All @@ -154,6 +159,8 @@ void writeContestBoard() {

given(memberRepository.findById(any())).willReturn(Optional.of(member));
given(contestBoardRepository.save(any())).willReturn(contestBoard);
given(contestFieldRepository.findById(contestField.getId()))
.willReturn(Optional.of(contestField));
given(menuRepository.findById(anyInt())).willReturn(Optional.of(menu));

// when
Expand Down

0 comments on commit 4effd25

Please sign in to comment.