Skip to content
Snippets Groups Projects
Commit 9f27a5d5 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Fix AnswerFacadeTest

parent 8d41e821
No related branches found
No related tags found
3 merge requests!31M2,!30M2 exercise,!29M2 exercise
......@@ -2,90 +2,52 @@ package org.fuseri.moduleexercise.answer;
import org.fuseri.model.dto.exercise.AnswerCreateDto;
import org.fuseri.model.dto.exercise.AnswerDto;
import org.fuseri.model.dto.exercise.AnswerInQuestionCreateDto;
import org.fuseri.model.dto.exercise.AnswersCreateDto;
import org.fuseri.model.dto.exercise.QuestionUpdateDto;
import org.fuseri.moduleexercise.exercise.Exercise;
import org.fuseri.moduleexercise.question.Question;
import org.fuseri.moduleexercise.question.QuestionService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import java.util.HashSet;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@SpringBootTest
public class AnswerFacadeTest {
class AnswerFacadeTest {
private final Exercise exercise = new Exercise();
private final Question question = new Question("text",new HashSet<>(),exercise);
private final AnswerDto answerDto = new AnswerDto("name",true);
private final AnswerCreateDto answerCreateDto = new AnswerCreateDto("name",true,1L);
private final AnswerInQuestionCreateDto inQuestionCreateDto = new AnswerInQuestionCreateDto("name",true);
private final AnswersCreateDto answersCreateDto = new AnswersCreateDto(1L, List.of(inQuestionCreateDto));
private final QuestionUpdateDto questionUpdateDto = QuestionUpdateDto.builder().build();
private final Answer answer = new Answer("name",true,question);
@MockBean
AnswerRepository repository;
@Autowired
AnswerFacade facade;
private AnswerFacade answerFacade;
@MockBean
AnswerService service;
private AnswerService answerService;
@MockBean
QuestionService questionService;
private AnswerMapper answerMapper;
@MockBean
AnswerMapper mapper;
@Test
void create() {
long id = 1;
when(service.find(id)).thenReturn(answer);
when(mapper.fromCreateDto(inQuestionCreateDto)).thenReturn(answer);
when(service.create(answer)).thenReturn(answer);
when(mapper.toDto(answer)).thenReturn(answerDto);
when(questionService.find(id)).thenReturn(question);
when(mapper.toDtoList(List.of(answer))).thenReturn(List.of(answerDto));
var actualDto = facade.createMultiple(answersCreateDto);
assertEquals(List.of(answerDto), actualDto);
}
private final AnswerDto answerDto = new AnswerDto("name", true);
private final AnswerCreateDto answerCreateDto = new AnswerCreateDto("name", true, 1L);
private final Question question = new Question("text", new HashSet<>(), new Exercise());
private final Answer answer = new Answer("name", true, question);
@Test
void update() {
Long id = 1L;
when(repository.existsById(id)).thenReturn(true);
when(service.find(id)).thenReturn(answer);
when(mapper.fromCreateDto(answerCreateDto)).thenReturn(answer);
when(service.update(answer)).thenReturn(answer);
when(mapper.toDto(answer)).thenReturn(answerDto);
AnswerDto actualDto = facade.update(id,answerCreateDto);
long id = 1L;
when(answerMapper.fromCreateDto(answerCreateDto)).thenReturn(answer);
when(answerService.update(id, answer)).thenReturn(answer);
when(answerMapper.toDto(answer)).thenReturn(answerDto);
AnswerDto actualDto = answerFacade.update(id, answerCreateDto);
assertEquals(answerDto, actualDto);
}
@Test
void testDelete() {
Long id = 1L;
when(service.find(id)).thenReturn(answer);
when(questionService.find(answer.getId())).thenReturn(question);
facade.delete(id);
verify(service).delete(id);
void delete() {
long id = 1L;
answerFacade.delete(id);
verify(answerService).delete(id);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment