Skip to content

Commit

Permalink
[BE] feat: 150자가 넘어가는 경우 ... 말줄임표 추가 (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
donghoony authored Sep 6, 2024
1 parent b7ea307 commit b02b054
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
public class ReviewPreviewGenerator {

private static final int PREVIEW_LENGTH = 150;
private static final String ELLIPSIS = "...";

public String generatePreview(List<TextAnswer> reviewTextAnswers) {
if (reviewTextAnswers.isEmpty()) {
return "";
}
String answer = reviewTextAnswers.get(0).getContent();
if (answer.length() > PREVIEW_LENGTH) {
return answer.substring(0, PREVIEW_LENGTH);
return answer.substring(0, PREVIEW_LENGTH) + ELLIPSIS;
}
return answer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ReviewPreviewGeneratorTest {

@Test
void 답변_내용이_미리보기_최대_글자를_넘는_경우_미리보기_길이만큼_잘라서_반환한다() {
void 답변_내용이_미리보기_최대_글자를_넘는_경우_미리보기_길이만큼_자르고_말줄임표를_붙여_반환한다() {
// given
ReviewPreviewGenerator reviewPreviewGenerator = new ReviewPreviewGenerator();
String answer = "*".repeat(151);
Expand All @@ -21,7 +21,7 @@ class ReviewPreviewGeneratorTest {
String actual = reviewPreviewGenerator.generatePreview(List.of(textAnswer));

// then
assertThat(actual).hasSize(150);
assertThat(actual).isEqualTo("*".repeat(150) + "...");
}

@ParameterizedTest
Expand Down

0 comments on commit b02b054

Please sign in to comment.