package qna.service;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import qna.CannotDeleteException;
import qna.domain.*;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class QnaServiceTest {
@Mock
private QuestionRepository questionRepository;
@Mock
private DeleteHistoryService deleteHistoryService;
@InjectMocks
private QnAService qnAService;
private Question question;
private Answer answer;
@BeforeEach
public void setUp() throws Exception {
question = new Question(1L, "title1", "contents1").writeBy(UserTest.JAVAJIGI);
answer = new Answer(11L, UserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1");
question.addAnswer(answer);
}
@Test
public void delete_성공() throws Exception {
when(questionRepository.findByIdAndDeletedFalse(question.getId())).thenReturn(Optional.of(question));
assertThat(question.isDeleted()).isFalse();
qnAService.deleteQuestion(UserTest.JAVAJIGI, question.getId());
assertThat(question.isDeleted()).isTrue();
verifyDeleteHistories();
}
@Test
public void delete_다른_사람이_쓴_글() throws Exception {
when(questionRepository.findByIdAndDeletedFalse(question.getId())).thenReturn(Optional.of(question));
assertThatThrownBy(() -> {
qnAService.deleteQuestion(UserTest.SANJIGI, question.getId());
}).isInstanceOf(CannotDeleteException.class);
}
@Test
public void delete_성공_질문자_답변자_같음() throws Exception {
when(questionRepository.findByIdAndDeletedFalse(question.getId())).thenReturn(Optional.of(question));
qnAService.deleteQuestion(UserTest.JAVAJIGI, question.getId());
assertThat(question.isDeleted()).isTrue();
assertThat(answer.isDeleted()).isTrue();
verifyDeleteHistories();
}
@Test
public void delete_답변_중_다른_사람이_쓴_글() throws Exception {
when(questionRepository.findByIdAndDeletedFalse(question.getId())).thenReturn(Optional.of(question));
assertThatThrownBy(() -> {
qnAService.deleteQuestion(UserTest.SANJIGI, question.getId());
}).isInstanceOf(CannotDeleteException.class);
}
private void verifyDeleteHistories() {
List<DeleteHistory> deleteHistories = Arrays.asList(
new DeleteHistory(ContentType.QUESTION, question.getId(), question.getWriter(), LocalDateTime.now()),
new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now()));
verify(deleteHistoryService).saveAll(deleteHistories);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于java的保龄球比赛记分板实现的存储库.zip
共32个文件
java:21个
properties:3个
gitkeep:2个
需积分: 5 0 下载量 129 浏览量
2024-07-31
17:31:11
上传
评论
收藏 71KB ZIP 举报
温馨提示
保龄球比赛记分牌 确定保龄球比赛记分牌要求。 完成需求的实现后,通过Pull Request(PR)向您的github账户对应的分支请求代码审查。 根据代码审查反馈进行改进并再次推送。 所有反馈完成后,进行下一步并重复前面的过程。 在线代码审查课程
资源推荐
资源详情
资源评论
收起资源包目录
基于java的保龄球比赛记分板实现的存储库.zip (32个子文件)
java-bowling-master
gradle.properties 66B
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 202B
src
test
java
qna
service
QnaServiceTest.java 3KB
domain
UserTest.java 260B
QuestionTest.java 254B
AnswerTest.java 258B
bowling
.gitkeep 0B
main
resources
application.properties 365B
java
qna
UnAuthorizedException.java 694B
UnAuthenticationException.java 715B
CannotDeleteException.java 205B
ForbiddenException.java 193B
service
DeleteHistoryService.java 869B
QnAService.java 2KB
NotFoundException.java 74B
domain
ContentType.java 71B
Question.java 2KB
QuestionRepository.java 312B
Answer.java 2KB
DeleteHistoryRepository.java 171B
UserRepository.java 230B
AbstractEntity.java 2KB
AnswerRepository.java 332B
DeleteHistory.java 2KB
User.java 3KB
bowling
.gitkeep 0B
gradlew.bat 3KB
build.gradle 549B
settings.gradle 34B
gradlew 6KB
.gitignore 351B
共 32 条
- 1
资源评论
t0_54coder
- 粉丝: 2467
- 资源: 4951
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功