diff --git a/README.md b/README.md index 44bb102aa..52344f49c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,38 @@ * [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview) # todo -- [] Question 에 삭제 상태 변경 추가 -- [] Answer에 삭제 상태 변경 추가 -- [] Answer 일급컬렉션 추가 +- [x] Question 에 삭제 상태 변경 추가 +- [x] Answer에 삭제 상태 변경 추가 +- [x] Answer 일급컬렉션 추가 + +# todo +### 수강신청 +- 과정 + - [] 강의 수강신청 + - 강의 + - 시작일 + - 종료일 + - 커버 이미지 + - 이미지 크기 + - [X] 1MB 이하 허용 검증 + - 이미지 타입 + - [X] gif, jpg(jpeg 포함), png, svg만 허용 + - 이미지 비율 + - width + - [X] 300px 이상 값 검증 + - height + - [X] width, heigth 비율 3:2 검증 + - 강의타입(유료, 무료) + - 유료 강의 + - 유료 강의 최대 수강 인원 제한 검증 + - [] 유료 강의 최대 수강 인원 초과 검증. + - 무료 강의 + - 무료 강의 최대 수강 인원 무제한 + - 강의 상태(준비중, 모집중, 종료) + - [x] 강의 수강신청 + - [X] 강의 상태가 준비중 검증 + - 수강생 일급컬렉션 + - 수강생 + - 결제금액 +- 결제 + - [X] 결제 여부 검증 diff --git a/src/main/java/nextstep/courses/domain/Course.java b/src/main/java/nextstep/courses/domain/Course.java index 0f6971604..6d64367fe 100644 --- a/src/main/java/nextstep/courses/domain/Course.java +++ b/src/main/java/nextstep/courses/domain/Course.java @@ -9,13 +9,12 @@ public class Course { private Long creatorId; + private Sessions sessions; + private LocalDateTime createdAt; private LocalDateTime updatedAt; - public Course() { - } - public Course(String title, Long creatorId) { this(0L, title, creatorId, LocalDateTime.now(), null); } diff --git a/src/main/java/nextstep/courses/domain/FreeSession.java b/src/main/java/nextstep/courses/domain/FreeSession.java new file mode 100644 index 000000000..441116799 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/FreeSession.java @@ -0,0 +1,9 @@ +package nextstep.courses.domain; + +public class FreeSession { + private final Session session; + + public FreeSession(Session session) { + this.session = session; + } +} diff --git a/src/main/java/nextstep/courses/domain/Image.java b/src/main/java/nextstep/courses/domain/Image.java new file mode 100644 index 000000000..ab60bc44d --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Image.java @@ -0,0 +1,18 @@ +package nextstep.courses.domain; + +public class Image { + + private ImageType imageType; + private ImageSize imageSize; + private ImageRate imageRate; + + public Image() { + } + + public Image(ImageType imageType, ImageSize imageSize, ImageRate imageRate) { + this.imageType = imageType; + this.imageSize = imageSize; + this.imageRate = imageRate; + } + +} diff --git a/src/main/java/nextstep/courses/domain/ImageRate.java b/src/main/java/nextstep/courses/domain/ImageRate.java new file mode 100644 index 000000000..5e2b7dd95 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/ImageRate.java @@ -0,0 +1,30 @@ +package nextstep.courses.domain; + +public class ImageRate { + + private final int MIN_WIDTH_SIZE = 300; + public int width; + public int height; + + public ImageRate(int width, int height) { + validRate(width, height); + validPixelSize(width); + this.width = width; + this.height = height; + } + + private void validRate(int width, int height) { + if (width / height != 3 / 2) { + throw new IllegalArgumentException("이미지 width, height 비율이 3:2를 만족하지 않습니다"); + } + } + + private void validPixelSize(int width) { + if (width < MIN_WIDTH_SIZE) { + throw new IllegalArgumentException("이미지 width가 300px 보다 작습니다"); + } + } + + + +} diff --git a/src/main/java/nextstep/courses/domain/ImageSize.java b/src/main/java/nextstep/courses/domain/ImageSize.java new file mode 100644 index 000000000..ebd41fe32 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/ImageSize.java @@ -0,0 +1,19 @@ +package nextstep.courses.domain; + +public class ImageSize { + + private final int MAX_SIZE = 1; + + private int size; + + public ImageSize(int size) { + validSize(size); + this.size = size; + } + + private void validSize(int size) { + if (size > MAX_SIZE) { + throw new IllegalArgumentException("이미지 사이즈가 1MB를 초과했습니다: " + size + "MB"); + } + } +} diff --git a/src/main/java/nextstep/courses/domain/ImageType.java b/src/main/java/nextstep/courses/domain/ImageType.java new file mode 100644 index 000000000..88c81b067 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/ImageType.java @@ -0,0 +1,29 @@ +package nextstep.courses.domain; + +import java.util.Arrays; +import java.util.List; + +public enum ImageType { + + GIF(List.of("gif")), + JPG(List.of("jpg", "jpeg")), + PNG(List.of("png")), + SVG(List.of("svg")); + + private List contentType; + + ImageType(List contentType) { + this.contentType = contentType; + } + + public static boolean isValidType(String type) { + return Arrays.stream(ImageType.values()) + .filter(imageType -> imageType.isContain(type)) + .findAny() + .isPresent(); + } + + private boolean isContain(String type) { + return this.contentType.contains(type); + } +} diff --git a/src/main/java/nextstep/courses/domain/JoinUser.java b/src/main/java/nextstep/courses/domain/JoinUser.java new file mode 100644 index 000000000..4cb62ceef --- /dev/null +++ b/src/main/java/nextstep/courses/domain/JoinUser.java @@ -0,0 +1,15 @@ +package nextstep.courses.domain; + +import nextstep.payments.domain.Payment; +import nextstep.users.domain.NsUser; + +public class JoinUser { + + private final NsUser user; + private final Payment payment; + + public JoinUser(NsUser user, Payment payment) { + this.user = user; + this.payment = payment; + } +} diff --git a/src/main/java/nextstep/courses/domain/JoinUsers.java b/src/main/java/nextstep/courses/domain/JoinUsers.java new file mode 100644 index 000000000..72e674845 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/JoinUsers.java @@ -0,0 +1,35 @@ +package nextstep.courses.domain; + +import java.util.List; +import java.util.Objects; + +public class JoinUsers { + + private final List joinUsers; + + public JoinUsers(List joinUsers) { + + this.joinUsers = joinUsers; + } + + public void add(JoinUser joinUser) { + this.joinUsers.add(joinUser); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + JoinUsers joinUsers1 = (JoinUsers) o; + return Objects.equals(joinUsers, joinUsers1.joinUsers); + } + + @Override + public int hashCode() { + return Objects.hash(joinUsers); + } +} diff --git a/src/main/java/nextstep/courses/domain/PaySession.java b/src/main/java/nextstep/courses/domain/PaySession.java new file mode 100644 index 000000000..f13ff32da --- /dev/null +++ b/src/main/java/nextstep/courses/domain/PaySession.java @@ -0,0 +1,42 @@ +package nextstep.courses.domain; + +import java.util.Objects; + +import nextstep.payments.domain.Payment; + +public class PaySession { + + private final Session session; + private int joinLimit; + + public PaySession(Session session) { + this.session = session; + } + + public void join(JoinUser joinUser, Payment payment) { + validPaid(payment); + session.join(joinUser); + } + + private void validPaid(Payment payment) { + if(!payment.isPaid()) + throw new IllegalStateException("유료 강의의 지불이 완료되지 않았습니다."); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PaySession session1 = (PaySession) o; + return Objects.equals(session, session1.session); + } + + @Override + public int hashCode() { + return Objects.hash(session); + } +} diff --git a/src/main/java/nextstep/courses/domain/Period.java b/src/main/java/nextstep/courses/domain/Period.java new file mode 100644 index 000000000..98e3c3192 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Period.java @@ -0,0 +1,18 @@ +package nextstep.courses.domain; + +import java.time.LocalDateTime; + +public class Period { + + private final LocalDateTime startDate; + private final LocalDateTime endDate; + + public Period() { + this(LocalDateTime.now(), LocalDateTime.now().plusWeeks(1)); + } + + public Period(LocalDateTime startDate, LocalDateTime endDate) { + this.startDate = startDate; + this.endDate = endDate; + } +} diff --git a/src/main/java/nextstep/courses/domain/Session.java b/src/main/java/nextstep/courses/domain/Session.java new file mode 100644 index 000000000..a185457e6 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Session.java @@ -0,0 +1,50 @@ +package nextstep.courses.domain; + +import java.util.*; + +public class Session { + + private final JoinUsers joinUsers; + private final Image coverImage; + private final SessionStatus status; + private final Period period; + + public Session() { + this(new ArrayList<>()); + } + + public Session(List joinUsers) { + this.joinUsers = new JoinUsers(joinUsers); + this.coverImage = new Image(); + this.status = SessionStatus.RECRUITING; + this.period = new Period(); + } + + public void join(JoinUser joinUser) { + validRecruiting(); + joinUsers.add(joinUser); + } + + private void validRecruiting() { + if (!status.isRecruiting()) { + throw new IllegalStateException("강의가 모집중이 아닙니다"); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Session session = (Session) o; + return Objects.equals(joinUsers, session.joinUsers); + } + + @Override + public int hashCode() { + return Objects.hash(joinUsers); + } +} diff --git a/src/main/java/nextstep/courses/domain/SessionStatus.java b/src/main/java/nextstep/courses/domain/SessionStatus.java new file mode 100644 index 000000000..965a7a723 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/SessionStatus.java @@ -0,0 +1,11 @@ +package nextstep.courses.domain; + +public enum SessionStatus { + READY, + RECRUITING, + END; + + public boolean isRecruiting() { + return this == RECRUITING; + } +} diff --git a/src/main/java/nextstep/courses/domain/SessionType.java b/src/main/java/nextstep/courses/domain/SessionType.java new file mode 100644 index 000000000..18715d01b --- /dev/null +++ b/src/main/java/nextstep/courses/domain/SessionType.java @@ -0,0 +1,6 @@ +package nextstep.courses.domain; + +public enum SessionType { + PAY(), + FREE() +} diff --git a/src/main/java/nextstep/courses/domain/Sessions.java b/src/main/java/nextstep/courses/domain/Sessions.java new file mode 100644 index 000000000..2334b97c9 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Sessions.java @@ -0,0 +1,9 @@ +package nextstep.courses.domain; + +import java.util.List; + +public class Sessions { + + private List sessions; + +} diff --git a/src/main/java/nextstep/payments/domain/Payment.java b/src/main/java/nextstep/payments/domain/Payment.java index 57d833f85..8a297dd82 100644 --- a/src/main/java/nextstep/payments/domain/Payment.java +++ b/src/main/java/nextstep/payments/domain/Payment.java @@ -26,4 +26,8 @@ public Payment(String id, Long sessionId, Long nsUserId, Long amount) { this.amount = amount; this.createdAt = LocalDateTime.now(); } + + public boolean isPaid() { + return true; + } } diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 7df698136..9cbe6c8ce 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -5,6 +5,7 @@ import nextstep.users.domain.NsUser; import java.time.LocalDateTime; +import java.util.Objects; public class Answer { @@ -62,4 +63,22 @@ public String toString() { public void delete() { deleted = true; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Answer answer = (Answer) o; + return deleted == answer.deleted && Objects.equals(id, answer.id) && Objects.equals(writer, answer.writer) && Objects.equals(contents, + answer.contents) && Objects.equals(createdDate, answer.createdDate) && Objects.equals(updatedDate, answer.updatedDate); + } + + @Override + public int hashCode() { + return Objects.hash(id, writer, contents, deleted, createdDate, updatedDate); + } } diff --git a/src/main/java/nextstep/qna/domain/Answers.java b/src/main/java/nextstep/qna/domain/Answers.java index 860790be9..bb2071c5c 100644 --- a/src/main/java/nextstep/qna/domain/Answers.java +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; import nextstep.users.domain.NsUser; @@ -9,6 +10,10 @@ public class Answers { private List answers; + public Answers() { + this(new ArrayList<>()); + } + public Answers(List answers) { this.answers = answers; } @@ -27,10 +32,25 @@ public void delete() { } public List getDeleteHistory() { - List deleteHistories = new ArrayList<>(); - for (Answer answer : answers) { - deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); + return answers.stream() + .map(DeleteHistory::ofAnswer) + .collect(Collectors.toList()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; } - return deleteHistories; + if (o == null || getClass() != o.getClass()) { + return false; + } + Answers answers1 = (Answers) o; + return Objects.equals(answers, answers1.answers); + } + + @Override + public int hashCode() { + return Objects.hash(answers); } } diff --git a/src/main/java/nextstep/qna/domain/DeleteHistory.java b/src/main/java/nextstep/qna/domain/DeleteHistory.java index 43c37e5e5..536795d1a 100644 --- a/src/main/java/nextstep/qna/domain/DeleteHistory.java +++ b/src/main/java/nextstep/qna/domain/DeleteHistory.java @@ -26,6 +26,15 @@ public DeleteHistory(ContentType contentType, Long contentId, NsUser deletedBy, this.createdDate = createdDate; } + public static DeleteHistory ofAnswer(Answer answer) { + return new DeleteHistory( + ContentType.ANSWER, + answer.getId(), + answer.getWriter(), + LocalDateTime.now() + ); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/test/java/nextstep/courses/domain/ImageRateTest.java b/src/test/java/nextstep/courses/domain/ImageRateTest.java new file mode 100644 index 000000000..e9afd23c3 --- /dev/null +++ b/src/test/java/nextstep/courses/domain/ImageRateTest.java @@ -0,0 +1,26 @@ +package nextstep.courses.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +@DisplayName("도메인 객체 ImageRate 테스트") +class ImageRateTest { + @DisplayName("이미지 비율 검증") + @Test + void 이미지_비율_검증() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new ImageRate(300, 100)) + .withMessage("이미지 width, height 비율이 3:2를 만족하지 않습니다"); + } + + @DisplayName("이미지 최저 픽셀 검증") + @Test + void 이미지_최저_픽셀_검증() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new ImageRate(30, 20)) + .withMessage("이미지 width가 300px 보다 작습니다"); + } +} + diff --git a/src/test/java/nextstep/courses/domain/ImageSizeTest.java b/src/test/java/nextstep/courses/domain/ImageSizeTest.java new file mode 100644 index 000000000..a2a35def4 --- /dev/null +++ b/src/test/java/nextstep/courses/domain/ImageSizeTest.java @@ -0,0 +1,17 @@ +package nextstep.courses.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +@DisplayName("도메인 객체 ImageSize 테스트") +class ImageSizeTest { + @DisplayName("이미지 1MB 초과 검증") + @Test + void 이미지_용량_검증() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new ImageSize(2)) + .withMessage("이미지 사이즈가 1MB를 초과했습니다: 2MB"); + } +} diff --git a/src/test/java/nextstep/courses/domain/ImageTypeTest.java b/src/test/java/nextstep/courses/domain/ImageTypeTest.java new file mode 100644 index 000000000..d26b5bccc --- /dev/null +++ b/src/test/java/nextstep/courses/domain/ImageTypeTest.java @@ -0,0 +1,46 @@ +package nextstep.courses.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +@DisplayName("도메인 객체 ImageType 테스트") +class ImageTypeTest { + + @DisplayName("이미지 gif 확장자 검증 테스트") + @Test + void imageTypeGifValidTest() { + assertThat(ImageType.isValidType("gif")).isTrue(); + } + + @DisplayName("이미지 jpeg 확장자 검증 테스트") + @Test + void imageTypeJpegValidTest() { + assertThat(ImageType.isValidType("jpeg")).isTrue(); + } + + @DisplayName("이미지 jpg 확장자 검증 테스트") + @Test + void imageTypeJpgValidTest() { + assertThat(ImageType.isValidType("jpg")).isTrue(); + } + + @DisplayName("이미지 png 확장자 검증 테스트") + @Test + void imageTypePngValidTest() { + assertThat(ImageType.isValidType("png")).isTrue(); + } + + @DisplayName("이미지 svg 확장자 검증 테스트") + @Test + void imageTypeSvgValidTest() { + assertThat(ImageType.isValidType("svg")).isTrue(); + } + + @DisplayName("이미지 비허용 확장자 검증 테스트") + @Test + void imageTypeInvalidTest() { + assertThat(ImageType.isValidType("zip")).isFalse(); + } +} diff --git a/src/test/java/nextstep/courses/domain/JoinUserTest.java b/src/test/java/nextstep/courses/domain/JoinUserTest.java new file mode 100644 index 000000000..d89eeb6e6 --- /dev/null +++ b/src/test/java/nextstep/courses/domain/JoinUserTest.java @@ -0,0 +1,10 @@ +package nextstep.courses.domain; + +import nextstep.users.domain.NsUserTest; + + +class JoinUserTest { + + public static final JoinUser JAVAJIGI = new JoinUser(NsUserTest.JAVAJIGI, null); + public static final JoinUser SANJIGI = new JoinUser(NsUserTest.SANJIGI, null); +} diff --git a/src/test/java/nextstep/courses/domain/PaySessionTest.java b/src/test/java/nextstep/courses/domain/PaySessionTest.java new file mode 100644 index 000000000..5b6630b66 --- /dev/null +++ b/src/test/java/nextstep/courses/domain/PaySessionTest.java @@ -0,0 +1,37 @@ +package nextstep.courses.domain; + +import nextstep.payments.domain.PaymentTest; +import org.junit.jupiter.api.*; + +import static nextstep.courses.domain.SessionTest.L1; +import static org.assertj.core.api.Assertions.*; + +class PaySessionTest { + + public static PaySession PAY_SESSION1; + + @BeforeEach + void init() { + PAY_SESSION1 = new PaySession(L1); + } + + @DisplayName("유료 강의 지불 여부 확인") + @Test + void 수강신청_정상기능() { + PaySession session = new PaySession(new Session()); + session.join(JoinUserTest.JAVAJIGI, PaymentTest.PAID_PAYMENT); + + assertThat(session).isEqualTo(PAY_SESSION1); + } + + @DisplayName("유료 강의 미지불 여부 확인") + @Test + void 수강신청_미지불() { + PaySession session = new PaySession(new Session()); + + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> session.join(JoinUserTest.JAVAJIGI, PaymentTest.NOTPAID_PAYMENT)) + .withMessage("유료 강의의 지불이 완료되지 않았습니다."); + } + +} diff --git a/src/test/java/nextstep/courses/domain/SessionTest.java b/src/test/java/nextstep/courses/domain/SessionTest.java new file mode 100644 index 000000000..457b7f7f3 --- /dev/null +++ b/src/test/java/nextstep/courses/domain/SessionTest.java @@ -0,0 +1,23 @@ +package nextstep.courses.domain; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class SessionTest { + + public static final Session L1 = new Session(List.of(JoinUserTest.JAVAJIGI)); + + @DisplayName("수강신청") + @Test + void 수강신청_기본기능() { + Session session = new Session(); + session.join(JoinUserTest.JAVAJIGI); + assertThat(session).isEqualTo(L1); + } + + +} diff --git a/src/test/java/nextstep/payments/domain/NotPaidPayment.java b/src/test/java/nextstep/payments/domain/NotPaidPayment.java new file mode 100644 index 000000000..8ec600d51 --- /dev/null +++ b/src/test/java/nextstep/payments/domain/NotPaidPayment.java @@ -0,0 +1,9 @@ +package nextstep.payments.domain; + +public class NotPaidPayment extends Payment{ + + @Override + public boolean isPaid() { + return false; + } +} diff --git a/src/test/java/nextstep/payments/domain/PaidPayment.java b/src/test/java/nextstep/payments/domain/PaidPayment.java new file mode 100644 index 000000000..b8d7f222a --- /dev/null +++ b/src/test/java/nextstep/payments/domain/PaidPayment.java @@ -0,0 +1,9 @@ +package nextstep.payments.domain; + +public class PaidPayment extends Payment{ + + @Override + public boolean isPaid() { + return true; + } +} diff --git a/src/test/java/nextstep/payments/domain/PaymentTest.java b/src/test/java/nextstep/payments/domain/PaymentTest.java new file mode 100644 index 000000000..5673eccb4 --- /dev/null +++ b/src/test/java/nextstep/payments/domain/PaymentTest.java @@ -0,0 +1,19 @@ +package nextstep.payments.domain; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +public class PaymentTest { + + public static final Payment PAY1 = new Payment(); + public static final Payment PAID_PAYMENT = new PaidPayment(); + public static final Payment NOTPAID_PAYMENT = new NotPaidPayment(); + + @Test + void isPaid() { + assertThat(PAY1.isPaid()).isTrue(); + } +} diff --git a/src/test/java/nextstep/qna/domain/AnswersTest.java b/src/test/java/nextstep/qna/domain/AnswersTest.java new file mode 100644 index 000000000..31e72c494 --- /dev/null +++ b/src/test/java/nextstep/qna/domain/AnswersTest.java @@ -0,0 +1,51 @@ +package nextstep.qna.domain; + +import java.util.List; + +import nextstep.users.domain.NsUserTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class AnswersTest { + + private static Answers ANSWERS1; + + @BeforeEach + void init() { + ANSWERS1 = new Answers(List.of(AnswerTest.A1)); + } + + @Test + void add() { + Answers answers = new Answers(); + answers.add(AnswerTest.A1); + assertThat(answers).isEqualTo(ANSWERS1); + } + + @Test + void isContainOtherOwner() { + boolean result = ANSWERS1.isContainOtherOwner(NsUserTest.JAVAJIGI); + assertThat(result).isTrue(); + } + + @Test + void delete() { + Answer expectedAnswer = new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1"); + expectedAnswer.delete(); + + Answers expected = new Answers(List.of(expectedAnswer)); + ANSWERS1.delete(); + assertThat(ANSWERS1).isEqualTo(expected); + } + + @Test + void getDeleteHistory() { + List deleteHistories = ANSWERS1.getDeleteHistory(); + List expected = List.of(DeleteHistoryTest.H1); + + assertThat(deleteHistories).isEqualTo(expected); + } +} diff --git a/src/test/java/nextstep/qna/domain/DeleteHistoryTest.java b/src/test/java/nextstep/qna/domain/DeleteHistoryTest.java new file mode 100644 index 000000000..088a7af4f --- /dev/null +++ b/src/test/java/nextstep/qna/domain/DeleteHistoryTest.java @@ -0,0 +1,12 @@ +package nextstep.qna.domain; + +import java.time.LocalDateTime; + +public class DeleteHistoryTest { + + public static final DeleteHistory H1 = new DeleteHistory(ContentType.ANSWER, + AnswerTest.A1.getId(), + AnswerTest.A1.getWriter(), + LocalDateTime.now()); + +}