Skip to content

Commit

Permalink
refactor: 예외명 명확하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
donghoony committed Aug 11, 2024
1 parent 6241cdc commit 93aec4d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import reviewme.global.exception.NotFoundException;

@Slf4j
public class OptionGroupNotFoundException extends NotFoundException {
public class MissingOptionGroupForQuestionException extends NotFoundException {

public OptionGroupNotFoundException(long questionId) {
public MissingOptionGroupForQuestionException(long questionId) {
super("질문에 해당하는 체크박스 그룹을 찾을 수 없어요.");
log.info("OptionGroup not found for questionId: {}", questionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.exception.OptionGroupNotFoundException;
import reviewme.question.domain.exception.MissingOptionGroupForQuestionException;

public interface OptionGroupRepository extends JpaRepository<OptionGroup, Long> {

Optional<OptionGroup> findByQuestionId(long questionId);

default OptionGroup getByQuestionId(long questionId) {
return findByQuestionId(questionId)
.orElseThrow(() -> new OptionGroupNotFoundException(questionId));
.orElseThrow(() -> new MissingOptionGroupForQuestionException(questionId));
}
}
4 changes: 2 additions & 2 deletions backend/src/main/java/reviewme/review/domain/TextAnswers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import reviewme.review.domain.exception.TextAnswerNotFoundException;
import reviewme.review.domain.exception.MissingTextAnswerForQuestionException;

@Slf4j
public class TextAnswers {
Expand All @@ -19,7 +19,7 @@ public TextAnswers(List<TextAnswer> textAnswers) {

public TextAnswer getAnswerByQuestionId(long questionId) {
if (!textAnswers.containsKey(questionId)) {
throw new TextAnswerNotFoundException(questionId);
throw new MissingTextAnswerForQuestionException(questionId);
}
return textAnswers.get(questionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import reviewme.global.exception.NotFoundException;

@Slf4j
public class TextAnswerNotFoundException extends NotFoundException {
public class MissingTextAnswerForQuestionException extends NotFoundException {

public TextAnswerNotFoundException(long questionId) {
public MissingTextAnswerForQuestionException(long questionId) {
super("질문에 해당하는 서술형 답변을 찾지 못했어요.");
log.warn("Text Answer not found for questionId: {}", questionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.List;
import org.junit.jupiter.api.Test;
import reviewme.review.domain.exception.TextAnswerNotFoundException;
import reviewme.review.domain.exception.MissingTextAnswerForQuestionException;

class TextAnswersTest {

Expand All @@ -16,7 +16,7 @@ class TextAnswersTest {

// when, then
assertThatThrownBy(() -> textAnswers.getAnswerByQuestionId(2))
.isInstanceOf(TextAnswerNotFoundException.class);
.isInstanceOf(MissingTextAnswerForQuestionException.class);
}

@Test
Expand Down

0 comments on commit 93aec4d

Please sign in to comment.