Search in sources :

Example 16 with QuestionModelInterface

use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.

the class QuestionsOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final QuestionModelInterface questionModelFirst = Mockito.mock(QuestionModelInterface.class);
    questionModelFirst.setId(1);
    given(questionModelFirst.getTopic()).willReturn(new TopicModelEmpty(1));
    given(questionModelFirst.getQuestionType()).willReturn(new QuestionTypeModelEmpty(1));
    final QuestionModelInterface questionModelSecond = Mockito.mock(QuestionModelInterface.class);
    questionModelSecond.setId(2);
    given(questionModelSecond.getTopic()).willReturn(new TopicModelEmpty(2));
    given(questionModelSecond.getQuestionType()).willReturn(new QuestionTypeModelEmpty(2));
    final List<QuestionModelInterface> questionsModels = new ArrayList<>(2);
    questionsModels.add(questionModelFirst);
    questionsModels.add(questionModelSecond);
    final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
    final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
    final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
    final QuestionTypesServiceInterface questionTypesService = Mockito.mock(QuestionTypesServiceInterface.class);
    final QuestionTypesOptionsInterface questionTypesOptions = Mockito.mock(QuestionTypesOptionsInterface.class);
    questionsOptions.setAnswersService(answersService);
    questionsOptions.withAnswers(answersOptions);
    questionsOptions.setTopicsService(topicsService);
    questionsOptions.withTopic(topicsOptions);
    questionsOptions.setQuestionTypesService(questionTypesService);
    questionsOptions.withQuestionType(questionTypesOptions);
    final List<AnswerModelInterface> answersModelsFirst = new ArrayList<>();
    answersModelsFirst.add(Mockito.mock(AnswerModelInterface.class));
    final List<AnswerModelInterface> answersModelsSecond = new ArrayList<>();
    answersModelsSecond.add(Mockito.mock(AnswerModelInterface.class));
    TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    QuestionTypeModelInterface questionTypeModelFirst = Mockito.mock(QuestionTypeModelInterface.class);
    QuestionTypeModelInterface questionTypeModelSecond = Mockito.mock(QuestionTypeModelInterface.class);
    given(answersService.findByQuestion(questionModelFirst, answersOptions)).willReturn(answersModelsFirst);
    given(answersService.findByQuestion(questionModelSecond, answersOptions)).willReturn(answersModelsSecond);
    given(topicsService.find(questionModelFirst.getTopic().getId(), topicsOptions)).willReturn(topicModelFirst);
    given(topicsService.find(questionModelSecond.getTopic().getId(), topicsOptions)).willReturn(topicModelSecond);
    given(questionTypesService.find(questionModelFirst.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelFirst);
    given(questionTypesService.find(questionModelSecond.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelSecond);
    final List<QuestionModelInterface> questionsModelsWithRelations = questionsOptions.withRelations(questionsModels);
    Assert.assertEquals(questionsModelsWithRelations, questionsModels);
    verify(answersService).findByQuestion(questionModelFirst, answersOptions);
    verify(questionsModels.get(0)).setAnswers(answersModelsFirst);
    verify(questionsModels.get(0)).setAnswers(Mockito.anyList());
    verify(answersService).findByQuestion(questionModelSecond, answersOptions);
    verify(questionsModels.get(1)).setAnswers(answersModelsSecond);
    verify(questionsModels.get(1)).setAnswers(Mockito.anyList());
    verify(topicsService).find(questionModelFirst.getTopic().getId(), topicsOptions);
    verify(topicsService).find(questionModelSecond.getTopic().getId(), topicsOptions);
    verify(questionsModels.get(0)).setTopic(topicModelFirst);
    verify(questionsModels.get(1)).setTopic(topicModelSecond);
    verify(questionTypesService).find(questionModelFirst.getQuestionType().getId(), questionTypesOptions);
    verify(questionTypesService).find(questionModelSecond.getQuestionType().getId(), questionTypesOptions);
    verify(questionModelFirst).setQuestionType(questionTypeModelFirst);
    verify(questionModelSecond).setQuestionType(questionTypeModelSecond);
}
Also used : QuestionTypesServiceInterface(easytests.core.services.QuestionTypesServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) AnswersServiceInterface(easytests.core.services.AnswersServiceInterface) QuestionTypeModelEmpty(easytests.core.models.empty.QuestionTypeModelEmpty) TopicModelInterface(easytests.core.models.TopicModelInterface) TopicModelEmpty(easytests.core.models.empty.TopicModelEmpty) QuestionTypeModelInterface(easytests.core.models.QuestionTypeModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) AnswerModelInterface(easytests.core.models.AnswerModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with QuestionModelInterface

use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.

the class AnswersMapperTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Integer id = 1;
    final String txt = "Answer1";
    final Integer questionId = 1;
    final Boolean right = true;
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    AnswerEntity answerEntity = this.answersMapper.find(id);
    Assert.assertNotNull(answerEntity);
    Assert.assertEquals(id, answerEntity.getId());
    Assert.assertEquals(txt, answerEntity.getTxt());
    Assert.assertEquals(questionId, answerEntity.getQuestionId());
    Assert.assertEquals(right, answerEntity.getRight());
    answerEntity = Mockito.mock(AnswerEntity.class);
    Mockito.when(answerEntity.getId()).thenReturn(id);
    Mockito.when(answerEntity.getTxt()).thenReturn(txt);
    Mockito.when(answerEntity.getQuestionId()).thenReturn(questionId);
    Mockito.when(answerEntity.getRight()).thenReturn(right);
    this.answersMapper.update(answerEntity);
    answerEntity = this.answersMapper.find(id);
    Assert.assertEquals(id, answerEntity.getId());
    Assert.assertEquals(txt, answerEntity.getTxt());
    Assert.assertEquals(questionId, answerEntity.getQuestionId());
    Assert.assertEquals(right, answerEntity.getRight());
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with QuestionModelInterface

use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testSaveUpdateEntityIdOnCreation.

@Test
public void testSaveUpdateEntityIdOnCreation() throws Exception {
    final Integer id = 7;
    final QuestionModelInterface questionModel = this.questionsSupport.getModelAdditionalMock(0);
    doAnswer(invocation -> {
        final QuestionEntity questionEntity = (QuestionEntity) invocation.getArguments()[0];
        questionEntity.setId(id);
        return null;
    }).when(this.questionsMapper).insert(any());
    this.questionsService.save(questionModel);
    verify(questionModel, times(1)).setId(id);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface)

Example 19 with QuestionModelInterface

use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testFindByTopicAbsentList.

@Test
public void testFindByTopicAbsentList() throws Exception {
    final TopicModelInterface topicModel = this.topicsSupport.getModelFixtureMock(0);
    when(this.questionsMapper.findByTopicId(topicModel.getId())).thenReturn(new ArrayList<>(0));
    final List<QuestionModelInterface> questionsFoundedModels = this.questionsService.findByTopic(topicModel);
    Assert.assertEquals(0, questionsFoundedModels.size());
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 20 with QuestionModelInterface

use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testFindByTopicPresentList.

@Test
public void testFindByTopicPresentList() throws Exception {
    final TopicModelInterface topicModel = this.topicsSupport.getModelFixtureMock(0);
    final List<QuestionEntity> questionEntities = this.getQuestionsFixturesEntities();
    when(this.questionsMapper.findByTopicId(topicModel.getId())).thenReturn(questionEntities);
    final List<QuestionModelInterface> questionsFoundedModels = this.questionsService.findByTopic(topicModel);
    this.questionsSupport.assertModelsListEquals(this.getQuestionsFixturesModels(), questionsFoundedModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Aggregations

QuestionModelInterface (easytests.core.models.QuestionModelInterface)40 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 TopicModelInterface (easytests.core.models.TopicModelInterface)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)10 QuestionsOptionsInterface (easytests.core.options.QuestionsOptionsInterface)9 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)9 QuestionEntity (easytests.core.entities.QuestionEntity)8 AnswerModelInterface (easytests.core.models.AnswerModelInterface)6 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)5 InOrder (org.mockito.InOrder)4 PointModelInterface (easytests.core.models.PointModelInterface)3 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)3 QuizModelInterface (easytests.core.models.QuizModelInterface)3 QuestionTypeModelEmpty (easytests.core.models.empty.QuestionTypeModelEmpty)3 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)3 QuestionTypesServiceInterface (easytests.core.services.QuestionTypesServiceInterface)3 QuestionModel (easytests.core.models.QuestionModel)2 SolutionModelInterface (easytests.core.models.SolutionModelInterface)2