Search in sources :

Example 21 with QuestionModelInterface

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

the class TopicsOptionsTest method testWithRelationsQuestionsOnList.

@Test
public void testWithRelationsQuestionsOnList() throws Exception {
    final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = new ArrayList<>(2);
    topicsModels.add(topicModelFirst);
    topicsModels.add(topicModelSecond);
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.setTopicsService(topicsService);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModelsFirst = new ArrayList<>();
    questionsModelsFirst.add(Mockito.mock(QuestionModelInterface.class));
    final List<QuestionModelInterface> questionsModelsSecond = new ArrayList<>();
    questionsModelsSecond.add(Mockito.mock(QuestionModelInterface.class));
    given(questionsService.findByTopic(topicModelFirst, questionsOptions)).willReturn(questionsModelsFirst);
    given(questionsService.findByTopic(topicModelSecond, questionsOptions)).willReturn(questionsModelsSecond);
    final List<TopicModelInterface> topicsModelsWithRelations = topicsOptions.withRelations(topicsModels);
    Assert.assertEquals(topicsModelsWithRelations, topicsModels);
    verify(questionsService).findByTopic(topicModelFirst, questionsOptions);
    verify(topicsModels.get(0)).setQuestions(questionsModelsFirst);
    verify(questionsService).findByTopic(topicModelSecond, questionsOptions);
    verify(topicsModels.get(1)).setQuestions(questionsModelsSecond);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with QuestionModelInterface

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

the class TopicsOptionsTest method testSaveWithRelationsQuestions.

@Test
public void testSaveWithRelationsQuestions() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.setTopicsService(topicsService);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    topicModel.setQuestions(questionsModels);
    final InOrder inOrder = Mockito.inOrder(topicsService, questionsService);
    topicsOptions.saveWithRelations(topicModel);
    inOrder.verify(topicsService).save(topicModel);
    inOrder.verify(questionsService).save(topicModel.getQuestions(), questionsOptions);
}
Also used : InOrder(org.mockito.InOrder) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with QuestionModelInterface

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

the class TopicsOptionsTest method testSaveDeleteWithRelationsQuestion.

@Test
public void testSaveDeleteWithRelationsQuestion() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.setTopicsService(topicsService);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    topicModel.setQuestions(questionsModels);
    topicsOptions.saveWithRelations((topicModel));
    verify(topicsService).save(topicModel);
    topicsOptions.deleteWithRelations(topicModel);
    verify(topicsService).delete(topicModel);
    verify(questionsService, times(2)).save(topicModel.getQuestions(), questionsOptions);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with QuestionModelInterface

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

the class QuestionsSupport method getModelMock.

private QuestionModelInterface getModelMock(Integer id, String text, Integer questionTypeId, Integer topicId) {
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(id);
    Mockito.when(questionModel.getText()).thenReturn(text);
    Mockito.when(questionModel.getQuestionType()).thenReturn(new QuestionTypeModelEmpty(questionTypeId));
    Mockito.when(questionModel.getTopic()).thenReturn(new TopicModelEmpty(topicId));
    Mockito.when(questionModel.getAnswers()).thenReturn(new ModelsListEmpty());
    return questionModel;
}
Also used : TopicModelEmpty(easytests.core.models.empty.TopicModelEmpty) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ModelsListEmpty(easytests.core.models.empty.ModelsListEmpty) QuestionTypeModelEmpty(easytests.core.models.empty.QuestionTypeModelEmpty)

Example 25 with QuestionModelInterface

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

the class QuestionsService method map.

private QuestionModelInterface map(QuestionEntity questionEntity) {
    if (questionEntity == null) {
        return null;
    }
    final QuestionModelInterface questionModel = new QuestionModel();
    questionModel.map(questionEntity);
    return questionModel;
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) QuestionModel(easytests.core.models.QuestionModel)

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