-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from choomi1217/step1
🚀 1단계 - 레거시 코드 리팩터링
- Loading branch information
Showing
6 changed files
with
112 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
package nextstep.qna.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import nextstep.qna.CannotDeleteException; | ||
import nextstep.users.domain.NsUser; | ||
import nextstep.users.domain.NsUserTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class AnswerTest { | ||
public static final Answer A1 = new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1"); | ||
public static final Answer A2 = new Answer(NsUserTest.SANJIGI, QuestionTest.Q1, "Answers Contents2"); | ||
|
||
public static final Answer A1 = new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, | ||
"Answers Contents1"); | ||
public static final Answer A2 = new Answer(NsUserTest.SANJIGI, QuestionTest.Q1, | ||
"Answers Contents2"); | ||
|
||
@DisplayName("답변 등록자와 로그인 유저가 일치할 땐 예외를 던지지 않습니다.") | ||
@Test | ||
void doesNotTrowExceptionWhenDeleteLoginUserMatchedWithAnswerWriter() { | ||
NsUser writer = A1.getWriter(); | ||
assertThatNoException().isThrownBy(() -> A1.delete(writer)); | ||
assertThat(A1.isDeleted()).isTrue(); | ||
} | ||
|
||
@DisplayName("답변 등록자와 로그인 유저가 일치하지 않은데 삭제하려고 하면 예외를 던집니다.") | ||
@Test | ||
void throwExceptionWhenDeleteLoginUserDoesNotMatchedWithAnswerWriter() { | ||
NsUser writer = A1.getWriter(); | ||
assertThatThrownBy(() -> A2.delete(writer)).isInstanceOf(CannotDeleteException.class); | ||
assertThat(A2.isDeleted()).isFalse(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
package nextstep.qna.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import nextstep.qna.CannotDeleteException; | ||
import nextstep.users.domain.NsUser; | ||
import nextstep.users.domain.NsUserTest; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class QuestionTest { | ||
|
||
public static final Question Q1 = new Question(NsUserTest.JAVAJIGI, "title1", "contents1"); | ||
public static final Question Q2 = new Question(NsUserTest.SANJIGI, "title2", "contents2"); | ||
|
||
@DisplayName("삭제할 권한이 있다면 질문이 삭제됩니다.") | ||
@Test | ||
void canDeleteIfYouHavePermission() throws CannotDeleteException { | ||
NsUser writer = Q1.getWriter(); | ||
assertThatNoException().isThrownBy(() -> Q1.delete(writer)); | ||
assertThat(Q1.isDeleted()).isTrue(); | ||
} | ||
|
||
@DisplayName("삭제할 권한이 없다면 질문을 삭제할 수 없습니다.") | ||
@Test | ||
void canNotDeleteIfYouDontHavePermission() throws CannotDeleteException { | ||
NsUser writer = Q1.getWriter(); | ||
assertThatThrownBy(() -> Q2.delete(writer)).isInstanceOf(CannotDeleteException.class); | ||
assertThat(Q2.isDeleted()).isFalse(); | ||
} | ||
|
||
} |